Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "RooArgSet.h"
39#include "RooAbsArg.h"
40
41using 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
54void* 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
64void 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
77RooSetProxy::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
92RooSetProxy::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
117Bool_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
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
193Bool_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()) {
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
208Bool_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
264Bool_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
292void 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 }
308 }
309 os << ")" ;
310 delete iter ;
311 }
312}
const Bool_t kFALSE
Definition RtypesCore.h:92
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
#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 and a "shape" in RooFi...
Definition RooAbsArg.h:72
Bool_t isValueServer(const RooAbsArg &arg) const
Check if this is serving values to arg.
Definition RooAbsArg.h:217
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Bool_t isShapeServer(const RooAbsArg &arg) const
Check if this is serving shape to arg.
Definition RooAbsArg.h:225
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
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.
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...
RooAbsArg * findNewServer(const RooAbsCollection &newSet, Bool_t nameChange) const
Find the new server in the specified set that matches the old server.
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
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:29
RooArgSet & operator=(const RooArgSet &other)
Definition RooArgSet.h:85
Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to non-owning set.
RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE) override
Add clone of specified element to an owning set.
Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE) override
Add element to an owning set.
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:23
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) override
Remove object 'var' from set and deregister 'var' as server to owner.
RooSetProxy & operator=(const RooArgSet &other)
Assign values of arguments on other set to arguments in this set.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::add() method inserts 'var' into set and registers 'var' as server to owner with...
virtual ~RooSetProxy()
Destructor.
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::addOwned() method insert object into owning set and registers object as server ...
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE) override
Overloaded RooArgSet::addClone() method insert clone of object into owning set and registers cloned o...
virtual const char * name() const override
Definition RooSetProxy.h:42
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2) override
Replace object 'var1' in set with 'var2'.
Bool_t _defValueServer
Definition RooSetProxy.h:67
virtual void removeAll() override
Remove all argument inset using remove(const RooAbsArg&).
virtual Bool_t changePointer(const RooAbsCollection &newServerSet, Bool_t nameChange=kFALSE, Bool_t factoryInitMode=kFALSE) override
Process server change operation on owner.
RooAbsArg * _owner
Definition RooSetProxy.h:66
Bool_t _defShapeServer
Definition RooSetProxy.h:68
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const override
Printing name of proxy on ostream.
Iterator abstract base class.
Definition TIterator.h:30
virtual TObject * Next()=0
static const UInt_t kObjectAllocMemValue
Definition TStorage.h:49