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
40
41
42////////////////////////////////////////////////////////////////////////////////
43/// Constructor with owner and proxied variable.
44
45RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner,
46 bool valueServer, bool shapeServer, bool proxyOwnsArg) :
47 TNamed(inName,desc), _owner(owner),
48 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
49{
50 _owner->registerProxy(*this) ;
51}
52
53
55////////////////////////////////////////////////////////////////////////////////
56/// Constructor with owner and proxied variable. The valueServer and shapeServer booleans
57/// control if the inserted client-server link in the owner propagates value and/or
58/// shape dirty flags. If proxyOwnsArg is true, the proxy takes ownership of its component
59
60RooArgProxy::RooArgProxy(const char *inName, const char *desc, RooAbsArg *owner, RooAbsArg &arg, bool valueServer,
61 bool shapeServer, bool proxyOwnsArg)
62 : TNamed(inName, desc),
64 _arg(&arg),
65 _valueServer(valueServer),
66 _shapeServer(shapeServer),
67 _isFund(_arg->isFundamental()),
68 _ownArg(proxyOwnsArg)
69{
70 _owner->registerProxy(*this) ;
71}
74
75////////////////////////////////////////////////////////////////////////////////
76/// Copy constructor
77
78RooArgProxy::RooArgProxy(const char* inName, RooAbsArg* owner, const RooArgProxy& other) :
79 TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg),
81 _isFund(other._isFund), _ownArg(other._ownArg)
82{
83 if (_ownArg) {
84 _arg = _arg ? static_cast<RooAbsArg*>(_arg->Clone()) : nullptr ;
85 }
86
87 _owner->registerProxy(*this) ;
88}
89
90
91
92////////////////////////////////////////////////////////////////////////////////
93/// Destructor
94
96{
97 if (_owner) _owner->unRegisterProxy(*this) ;
98 if (_ownArg) delete _arg ;
99}
100
101
102
103////////////////////////////////////////////////////////////////////////////////
104/// Change proxied object to object of same name in given list. If nameChange is true
105/// the replacement object can have a different name and is identified as the replacement object by
106/// the existence of a boolean attribute "origName:MyName" where MyName is the name of this instance
107
108bool RooArgProxy::changePointer(const RooAbsCollection& newServerList, bool nameChange, bool factoryInitMode)
109{
110 RooAbsArg* newArg = nullptr;
111 const bool initEmpty = _arg == nullptr;
112
113 if (_arg) {
114 newArg = _arg->findNewServer(newServerList, nameChange);
115 if (newArg==_owner) newArg = nullptr;
116 } else if (factoryInitMode) {
117 newArg = newServerList.first() ;
118 _owner->addServer(*newArg,_valueServer,_shapeServer) ;
119 }
120
121 if (newArg) {
122 if (_ownArg) {
123 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
124 delete _arg;
125 _ownArg = false;
126 }
127
128 _arg = newArg ;
129 _isFund = _arg->isFundamental();
130 }
131
132 if (initEmpty && !factoryInitMode) return true;
133 return newArg != nullptr;
134}
135
136bool RooArgProxy::changePointer(std::unordered_map<RooAbsArg *, RooAbsArg *> const &replacements)
137{
138 if (!_arg)
139 return true;
140
141 RooAbsArg *newArg = nullptr;
142
143 auto newArgFound = replacements.find(_arg);
144 if (newArgFound != replacements.end()) {
145 newArg = newArgFound->second;
146 }
147
148 if (newArg) {
149 if (_ownArg) {
150 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
151 delete _arg;
152 _ownArg = false;
153 }
154
155 _arg = newArg;
156 _isFund = _arg->isFundamental();
157 }
158
159 return newArg != nullptr;
160}
161
162
163////////////////////////////////////////////////////////////////////////////////
164/// Change the normalization set that should be offered to the
165/// content objects getVal() when evaluated.
166
168{
169 RooAbsProxy::changeNormSet(newNormSet) ;
170 _arg->setProxyNormSet(newNormSet) ;
171}
172
173
174
175////////////////////////////////////////////////////////////////////////////////
176/// Print the name of the proxy on ostream. If addContents is
177/// true also the value of the contained RooAbsArg is also printed
178
179void RooArgProxy::print(ostream& os, bool addContents) const
180{
181 os << name() << "=" << (_arg?_arg->GetName():"nullptr") ;
182 if (_arg && addContents) {
183 os << "=" ;
185 }
186}
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsArg * first() const
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
friend class RooAbsArg
Definition RooAbsProxy.h:62
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 * owner() const
Returns the owner of this proxy.
Definition RooArgProxy.h:57
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:24
TNamed()
Definition TNamed.h:38