Logo ROOT   6.10/09
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  return malloc(bytes) ;
58 }
59 
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 
63 void RooSetProxy::operator delete (void* ptr)
64 {
65  free(ptr) ;
66 }
67 
68 #endif
69 
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 /// Construct proxy with given name and description, with given owner
73 /// The default value and shape dirty propagation of the set contents
74 /// to the set owner is controlled by flags defValueServer and defShapeServer
75 
76 RooSetProxy::RooSetProxy(const char* inName, const char* /*desc*/, RooAbsArg* owner,
77  Bool_t defValueServer, Bool_t defShapeServer) :
78  RooArgSet(inName), _owner(owner),
79  _defValueServer(defValueServer),
80  _defShapeServer(defShapeServer)
81 {
82  //SetTitle(desc) ;
83  _owner->registerProxy(*this) ;
84  _iter = createIterator() ;
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),
96 {
97  _owner->registerProxy(*this) ;
98  _iter = createIterator() ;
99 }
100 
101 
102 
103 ////////////////////////////////////////////////////////////////////////////////
104 /// Destructor
105 
107 {
108  if (_owner) _owner->unRegisterProxy(*this) ;
109  delete _iter ;
110 }
111 
112 
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Overloaded RooArgSet::add() method insert object into set
116 /// and registers object as server to owner with given value
117 /// and shape dirty flag propagation requests
118 
119 Bool_t RooSetProxy::add(const RooAbsArg& var, Bool_t valueServer, Bool_t shapeServer, Bool_t silent)
120 {
121  Bool_t ret=RooArgSet::add(var,silent) ;
122  if (ret) {
123  _owner->addServer((RooAbsArg&)var,valueServer,shapeServer) ;
124  }
125  return ret ;
126 }
127 
128 
129 
130 ////////////////////////////////////////////////////////////////////////////////
131 /// Overloaded RooArgSet::addOwned() method insert object into owning set
132 /// and registers object as server to owner with default value
133 /// and shape dirty flag propagation
134 
136 {
137  Bool_t ret=RooArgSet::addOwned(var,silent) ;
138  if (ret) {
140  }
141  return ret ;
142 }
143 
144 
145 
146 ////////////////////////////////////////////////////////////////////////////////
147 /// Overloaded RooArgSet::addClone() method insert clone of object into owning set
148 /// and registers cloned object as server to owner with default value
149 /// and shape dirty flag propagation
150 
152 {
153  RooAbsArg* ret=RooArgSet::addClone(var,silent) ;
154  if (ret) {
156  }
157  return ret ;
158 }
159 
160 
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Overloaded RooArgSet::add() method inserts 'var' into set
164 /// and registers 'var' as server to owner with default value
165 /// and shape dirty flag propagation
166 
168 {
169  return add(var,_defValueServer,_defShapeServer,silent) ;
170 }
171 
172 
173 
174 ////////////////////////////////////////////////////////////////////////////////
175 /// Replace object 'var1' in set with 'var2'. Deregister var1 as
176 /// server from owner and register var2 as server to owner with
177 /// default value and shape dirty propagation flags
178 
179 Bool_t RooSetProxy::replace(const RooAbsArg& var1, const RooAbsArg& var2)
180 {
181  Bool_t ret=RooArgSet::replace(var1,var2) ;
182  if (ret) {
183  if (!isOwning()) _owner->removeServer((RooAbsArg&)var1) ;
185  _owner->isShapeServer(var2)) ;
186  }
187  return ret ;
188 }
189 
190 
191 
192 ////////////////////////////////////////////////////////////////////////////////
193 /// Remove object 'var' from set and deregister 'var' as server to owner.
194 
195 Bool_t RooSetProxy::remove(const RooAbsArg& var, Bool_t silent, Bool_t matchByNameOnly)
196 {
197  Bool_t ret=RooArgSet::remove(var,silent,matchByNameOnly) ;
198  if (ret && !isOwning()) {
199  _owner->removeServer((RooAbsArg&)var) ;
200  }
201  return ret ;
202 }
203 
204 
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Remove each argument in the input list from our list using remove(const RooAbsArg&).
208 /// and remove each argument as server to owner
209 
210 Bool_t RooSetProxy::remove(const RooAbsCollection& list, Bool_t silent, Bool_t matchByNameOnly)
211 {
212  Bool_t result(false) ;
213 
214  TIterator* iter = list.createIterator() ;
215  RooAbsArg* arg ;
216  while((arg=(RooAbsArg*)iter->Next())) {
217  result |= remove(*arg,silent,matchByNameOnly) ;
218  }
219  delete iter ;
220 
221  return result;
222 }
223 
224 
225 
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Remove all argument inset using remove(const RooAbsArg&).
229 /// and remove each argument as server to owner
230 
232 {
233  if (!isOwning()) {
234  TIterator* iter = createIterator() ;
235  RooAbsArg* arg ;
236  while ((arg=(RooAbsArg*)iter->Next())) {
237  if (!isOwning()) {
238  _owner->removeServer(*arg) ;
239  }
240  }
241  delete iter ;
242  }
243 
245 }
246 
247 
248 
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Assign values of arguments on other set to arguments in this set
252 
254 {
255  RooArgSet::operator=(other) ;
256  return *this ;
257 }
258 
259 
260 
261 
262 ////////////////////////////////////////////////////////////////////////////////
263 /// Process server change operation on owner. Replace elements in set with equally
264 /// named objects in 'newServerList'
265 
266 Bool_t RooSetProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode)
267 {
268  if (getSize()==0) {
269  if (factoryInitMode) {
270  TIterator* iter = newServerList.createIterator() ;
271  RooAbsArg* arg ;
272  while((arg=(RooAbsArg*)iter->Next())) {
273  if (arg!=_owner) {
274  add(*arg,kTRUE) ;
275  }
276  }
277  delete iter ;
278  } else {
279  return kTRUE ;
280  }
281  }
282 
283  _iter->Reset() ;
284  RooAbsArg* arg ;
285  Bool_t error(kFALSE) ;
286  while ((arg=(RooAbsArg*)_iter->Next())) {
287 
288  RooAbsArg* newArg= arg->findNewServer(newServerList, nameChange);
289  if (newArg && newArg!=_owner) error |= !RooArgSet::replace(*arg,*newArg) ;
290  }
291  return !error ;
292 }
293 
294 
295 
296 ////////////////////////////////////////////////////////////////////////////////
297 /// Printing name of proxy on ostream. If addContents is true
298 /// also print names of objects in set
299 
300 void RooSetProxy::print(ostream& os, Bool_t addContents) const
301 {
302  if (!addContents) {
303  os << name() << "=" ; printStream(os,kValue,kInline) ;
304  } else {
305  os << name() << "=(" ;
306  TIterator* iter = createIterator() ;
307  RooAbsArg* arg ;
308  Bool_t first2(kTRUE) ;
309  while ((arg=(RooAbsArg*)iter->Next())) {
310  if (first2) {
311  first2 = kFALSE ;
312  } else {
313  os << "," ;
314  }
315  arg->printStream(os,kValue|kName,kInline) ;
316  }
317  os << ")" ;
318  delete iter ;
319  }
320 }
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:1173
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&).
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1145
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
#define malloc
Definition: civetweb.c:818
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:1051
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:92
#define ClassImp(name)
Definition: Rtypes.h:336
TIterator * _iter
Definition: RooSetProxy.h:66
Bool_t _defShapeServer
Definition: RooSetProxy.h:65
#define free
Definition: civetweb.c:821
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
double result[121]
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:362
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:413
const Bool_t kTRUE
Definition: RtypesCore.h:91
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...