Logo ROOT   6.14/05
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 "RooSetProxy.h"
39 #include "RooArgSet.h"
40 #include "RooAbsArg.h"
41 
42 using namespace std;
43 
45 ;
46 
47 
48 #ifdef USEMEMPOOL
49 
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Overload new operator must be implemented because it is overloaded
52 /// in the RooArgSet base class. Perform standard memory allocation
53 /// here instead of memory pool management performed in RooArgSet
54 
55 void* RooSetProxy::operator new (size_t bytes)
56 {
57  auto mem = malloc(bytes) ;
58  memset(mem, TStorage::kObjectAllocMemValue, bytes);
59  return mem;
60 }
61 
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 
65 void RooSetProxy::operator delete (void* ptr)
66 {
67  free(ptr) ;
68 }
69 
70 #endif
71 
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Construct proxy with given name and description, with given owner
75 /// The default value and shape dirty propagation of the set contents
76 /// to the set owner is controlled by flags defValueServer and defShapeServer
77 
78 RooSetProxy::RooSetProxy(const char* inName, const char* /*desc*/, RooAbsArg* owner,
79  Bool_t defValueServer, Bool_t defShapeServer) :
80  RooArgSet(inName), _owner(owner),
81  _defValueServer(defValueServer),
82  _defShapeServer(defShapeServer)
83 {
84  //SetTitle(desc) ;
85  _owner->registerProxy(*this) ;
86  _iter = createIterator() ;
87 }
88 
89 
90 
91 ////////////////////////////////////////////////////////////////////////////////
92 /// Copy constructor
93 
94 RooSetProxy::RooSetProxy(const char* inName, RooAbsArg* owner, const RooSetProxy& other) :
95  RooArgSet(other,inName), _owner(owner),
98 {
99  _owner->registerProxy(*this) ;
100  _iter = createIterator() ;
101 }
102 
103 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// Destructor
107 
109 {
110  if (_owner) _owner->unRegisterProxy(*this) ;
111  delete _iter ;
112 }
113 
114 
115 
116 ////////////////////////////////////////////////////////////////////////////////
117 /// Overloaded RooArgSet::add() method insert object into set
118 /// and registers object as server to owner with given value
119 /// and shape dirty flag propagation requests
120 
121 Bool_t RooSetProxy::add(const RooAbsArg& var, Bool_t valueServer, Bool_t shapeServer, Bool_t silent)
122 {
123  Bool_t ret=RooArgSet::add(var,silent) ;
124  if (ret) {
125  _owner->addServer((RooAbsArg&)var,valueServer,shapeServer) ;
126  }
127  return ret ;
128 }
129 
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Overloaded RooArgSet::addOwned() method insert object into owning set
134 /// and registers object as server to owner with default value
135 /// and shape dirty flag propagation
136 
138 {
139  Bool_t ret=RooArgSet::addOwned(var,silent) ;
140  if (ret) {
142  }
143  return ret ;
144 }
145 
146 
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// Overloaded RooArgSet::addClone() method insert clone of object into owning set
150 /// and registers cloned object as server to owner with default value
151 /// and shape dirty flag propagation
152 
154 {
155  RooAbsArg* ret=RooArgSet::addClone(var,silent) ;
156  if (ret) {
158  }
159  return ret ;
160 }
161 
162 
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 /// Overloaded RooArgSet::add() method inserts 'var' into set
166 /// and registers 'var' as server to owner with default value
167 /// and shape dirty flag propagation
168 
170 {
171  return add(var,_defValueServer,_defShapeServer,silent) ;
172 }
173 
174 
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Replace object 'var1' in set with 'var2'. Deregister var1 as
178 /// server from owner and register var2 as server to owner with
179 /// default value and shape dirty propagation flags
180 
181 Bool_t RooSetProxy::replace(const RooAbsArg& var1, const RooAbsArg& var2)
182 {
183  Bool_t ret=RooArgSet::replace(var1,var2) ;
184  if (ret) {
185  if (!isOwning()) _owner->removeServer((RooAbsArg&)var1) ;
187  _owner->isShapeServer(var2)) ;
188  }
189  return ret ;
190 }
191 
192 
193 
194 ////////////////////////////////////////////////////////////////////////////////
195 /// Remove object 'var' from set and deregister 'var' as server to owner.
196 
197 Bool_t RooSetProxy::remove(const RooAbsArg& var, Bool_t silent, Bool_t matchByNameOnly)
198 {
199  Bool_t ret=RooArgSet::remove(var,silent,matchByNameOnly) ;
200  if (ret && !isOwning()) {
201  _owner->removeServer((RooAbsArg&)var) ;
202  }
203  return ret ;
204 }
205 
206 
207 
208 ////////////////////////////////////////////////////////////////////////////////
209 /// Remove each argument in the input list from our list using remove(const RooAbsArg&).
210 /// and remove each argument as server to owner
211 
212 Bool_t RooSetProxy::remove(const RooAbsCollection& list, Bool_t silent, Bool_t matchByNameOnly)
213 {
214  Bool_t result(false) ;
215 
216  TIterator* iter = list.createIterator() ;
217  RooAbsArg* arg ;
218  while((arg=(RooAbsArg*)iter->Next())) {
219  result |= remove(*arg,silent,matchByNameOnly) ;
220  }
221  delete iter ;
222 
223  return result;
224 }
225 
226 
227 
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Remove all argument inset using remove(const RooAbsArg&).
231 /// and remove each argument as server to owner
232 
234 {
235  if (!isOwning()) {
236  TIterator* iter = createIterator() ;
237  RooAbsArg* arg ;
238  while ((arg=(RooAbsArg*)iter->Next())) {
239  if (!isOwning()) {
240  _owner->removeServer(*arg) ;
241  }
242  }
243  delete iter ;
244  }
245 
247 }
248 
249 
250 
251 
252 ////////////////////////////////////////////////////////////////////////////////
253 /// Assign values of arguments on other set to arguments in this set
254 
256 {
257  RooArgSet::operator=(other) ;
258  return *this ;
259 }
260 
261 
262 
263 
264 ////////////////////////////////////////////////////////////////////////////////
265 /// Process server change operation on owner. Replace elements in set with equally
266 /// named objects in 'newServerList'
267 
268 Bool_t RooSetProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode)
269 {
270  if (getSize()==0) {
271  if (factoryInitMode) {
272  TIterator* iter = newServerList.createIterator() ;
273  RooAbsArg* arg ;
274  while((arg=(RooAbsArg*)iter->Next())) {
275  if (arg!=_owner) {
276  add(*arg,kTRUE) ;
277  }
278  }
279  delete iter ;
280  } else {
281  return kTRUE ;
282  }
283  }
284 
285  _iter->Reset() ;
286  RooAbsArg* arg ;
287  Bool_t error(kFALSE) ;
288  while ((arg=(RooAbsArg*)_iter->Next())) {
289 
290  RooAbsArg* newArg= arg->findNewServer(newServerList, nameChange);
291  if (newArg && newArg!=_owner) error |= !RooArgSet::replace(*arg,*newArg) ;
292  }
293  return !error ;
294 }
295 
296 
297 
298 ////////////////////////////////////////////////////////////////////////////////
299 /// Printing name of proxy on ostream. If addContents is true
300 /// also print names of objects in set
301 
302 void RooSetProxy::print(ostream& os, Bool_t addContents) const
303 {
304  if (!addContents) {
305  os << name() << "=" ; printStream(os,kValue,kInline) ;
306  } else {
307  os << name() << "=(" ;
308  TIterator* iter = createIterator() ;
309  RooAbsArg* arg ;
310  Bool_t first2(kTRUE) ;
311  while ((arg=(RooAbsArg*)iter->Next())) {
312  if (first2) {
313  first2 = kFALSE ;
314  } else {
315  os << "," ;
316  }
317  arg->printStream(os,kValue|kName,kInline) ;
318  }
319  os << ")" ;
320  delete iter ;
321  }
322 }
RooArgSet & operator=(const RooArgSet &other)
Definition: RooArgSet.h:84
TIterator * createIterator(Bool_t dir=kIterForward) const
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, which is interpreted as an OR of &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1164
Bool_t _defValueServer
Definition: RooSetProxy.h:64
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:86
virtual void Reset()=0
virtual Bool_t changePointer(const RooAbsCollection &newServerSet, Bool_t nameChange=kFALSE, Bool_t factoryInitMode=kFALSE)
do not persist
Bool_t isOwning() const
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
virtual void removeAll()
Remove all argument inset using remove(const RooAbsArg&).
static const UInt_t kObjectAllocMemValue
Definition: TStorage.h:43
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1136
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
#define malloc
Definition: civetweb.c:1347
Iterator abstract base class.
Definition: TIterator.h:30
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:1042
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove object &#39;var&#39; from set and deregister &#39;var&#39; as server to owner.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace object &#39;var1&#39; in set with &#39;var2&#39;.
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:94
virtual const char * name() const
Definition: RooSetProxy.h:42
Int_t getSize() const
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::addOwned() method insert object into owning set and registers object as server ...
RooAbsArg * _owner
Definition: RooSetProxy.h:63
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:90
RooSetProxy & operator=(const RooArgSet &other)
Assign values of arguments on other set to arguments in this set.
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define ClassImp(name)
Definition: Rtypes.h:359
TIterator * _iter
Definition: RooSetProxy.h:66
Bool_t _defShapeServer
Definition: RooSetProxy.h:65
#define free
Definition: civetweb.c:1350
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Bool_t isShapeServer(const RooAbsArg &arg) const
Definition: RooAbsArg.h:142
virtual ~RooSetProxy()
Destructor.
Bool_t isValueServer(const RooAbsArg &arg) const
Definition: RooAbsArg.h:134
virtual TObject * Next()=0
RooSetProxy is the concrete proxy for RooArgSet objects.
Definition: RooSetProxy.h:24
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
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...
void addServer(RooAbsArg &server, Bool_t valueProp=kTRUE, Bool_t shapeProp=kFALSE)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
Definition: RooAbsArg.cxx:334
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:385
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Printing name of proxy on ostream.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Overloaded RooArgSet::add() method inserts &#39;var&#39; into set and registers &#39;var&#39; as server to owner with...