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
22RooSetProxy is the concrete proxy for RooArgSet objects.
23A RooSetProxy is the general mechanism to store a RooArgSet
24with RooAbsArgs in a RooAbsArg.
25
26Creating a RooSetProxy adds all members of the proxied RooArgSet to the proxy owners
27server list (thus receiving value/shape dirty flags from it) and
28registers itself with the owning class. The latter allows the
29owning class to update the pointers of RooArgSet contents to reflect
30the 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
42using namespace std;
43
45;
46
47
48#ifdef USEMEMPOOLFORARGSET
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
55void* 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
65void 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
78RooSetProxy::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}
87
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// Copy constructor
92
93RooSetProxy::RooSetProxy(const char* inName, RooAbsArg* owner, const RooSetProxy& other) :
94 RooArgSet(other,inName), _owner(owner),
95 _defValueServer(other._defValueServer),
96 _defShapeServer(other._defShapeServer)
97{
98 _owner->registerProxy(*this) ;
99}
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Destructor
105
107{
108 if (_owner) _owner->unRegisterProxy(*this) ;
109}
110
111
112
113////////////////////////////////////////////////////////////////////////////////
114/// Overloaded RooArgSet::add() method insert object into set
115/// and registers object as server to owner with given value
116/// and shape dirty flag propagation requests
117
118Bool_t RooSetProxy::add(const RooAbsArg& var, Bool_t valueServer, Bool_t shapeServer, Bool_t silent)
119{
120 Bool_t ret=RooArgSet::add(var,silent) ;
121 if (ret) {
122 _owner->addServer((RooAbsArg&)var,valueServer,shapeServer) ;
123 }
124 return ret ;
125}
126
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Overloaded RooArgSet::addOwned() method insert object into owning set
131/// and registers object as server to owner with default value
132/// and shape dirty flag propagation
133
135{
136 Bool_t ret=RooArgSet::addOwned(var,silent) ;
137 if (ret) {
139 }
140 return ret ;
141}
142
143
144
145////////////////////////////////////////////////////////////////////////////////
146/// Overloaded RooArgSet::addClone() method insert clone of object into owning set
147/// and registers cloned object as server to owner with default value
148/// and shape dirty flag propagation
149
151{
152 RooAbsArg* ret=RooArgSet::addClone(var,silent) ;
153 if (ret) {
155 }
156 return ret ;
157}
158
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Overloaded RooArgSet::add() method inserts 'var' into set
163/// and registers 'var' as server to owner with default value
164/// and shape dirty flag propagation
165
167{
168 return add(var,_defValueServer,_defShapeServer,silent) ;
169}
170
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Replace object 'var1' in set with 'var2'. Deregister var1 as
175/// server from owner and register var2 as server to owner with
176/// default value and shape dirty propagation flags
177
179{
180 Bool_t ret=RooArgSet::replace(var1,var2) ;
181 if (ret) {
182 if (!isOwning()) _owner->removeServer((RooAbsArg&)var1) ;
184 _owner->isShapeServer(var2)) ;
185 }
186 return ret ;
187}
188
189
190
191////////////////////////////////////////////////////////////////////////////////
192/// Remove object 'var' from set and deregister 'var' as server to owner.
193
194Bool_t RooSetProxy::remove(const RooAbsArg& var, Bool_t silent, Bool_t matchByNameOnly)
195{
196 Bool_t ret=RooArgSet::remove(var,silent,matchByNameOnly) ;
197 if (ret && !isOwning()) {
199 }
200 return ret ;
201}
202
203
204
205////////////////////////////////////////////////////////////////////////////////
206/// Remove each argument in the input list from our list using remove(const RooAbsArg&).
207/// and remove each argument as server to owner
208
209Bool_t RooSetProxy::remove(const RooAbsCollection& list, Bool_t silent, Bool_t matchByNameOnly)
210{
211 Bool_t result(false) ;
212
213 TIterator* iter = list.createIterator() ;
214 RooAbsArg* arg ;
215 while((arg=(RooAbsArg*)iter->Next())) {
216 result |= remove(*arg,silent,matchByNameOnly) ;
217 }
218 delete iter ;
219
220 return result;
221}
222
223
224
225
226////////////////////////////////////////////////////////////////////////////////
227/// Remove all argument inset using remove(const RooAbsArg&).
228/// and remove each argument as server to owner
229
231{
232 if (!isOwning()) {
233 TIterator* iter = createIterator() ;
234 RooAbsArg* arg ;
235 while ((arg=(RooAbsArg*)iter->Next())) {
236 if (!isOwning()) {
237 _owner->removeServer(*arg) ;
238 }
239 }
240 delete iter ;
241 }
242
244}
245
246
247
248
249////////////////////////////////////////////////////////////////////////////////
250/// Assign values of arguments on other set to arguments in this set
251
253{
254 RooArgSet::operator=(other) ;
255 return *this ;
256}
257
258
259
260
261////////////////////////////////////////////////////////////////////////////////
262/// Process server change operation on owner. Replace elements in set with equally
263/// named objects in 'newServerList'
264
265Bool_t RooSetProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode)
266{
267 if (getSize()==0) {
268 if (factoryInitMode) {
269 for (const auto arg : newServerList) {
270 if (arg!=_owner) {
271 add(*arg,kTRUE);
272 }
273 }
274 } else {
275 return kTRUE ;
276 }
277 }
278
279 Bool_t error(kFALSE);
280 for (const auto arg : _list) {
281 RooAbsArg* newArg= arg->findNewServer(newServerList, nameChange);
282 if (newArg && newArg!=_owner) error |= !RooArgSet::replace(*arg,*newArg) ;
283 }
284 return !error ;
285}
286
287
288
289////////////////////////////////////////////////////////////////////////////////
290/// Printing name of proxy on ostream. If addContents is true
291/// also print names of objects in set
292
293void RooSetProxy::print(ostream& os, Bool_t addContents) const
294{
295 if (!addContents) {
296 os << name() << "=" ; printStream(os,kValue,kInline) ;
297 } else {
298 os << name() << "=(" ;
299 TIterator* iter = createIterator() ;
300 RooAbsArg* arg ;
301 Bool_t first2(kTRUE) ;
302 while ((arg=(RooAbsArg*)iter->Next())) {
303 if (first2) {
304 first2 = kFALSE ;
305 } else {
306 os << "," ;
307 }
309 }
310 os << ")" ;
311 delete iter ;
312 }
313}
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
#define free
Definition: civetweb.c:1539
#define malloc
Definition: civetweb.c:1536
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
Bool_t isValueServer(const RooAbsArg &arg) const
Check if this is serving values to arg.
Definition: RooAbsArg.h:181
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1127
Bool_t isShapeServer(const RooAbsArg &arg) const
Check if this is serving shape to arg.
Definition: RooAbsArg.h:189
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1155
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:358
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:409
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:1035
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
Int_t getSize() const
Bool_t isOwning() const
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooArgSet & operator=(const RooArgSet &other)
Definition: RooArgSet.h:86
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
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
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
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,...
RooSetProxy is the concrete proxy for RooArgSet objects.
Definition: RooSetProxy.h:24
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...
virtual const char * name() const
Definition: RooSetProxy.h:43
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Printing name of proxy on ostream.
RooSetProxy & operator=(const RooArgSet &other)
Assign values of arguments on other set to arguments in this set.
virtual ~RooSetProxy()
Destructor.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace object 'var1' in set with 'var2'.
Bool_t _defValueServer
Definition: RooSetProxy.h:65
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...
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.
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:64
Bool_t _defShapeServer
Definition: RooSetProxy.h:66
virtual Bool_t changePointer(const RooAbsCollection &newServerSet, Bool_t nameChange=kFALSE, Bool_t factoryInitMode=kFALSE)
Process server change operation on owner.
virtual void removeAll()
Remove all argument inset using remove(const RooAbsArg&).
Iterator abstract base class.
Definition: TIterator.h:30
virtual TObject * Next()=0
static const UInt_t kObjectAllocMemValue
Definition: TStorage.h:49