Logo ROOT   6.16/01
Reference Guide
RooListProxy.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 RooListProxy.cxx
19\class RooListProxy
20\ingroup Roofitcore
21
22RooListProxy is the concrete proxy for RooArgList objects.
23A RooListProxy is the only safe mechanism to store a RooArgList
24with RooAbsArg contents in another RooAbsArg.
25The list proxy has the semantic of a RooArgList but also
26takes care of all bookkeeping required when composite objects
27are clone and client-server links need to be redirected.
28**/
29
30
31#include "RooFit.h"
32#include "Riostream.h"
33
34#include "RooListProxy.h"
35#include "RooArgList.h"
36#include "RooAbsArg.h"
37
38using namespace std;
39
41;
42
43
44
45////////////////////////////////////////////////////////////////////////////////
46/// Constructor with proxy name, description and pointer to ownder of
47/// the RooListProxy. The default strategy for value/shape dirty flag
48/// propagation of the list contents to the list owner is controlled
49/// by the defValueServer and defShapeServer flags.
50
51RooListProxy::RooListProxy(const char* inName, const char* /*desc*/, RooAbsArg* owner,
52 Bool_t defValueServer, Bool_t defShapeServer) :
53 RooArgList(inName), _owner(owner),
54 _defValueServer(defValueServer),
55 _defShapeServer(defShapeServer)
56{
57 _owner->registerProxy(*this) ;
58}
59
60
61
62////////////////////////////////////////////////////////////////////////////////
63/// Copy constructor with name of proxy, pointer to owner of this proxy and
64/// reference to list proxy to be copied
65
66RooListProxy::RooListProxy(const char* inName, RooAbsArg* owner, const RooListProxy& other) :
67 RooArgList(other,inName), _owner(owner),
68 _defValueServer(other._defValueServer),
69 _defShapeServer(other._defShapeServer)
70{
71 _owner->registerProxy(*this) ;
72}
73
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Destructor
78
80{
81 if (_owner) _owner->unRegisterProxy(*this) ;
82}
83
84
85
86////////////////////////////////////////////////////////////////////////////////
87/// Add object to list with explicitl directives on value and shape dirty flag propagation
88/// of inserted object to list owner
89
90Bool_t RooListProxy::add(const RooAbsArg& var, Bool_t valueServer, Bool_t shapeServer, Bool_t silent)
91{
92 Bool_t ret=RooArgList::add(var,silent) ;
93 if (ret && _owner) {
94 _owner->addServer((RooAbsArg&)var,valueServer,shapeServer) ;
95 }
96 return ret ;
97}
98
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Reimplementation of standard RooArgList::add()
103
105{
106 return add(var,_defValueServer,_defShapeServer,silent) ;
107}
108
109
110
111////////////////////////////////////////////////////////////////////////////////
112/// Reimplementation of standard RooArgList::addOwned()
113
115{
116 Bool_t ret=RooArgList::addOwned(var,silent) ;
117 if (ret) {
119 }
120 return ret ;
121}
122
123
124////////////////////////////////////////////////////////////////////////////////
125/// Reimplementation of standard RooArgList::replace()
126
128{
129 Bool_t ret=RooArgList::replace(var1,var2) ;
130 if (ret) {
131 _owner->removeServer((RooAbsArg&)var1) ;
133 _owner->isShapeServer(var2)) ;
134 }
135 return ret ;
136}
137
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// Reimplementation of standard RooArgList::remove()
142
143Bool_t RooListProxy::remove(const RooAbsArg& var, Bool_t silent, Bool_t matchByNameOnly)
144{
145 Bool_t ret=RooArgList::remove(var,silent,matchByNameOnly) ;
146 if (ret) {
148 }
149 return ret ;
150}
151
152
153
154////////////////////////////////////////////////////////////////////////////////
155/// Reimplementation of standard RooArgList::removeAll()
156
158{
159 RooFIter iter = fwdIterator();
160 RooAbsArg* arg ;
161 while ((arg=(RooAbsArg*)iter.next())) {
162 _owner->removeServer(*arg) ;
163 }
164
166}
167
168
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Reimplementation of standard RooArgList assignment operator
173
175{
176 RooArgList::operator=(other) ;
177 return *this ;
178}
179
180
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// Internal function that implements consequences of a server redirect on the
185/// owner. If the list contains any element with names identical to those in newServerList
186/// replace them with the instance in newServerList
187
188Bool_t RooListProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode)
189{
190 if (getSize()==0) {
191 if (factoryInitMode) {
192 RooFIter iter = newServerList.fwdIterator() ;
193 RooAbsArg* arg ;
194 while((arg=(RooAbsArg*)iter.next())) {
195 if (arg!=_owner) {
196 add(*arg,kTRUE) ;
197 }
198 }
199 } else {
200 return kTRUE ;
201 }
202 }
203 RooFIter iter = fwdIterator();
204 RooAbsArg* arg ;
205 Bool_t error(kFALSE) ;
206 while ((arg=(RooAbsArg*)iter.next())) {
207
208 RooAbsArg* newArg= arg->findNewServer(newServerList, nameChange);
209 if (newArg && newArg!=_owner) error |= !RooArgList::replace(*arg,*newArg) ;
210 }
211 return !error ;
212}
213
214
215
216////////////////////////////////////////////////////////////////////////////////
217/// Print the name of the proxy, and if requested a summary of
218/// the contained elements as well
219
220void RooListProxy::print(ostream& os, Bool_t addContents) const
221{
222 if (!addContents) {
223 os << name() << "=" ; printStream(os,kValue,kInline) ;
224 } else {
225 os << name() << "=(" ;
226 RooFIter iter = fwdIterator() ;
227 RooAbsArg* arg ;
228 Bool_t first2(kTRUE) ;
229 while ((arg=(RooAbsArg*)iter.next())) {
230 if (first2) {
231 first2 = kFALSE ;
232 } else {
233 os << "," ;
234 }
236 }
237 os << ")" ;
238 }
239}
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:363
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
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:335
Bool_t isValueServer(const RooAbsArg &arg) const
Definition: RooAbsArg.h:134
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1137
Bool_t isShapeServer(const RooAbsArg &arg) const
Definition: RooAbsArg.h:142
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1165
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:386
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:1043
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
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
RooFIter fwdIterator() const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
RooArgList & operator=(const RooArgList &other)
Definition: RooArgList.h:70
RooAbsArg * next()
RooListProxy is the concrete proxy for RooArgList objects.
Definition: RooListProxy.h:25
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::add()
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Reimplementation of standard RooArgList::remove()
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print the name of the proxy, and if requested a summary of the contained elements as well.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Reimplementation of standard RooArgList::replace()
Bool_t _defValueServer
Definition: RooListProxy.h:54
RooListProxy & operator=(const RooArgList &other)
Reimplementation of standard RooArgList assignment operator.
virtual ~RooListProxy()
Destructor.
virtual Bool_t changePointer(const RooAbsCollection &newServerSet, Bool_t nameChange=kFALSE, Bool_t factoryInitMode=kFALSE)
Internal function that implements consequences of a server redirect on the owner.
virtual const char * name() const
Definition: RooListProxy.h:35
Bool_t _defShapeServer
Definition: RooListProxy.h:55
RooAbsArg * _owner
Definition: RooListProxy.h:53
virtual void removeAll()
Reimplementation of standard RooArgList::removeAll()
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Reimplementation of standard RooArgList::addOwned()
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,...
STL namespace.