Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooArgProxy.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#include "RooArgProxy.h"
18#include "RooArgSet.h"
19#include "RooAbsArg.h"
20#include <iostream>
21using std::ostream;
22
23/**
24\file RooArgProxy.cxx
25\class RooArgProxy
26\ingroup Roofitcore
27
28Abstract interface for RooAbsArg proxy classes.
29A RooArgProxy is the general mechanism to store references
30to other RooAbsArgs inside a RooAbsArg.
31
32Creating a RooArgProxy adds the proxied object to the proxy owners
33server list (thus receiving value/shape dirty flags from it) and
34registers itself with the owning class. The latter allows the
35owning class to change the proxied pointer when the server it
36points to gets redirected (e.g. in a copy or clone operation).
37**/
38
39
41
42
43////////////////////////////////////////////////////////////////////////////////
44/// Constructor with owner and proxied variable.
45
46RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner,
47 bool valueServer, bool shapeServer, bool proxyOwnsArg) :
48 TNamed(inName,desc), _owner(owner),
49 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
50{
51 _owner->registerProxy(*this) ;
52}
53
54
55
56////////////////////////////////////////////////////////////////////////////////
57/// Constructor with owner and proxied variable. The valueServer and shapeServer booleans
58/// control if the inserted client-server link in the owner propagates value and/or
59/// shape dirty flags. If proxyOwnsArg is true, the proxy takes ownership of its component
60
61RooArgProxy::RooArgProxy(const char *inName, const char *desc, RooAbsArg *owner, RooAbsArg &arg, bool valueServer,
62 bool shapeServer, bool proxyOwnsArg)
63 : TNamed(inName, desc),
64 _owner(owner),
65 _arg(&arg),
66 _valueServer(valueServer),
67 _shapeServer(shapeServer),
68 _isFund(_arg->isFundamental()),
69 _ownArg(proxyOwnsArg)
70{
71 _owner->registerProxy(*this) ;
72}
73
74
75
76////////////////////////////////////////////////////////////////////////////////
77/// Copy constructor
78
79RooArgProxy::RooArgProxy(const char* inName, RooAbsArg* owner, const RooArgProxy& other) :
80 TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg),
81 _valueServer(other._valueServer), _shapeServer(other._shapeServer),
82 _isFund(other._isFund), _ownArg(other._ownArg)
83{
84 if (_ownArg) {
85 _arg = _arg ? static_cast<RooAbsArg*>(_arg->Clone()) : nullptr ;
86 }
87
88 _owner->registerProxy(*this) ;
89}
90
91
92
93////////////////////////////////////////////////////////////////////////////////
94/// Destructor
95
97{
98 if (_owner) _owner->unRegisterProxy(*this) ;
99 if (_ownArg) delete _arg ;
100}
101
102
103
104////////////////////////////////////////////////////////////////////////////////
105/// Change proxied object to object of same name in given list. If nameChange is true
106/// the replacement object can have a different name and is identified as the replacement object by
107/// the existence of a boolean attribute "origName:MyName" where MyName is the name of this instance
108
109bool RooArgProxy::changePointer(const RooAbsCollection& newServerList, bool nameChange, bool factoryInitMode)
110{
111 RooAbsArg* newArg = nullptr;
112 const bool initEmpty = _arg == nullptr;
113
114 if (_arg) {
115 newArg = _arg->findNewServer(newServerList, nameChange);
116 if (newArg==_owner) newArg = nullptr;
117 } else if (factoryInitMode) {
118 newArg = newServerList.first() ;
120 }
121
122 if (newArg) {
123 if (_ownArg) {
124 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
125 delete _arg;
126 _ownArg = false;
127 }
128
129 _arg = newArg ;
131 }
132
133 if (initEmpty && !factoryInitMode) return true;
134 return newArg != nullptr;
135}
136
137bool RooArgProxy::changePointer(std::unordered_map<RooAbsArg *, RooAbsArg *> const &replacements)
138{
139 if (!_arg)
140 return true;
141
142 RooAbsArg *newArg = nullptr;
143
144 auto newArgFound = replacements.find(_arg);
145 if (newArgFound != replacements.end()) {
146 newArg = newArgFound->second;
147 }
148
149 if (newArg) {
150 if (_ownArg) {
151 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
152 delete _arg;
153 _ownArg = false;
154 }
155
156 _arg = newArg;
158 }
159
160 return newArg != nullptr;
161}
162
163
164////////////////////////////////////////////////////////////////////////////////
165/// Change the normalization set that should be offered to the
166/// content objects getVal() when evaluated.
167
169{
170 RooAbsProxy::changeNormSet(newNormSet) ;
171 _arg->setProxyNormSet(newNormSet) ;
172}
173
174
175
176////////////////////////////////////////////////////////////////////////////////
177/// Print the name of the proxy on ostream. If addContents is
178/// true also the value of the contained RooAbsArg is also printed
179
180void RooArgProxy::print(ostream& os, bool addContents) const
181{
182 os << name() << "=" << (_arg?_arg->GetName():"nullptr") ;
183 if (_arg && addContents) {
184 os << "=" ;
186 }
187}
#define ClassImp(name)
Definition Rtypes.h:377
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
void addServer(RooAbsArg &server, bool valueProp=true, bool shapeProp=false, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
TObject * Clone(const char *newname=nullptr) const override
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:89
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooAbsArg.h:249
RooAbsArg * findNewServer(const RooAbsCollection &newSet, bool nameChange) const
Find the new server in the specified set that matches the old server.
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsArg * first() const
Abstract interface for proxy classes.
Definition RooAbsProxy.h:37
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
Abstract interface for RooAbsArg proxy classes.
Definition RooArgProxy.h:24
void print(std::ostream &os, bool addContents=false) const override
Print the name of the proxy on ostream.
const char * name() const override
Return name of proxy.
Definition RooArgProxy.h:51
RooAbsArg * _owner
Pointer to owner of proxy.
Definition RooArgProxy.h:77
~RooArgProxy() override
Destructor.
bool _ownArg
If true proxy owns contents.
Definition RooArgProxy.h:83
virtual void changeDataSet(const RooArgSet *newNormSet)
Change the normalization set that should be offered to the content objects getVal() when evaluated.
RooArgProxy()=default
Default constructor.
bool _isFund
If true proxy contains an lvalue.
Definition RooArgProxy.h:82
bool _valueServer
If true contents is value server of owner.
Definition RooArgProxy.h:80
RooAbsArg * _arg
Pointer to content of proxy.
Definition RooArgProxy.h:78
bool _shapeServer
If true contents is shape server of owner.
Definition RooArgProxy.h:81
bool changePointer(const RooAbsCollection &newServerSet, bool nameChange=false, bool factoryInitMode=false) override
Change proxied object to object of same name in given list.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
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,...
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47