Logo ROOT  
Reference Guide
RooSetProxy.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 \file RooSetProxy.cxx
19 \class RooSetProxy
20 \ingroup Roofitcore
21 
22 RooSetProxy is the concrete proxy for RooArgSet objects.
23 A RooSetProxy is the general mechanism to store a RooArgSet
24 with RooAbsArgs in a RooAbsArg.
25 
26 Creating a RooSetProxy adds all members of the proxied RooArgSet to the proxy owners
27 server list (thus receiving value/shape dirty flags from it) and
28 registers itself with the owning class. The latter allows the
29 owning class to update the pointers of RooArgSet contents to reflect
30 the serverRedirect changes.
31 **/
32 
33 
34 #include "RooFit.h"
35 
36 #include "Riostream.h"
37 #include "RooSetProxy.h"
38 #include "RooArgSet.h"
39 #include "RooAbsArg.h"
40 
41 using namespace std;
42 
44 ;
45 
46 
47 #ifdef USEMEMPOOLFORARGSET
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Overload new operator must be implemented because it is overloaded
51 /// in the RooArgSet base class. Perform standard memory allocation
52 /// here instead of memory pool management performed in RooArgSet
53 
54 void* RooSetProxy::operator new (size_t bytes)
55 {
56  auto mem = malloc(bytes) ;
57  memset(mem, TStorage::kObjectAllocMemValue, bytes);
58  return mem;
59 }
60 
61 
62 ////////////////////////////////////////////////////////////////////////////////
63 
64 void RooSetProxy::operator delete (void* ptr)
65 {
66  free(ptr) ;
67 }
68 
69 #endif
70 
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Construct proxy with given name and description, with given owner
74 /// The default value and shape dirty propagation of the set contents
75 /// to the set owner is controlled by flags defValueServer and defShapeServer
76 
77 RooSetProxy::RooSetProxy(const char* inName, const char* /*desc*/, RooAbsArg* owner,
78  Bool_t defValueServer, Bool_t defShapeServer) :
79  RooArgSet(inName), _owner(owner),
80  _defValueServer(defValueServer),
81  _defShapeServer(defShapeServer)
82 {
83  //SetTitle(desc) ;
84  _owner->registerProxy(*this) ;
85 }
86 
87 
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Copy constructor
91 
92 RooSetProxy::RooSetProxy(const char* inName, RooAbsArg* owner, const RooSetProxy& other) :
93  RooArgSet(other,inName), _owner(owner),
94  _defValueServer(other._defValueServer),
95  _defShapeServer(other._defShapeServer)
96 {
97  _owner->registerProxy(*this) ;
98 }
99 
100 
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Destructor
104 
106 {
107  if (_owner) _owner->unRegisterProxy(*this) ;
108 }
109 
110 
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Overloaded RooArgSet::add() method insert object into set
114 /// and registers object as server to owner with given value
115 /// and shape dirty flag propagation requests
116 
117 Bool_t RooSetProxy::add(const RooAbsArg& var, Bool_t valueServer, Bool_t shapeServer, Bool_t silent)
118 {
119  Bool_t ret=RooArgSet::add(var,silent) ;
120  if (ret) {
121  _owner->addServer((RooAbsArg&)var,valueServer,shapeServer) ;
122  }
123  return ret ;
124 }
125 
126 
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Overloaded RooArgSet::addOwned() method insert object into owning set
130 /// and registers object as server to owner with default value
131 /// and shape dirty flag propagation
132 
134 {
135  Bool_t ret=RooArgSet::addOwned(var,silent) ;
136  if (ret) {
138  }
139  return ret ;
140 }
141 
142 
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Overloaded RooArgSet::addClone() method insert clone of object into owning set
146 /// and registers cloned object as server to owner with default value
147 /// and shape dirty flag propagation
148 
150 {
151  RooAbsArg* ret=RooArgSet::addClone(var,silent) ;
152  if (ret) {
154  }
155  return ret ;
156 }
157 
158 
159 
160 ////////////////////////////////////////////////////////////////////////////////
161 /// Overloaded RooArgSet::add() method inserts 'var' into set
162 /// and registers 'var' as server to owner with default value
163 /// and shape dirty flag propagation
164 
166 {
167  return add(var,_defValueServer,_defShapeServer,silent) ;
168 }
169 
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 /// Replace object 'var1' in set with 'var2'. Deregister var1 as
174 /// server from owner and register var2 as server to owner with
175 /// default value and shape dirty propagation flags
176 
177 Bool_t RooSetProxy::replace(const RooAbsArg& var1, const RooAbsArg& var2)
178 {
179  Bool_t ret=RooArgSet::replace(var1,var2) ;
180  if (ret) {
181  if (!isOwning()) _owner->removeServer((RooAbsArg&)var1) ;
183  _owner->isShapeServer(var2)) ;
184  }
185  return ret ;
186 }
187 
188 
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Remove object 'var' from set and deregister 'var' as server to owner.
192 
193 Bool_t RooSetProxy::remove(const RooAbsArg& var, Bool_t silent, Bool_t matchByNameOnly)
194 {
195  Bool_t ret=RooArgSet::remove(var,silent,matchByNameOnly) ;
196  if (ret && !isOwning()) {
197  _owner->removeServer((RooAbsArg&)var) ;
198  }
199  return ret ;
200 }
201 
202 
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Remove each argument in the input list from our list using remove(const RooAbsArg&).
206 /// and remove each argument as server to owner
207 
208 Bool_t RooSetProxy::remove(const RooAbsCollection& list, Bool_t silent, Bool_t matchByNameOnly)
209 {
210  Bool_t result(false) ;
211 
212  TIterator* iter = list.createIterator() ;
213  RooAbsArg* arg ;
214  while((arg=(RooAbsArg*)iter->Next())) {
215  result |= remove(*arg,silent,matchByNameOnly) ;
216  }
217  delete iter ;
218 
219  return result;
220 }
221 
222 
223 
224 
225 ////////////////////////////////////////////////////////////////////////////////
226 /// Remove all argument inset using remove(const RooAbsArg&).
227 /// and remove each argument as server to owner
228 
230 {
231  if (!isOwning()) {
232  TIterator* iter = createIterator() ;
233  RooAbsArg* arg ;
234  while ((arg=(RooAbsArg*)iter->Next())) {
235  if (!isOwning()) {
236  _owner->removeServer(*arg) ;
237  }
238  }
239  delete iter ;
240  }
241 
243 }
244 
245 
246 
247 
248 ////////////////////////////////////////////////////////////////////////////////
249 /// Assign values of arguments on other set to arguments in this set
250 
252 {
253  RooArgSet::operator=(other) ;
254  return *this ;
255 }
256 
257 
258 
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Process server change operation on owner. Replace elements in set with equally
262 /// named objects in 'newServerList'
263 
264 Bool_t RooSetProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode)
265 {
266  if (getSize()==0) {
267  if (factoryInitMode) {
268  for (const auto arg : newServerList) {
269  if (arg!=_owner) {
270  add(*arg,kTRUE);
271  }
272  }
273  } else {
274  return kTRUE ;
275  }
276  }
277 
278  Bool_t error(kFALSE);
279  for (const auto arg : _list) {
280  RooAbsArg* newArg= arg->findNewServer(newServerList, nameChange);
281  if (newArg && newArg!=_owner) error |= !RooArgSet::replace(*arg,*newArg) ;
282  }
283  return !error ;
284 }
285 
286 
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 /// Printing name of proxy on ostream. If addContents is true
290 /// also print names of objects in set
291 
292 void RooSetProxy::print(ostream& os, Bool_t addContents) const
293 {
294  if (!addContents) {
295  os << name() << "=" ; printStream(os,kValue,kInline) ;
296  } else {
297  os << name() << "=(" ;
298  TIterator* iter = createIterator() ;
299  RooAbsArg* arg ;
300  Bool_t first2(kTRUE) ;
301  while ((arg=(RooAbsArg*)iter->Next())) {
302  if (first2) {
303  first2 = kFALSE ;
304  } else {
305  os << "," ;
306  }
307  arg->printStream(os,kValue|kName,kInline) ;
308  }
309  os << ")" ;
310  delete iter ;
311  }
312 }
RooSetProxy::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
Definition: RooSetProxy.cxx:165
RooAbsArg::isValueServer
Bool_t isValueServer(const RooAbsArg &arg) const
Check if this is serving values to arg.
Definition: RooAbsArg.h:217
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooSetProxy::removeAll
virtual void removeAll()
Remove all argument inset using remove(const RooAbsArg&).
Definition: RooSetProxy.cxx:229
RooSetProxy::_defValueServer
Bool_t _defValueServer
Definition: RooSetProxy.h:78
RooFit.h
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooSetProxy
Definition: RooSetProxy.h:23
RooSetProxy::RooSetProxy
RooSetProxy()
Definition: RooSetProxy.h:46
RooAbsArg.h
RooArgSet::operator=
RooArgSet & operator=(const RooArgSet &other)
Definition: RooArgSet.h:86
RooAbsCollection::remove
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Definition: RooAbsCollection.cxx:584
RooAbsArg::isShapeServer
Bool_t isShapeServer(const RooAbsArg &arg) const
Check if this is serving shape to arg.
Definition: RooAbsArg.h:225
RooArgSet::add
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooSetProxy.h
RooSetProxy::replace
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace object 'var1' in set with 'var2'.
Definition: RooSetProxy.cxx:177
RooSetProxy::name
virtual const char * name() const
Definition: RooSetProxy.h:56
bool
TIterator
Definition: TIterator.h:30
RooAbsArg::registerProxy
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1121
RooArgSet::addOwned
virtual Bool_t addOwned(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
Definition: RooArgSet.h:92
RooAbsArg::findNewServer
RooAbsArg * findNewServer(const RooAbsCollection &newSet, Bool_t nameChange) const
Find the new server in the specified set that matches the old server.
Definition: RooAbsArg.cxx:1029
TStorage::kObjectAllocMemValue
static const UInt_t kObjectAllocMemValue
Definition: TStorage.h:49
RooSetProxy::_owner
RooAbsArg * _owner
Definition: RooSetProxy.h:77
RooSetProxy::remove
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove object 'var' from set and deregister 'var' as server to owner.
Definition: RooSetProxy.cxx:193
RooPrintable::kName
@ kName
Definition: RooPrintable.h:33
malloc
#define malloc
Definition: civetweb.c:1536
RooAbsArg::removeServer
void removeServer(RooAbsArg &server, Bool_t force=kFALSE)
Unregister another RooAbsArg as a server to us, ie, declare that we no longer depend on its value and...
Definition: RooAbsArg.cxx:407
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooAbsCollection::createIterator
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
Definition: RooAbsCollection.h:118
RooAbsCollection::isOwning
Bool_t isOwning() const
Definition: RooAbsCollection.h:230
RooAbsCollection::replace
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
Definition: RooAbsCollection.cxx:533
RooAbsCollection
Definition: RooAbsCollection.h:30
RooPrintable::kValue
@ kValue
Definition: RooPrintable.h:33
RooSetProxy::addOwned
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::addOwned() method insert object into owning set and registers object as server ...
Definition: RooSetProxy.cxx:133
TIterator::Next
virtual TObject * Next()=0
RooSetProxy::operator=
RooSetProxy & operator=(const RooArgSet &other)
Assign values of arguments on other set to arguments in this set.
Definition: RooSetProxy.cxx:251
RooAbsArg::addServer
void addServer(RooAbsArg &server, Bool_t valueProp=kTRUE, Bool_t shapeProp=kFALSE, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
Definition: RooAbsArg.cxx:356
RooSetProxy::addClone
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::addClone() method insert clone of object into owning set and registers cloned o...
Definition: RooSetProxy.cxx:149
RooPrintable::kInline
@ kInline
Definition: RooPrintable.h:34
RooPrintable::printStream
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
Definition: RooPrintable.cxx:75
RooAbsArg
Definition: RooAbsArg.h:73
RooSetProxy::_defShapeServer
Bool_t _defShapeServer
Definition: RooSetProxy.h:79
RooArgSet::addClone
virtual void addClone(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
Definition: RooArgSet.h:96
free
#define free
Definition: civetweb.c:1539
RooAbsCollection::removeAll
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Definition: RooAbsCollection.cxx:643
Riostream.h
RooAbsArg::unRegisterProxy
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1149
RooSetProxy::changePointer
virtual Bool_t changePointer(const RooAbsCollection &newServerSet, Bool_t nameChange=kFALSE, Bool_t factoryInitMode=kFALSE)
Process server change operation on owner.
Definition: RooSetProxy.cxx:264
RooSetProxy::~RooSetProxy
virtual ~RooSetProxy()
Destructor.
Definition: RooSetProxy.cxx:105
RooAbsCollection::getSize
Int_t getSize() const
Definition: RooAbsCollection.h:171
RooAbsCollection::_list
Storage_t _list
Definition: RooAbsCollection.h:249
RooArgSet
Definition: RooArgSet.h:28
RooSetProxy::print
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Printing name of proxy on ostream.
Definition: RooSetProxy.cxx:292