00001 /***************************************************************************** 00002 * Project: RooFit * 00003 * Package: RooFitCore * 00004 * @(#)root/roofitcore:$Id: RooSharedPropertiesList.cxx 24285 2008-06-16 15:05:15Z wouter $ 00005 * Authors: * 00006 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu * 00007 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu * 00008 * * 00009 * Copyright (c) 2000-2005, Regents of the University of California * 00010 * and Stanford University. All rights reserved. * 00011 * * 00012 * Redistribution and use in source and binary forms, * 00013 * with or without modification, are permitted according to the terms * 00014 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) * 00015 *****************************************************************************/ 00016 00017 ////////////////////////////////////////////////////////////////////////////// 00018 // 00019 // BEGIN_HTML 00020 // Class RooSharedPropertiesList maintains the properties of RooRealVars 00021 // and RooCategories that are clones of each other. 00022 // END_HTML 00023 // 00024 00025 #include "RooFit.h" 00026 #include "RooSharedPropertiesList.h" 00027 #include "RooSharedProperties.h" 00028 #include "TIterator.h" 00029 #include "RooMsgService.h" 00030 #include "Riostream.h" 00031 using std::cout ; 00032 using std::endl ; 00033 00034 ClassImp(RooSharedPropertiesList) 00035 ; 00036 00037 00038 00039 //_____________________________________________________________________________ 00040 RooSharedPropertiesList::RooSharedPropertiesList() 00041 { 00042 // Constructor 00043 } 00044 00045 00046 00047 //_____________________________________________________________________________ 00048 RooSharedPropertiesList::~RooSharedPropertiesList() 00049 { 00050 // Destructor 00051 00052 // Delete all objects in property list 00053 TIterator* iter = _propList.MakeIterator() ; 00054 RooSharedProperties* prop ; 00055 while((prop=(RooSharedProperties*)iter->Next())) { 00056 delete prop ; 00057 } 00058 delete iter ; 00059 } 00060 00061 00062 00063 //_____________________________________________________________________________ 00064 RooSharedProperties* RooSharedPropertiesList::registerProperties(RooSharedProperties* prop, Bool_t canDeleteIncoming) 00065 { 00066 // Register property into list and take ownership. 00067 // 00068 // If an existing entry has a UUID that identical to that of the argument prop, 00069 // the argument prop is deleted and a pointer to the already stored is returned to 00070 // eliminate the duplication of instances with a unique identity. 00071 // 00072 // The caller should therefore not refer anymore to the input argument pointer as 00073 // as the object cannot be assumed to be live. 00074 00075 if (prop==0) { 00076 oocoutE((TObject*)0,InputArguments) << "RooSharedPropertiesList::ERROR null pointer!:" << endl ; 00077 return 0 ; 00078 } 00079 00080 // Find property with identical uuid in list 00081 TIterator* iter = _propList.MakeIterator() ; 00082 RooSharedProperties* tmp ; 00083 while((tmp=(RooSharedProperties*)iter->Next())) { 00084 if (*tmp==*prop && tmp != prop) { 00085 // Found another instance of object with identical UUID 00086 00087 // Delete incoming instance, increase ref count of already stored instance 00088 // cout << "RooSharedProperties::reg deleting incoming prop " << prop << " recycling existing prop " << tmp << endl ; 00089 00090 // Check if prop is in _propList 00091 if (_propList.FindObject(prop)) { 00092 // cout << "incoming object to be deleted is in proplist!!" << endl ; 00093 } else { 00094 // cout << "deleting prop object " << prop << endl ; 00095 if (canDeleteIncoming) delete prop ; 00096 } 00097 00098 // delete prop ; 00099 _propList.Add(tmp) ; 00100 00101 delete iter ; 00102 00103 // Return pointer to already-stored instance 00104 return tmp ; 00105 } 00106 } 00107 delete iter ; 00108 00109 00110 // cout << "RooSharedProperties::reg storing incoming prop " << prop << endl ; 00111 _propList.Add(prop) ; 00112 return prop ; 00113 } 00114 00115 00116 00117 //_____________________________________________________________________________ 00118 void RooSharedPropertiesList::unregisterProperties(RooSharedProperties* prop) 00119 { 00120 // Decrease reference count of property. If reference count is at zero, 00121 // delete the propery 00122 00123 _propList.Remove(prop) ; 00124 00125 // We own object if ref-counted list. If count drops to zero, delete object 00126 if (_propList.refCount(prop)==0) { 00127 delete prop ; 00128 } 00129 00130 } 00131 00132