ROOT  6.06/09
Reference Guide
RooSharedPropertiesList.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //////////////////////////////////////////////////////////////////////////////
18 //
19 // BEGIN_HTML
20 // Class RooSharedPropertiesList maintains the properties of RooRealVars
21 // and RooCategories that are clones of each other.
22 // END_HTML
23 //
24 
25 #include "RooFit.h"
27 #include "RooSharedProperties.h"
28 #include "RooLinkedListIter.h"
29 #include "TIterator.h"
30 #include "RooMsgService.h"
31 #include "Riostream.h"
32 using std::cout ;
33 using std::endl ;
34 
35 using namespace std;
36 
38 ;
39 
40 
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Constructor
44 
46 {
47  _propList.setHashTableSize(1000);
48 }
49 
50 
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Destructor
54 
56 {
57  // Delete all objects in property list
58  RooFIter iter = _propList.fwdIterator() ;
60  while((prop=(RooSharedProperties*)iter.next())) {
61  delete prop ;
62  }
63 }
64 
65 
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// Register property into list and take ownership.
69 ///
70 /// If an existing entry has a UUID that identical to that of the argument prop,
71 /// the argument prop is deleted and a pointer to the already stored is returned to
72 /// eliminate the duplication of instances with a unique identity.
73 ///
74 /// The caller should therefore not refer anymore to the input argument pointer as
75 /// as the object cannot be assumed to be live.
76 
78 {
79  if (prop==0) {
80  oocoutE((TObject*)0,InputArguments) << "RooSharedPropertiesList::ERROR null pointer!:" << endl ;
81  return 0 ;
82  }
83 
84 
85  // If the reference count is non-zero, it is already in the list, so no need
86  // to look it up anymore
87  if (prop->inSharedList()) {
88  prop->increaseRefCount() ;
89  return prop ;
90  }
91 
92  //std::cout << "REGISTER properties " << prop->asString() << " - list size = " << _propList.GetSize() << std::endl;
93  RooSharedProperties* tmp ;
94 
95  std::map<std::string, RooSharedProperties *>::iterator it;
96 
97  it = _newPropList.find( std::string(prop->asString()) );
98  if (it != _newPropList.end() ) {
99  tmp = it->second;
100  if (tmp != prop) {
101  // found another instance with same UUID
102  if (canDeleteIncoming) delete prop;
103  }
104  tmp->increaseRefCount();
105  return tmp;
106  }
107  prop->setInSharedList() ;
108  prop->increaseRefCount() ;
109  _newPropList[ std::string(prop->asString()) ] = prop;
110 
111  return prop ;
112 }
113 
114 
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Decrease reference count of property. If reference count is at zero,
118 /// delete the propery
119 
121 {
122  prop->decreaseRefCount() ;
123 
124  if (prop->refCount()==0) {
125  _propList.Remove(prop) ;
126 
127  std::map<std::string, RooSharedProperties *>::iterator it;
128  it = _newPropList.find( std::string(prop->asString()) );
129  if (it != _newPropList.end() ) _newPropList.erase(it);
130 
131  // We own object if ref-counted list. If count drops to zero, delete object
132  delete prop ;
133  }
134 
135 }
136 
137 
ClassImp(RooSharedPropertiesList)
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
#define oocoutE(o, a)
Definition: RooMsgService.h:48
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
RooSharedProperties * registerProperties(RooSharedProperties *, Bool_t canDeleteIncoming=kTRUE)
Register property into list and take ownership.
void unregisterProperties(RooSharedProperties *)
Decrease reference count of property.
virtual ~RooSharedPropertiesList()
Destructor.
Bool_t inSharedList() const
RooAbsArg * next()
Mother of all ROOT objects.
Definition: TObject.h:58