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 namespace std ;
22
23/**
24\file RooArgProxy.cxx
25\class RooArgProxy
26\ingroup Roofitcore
27
28RooArgProxy is the abstract 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////////////////////////////////////////////////////////////////////////////////
45/// Constructor with owner and proxied variable.
46
47RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner,
48 bool valueServer, bool shapeServer, bool proxyOwnsArg) :
49 TNamed(inName,desc), _owner(owner), _arg(0),
50 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
51{
52 _owner->registerProxy(*this) ;
53}
54
55
56
57////////////////////////////////////////////////////////////////////////////////
58/// Constructor with owner and proxied variable. The valueServer and shapeServer booleans
59/// control if the inserted client-server link in the owner propagates value and/or
60/// shape dirty flags. If proxyOwnsArg is true, the proxy takes ownership of its component
61
62RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner, RooAbsArg& arg,
63 bool valueServer, bool shapeServer, bool proxyOwnsArg) :
64 TNamed(inName,desc), _owner(owner), _arg(&arg),
65 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
66{
67 _owner->registerProxy(*this) ;
69}
70
71
72
73////////////////////////////////////////////////////////////////////////////////
74/// Copy constructor
75
76RooArgProxy::RooArgProxy(const char* inName, RooAbsArg* owner, const RooArgProxy& other) :
77 TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg),
78 _valueServer(other._valueServer), _shapeServer(other._shapeServer),
79 _isFund(other._isFund), _ownArg(other._ownArg)
80{
81 if (_ownArg) {
82 _arg = _arg ? (RooAbsArg*) _arg->Clone() : 0 ;
83 }
84
85 _owner->registerProxy(*this) ;
86}
87
88
89
90////////////////////////////////////////////////////////////////////////////////
91/// Destructor
92
94{
95 if (_owner) _owner->unRegisterProxy(*this) ;
96 if (_ownArg) delete _arg ;
97}
98
99
100
101////////////////////////////////////////////////////////////////////////////////
102/// Change proxied object to object of same name in given list. If nameChange is true
103/// the replacement object can have a different name and is identified as the replacement object by
104/// the existence of a boolean attribute "origName:MyName" where MyName is the name of this instance
105
106bool RooArgProxy::changePointer(const RooAbsCollection& newServerList, bool nameChange, bool factoryInitMode)
107{
108 RooAbsArg* newArg = nullptr;
109 const bool initEmpty = _arg == nullptr;
110
111 if (_arg) {
112 newArg = _arg->findNewServer(newServerList, nameChange);
113 if (newArg==_owner) newArg = nullptr;
114 } else if (factoryInitMode) {
115 newArg = newServerList.first() ;
117 }
118
119 if (newArg) {
120 if (_ownArg) {
121 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
122 delete _arg;
123 _ownArg = false;
124 }
125
126 _arg = newArg ;
128 }
129
130 if (initEmpty && !factoryInitMode) return true;
131 return newArg != nullptr;
132}
133
134bool RooArgProxy::changePointer(std::unordered_map<RooAbsArg *, RooAbsArg *> const &replacements)
135{
136 if (!_arg)
137 return true;
138
139 RooAbsArg *newArg = nullptr;
140
141 auto newArgFound = replacements.find(_arg);
142 if (newArgFound != replacements.end()) {
143 newArg = newArgFound->second;
144 }
145
146 if (newArg) {
147 if (_ownArg) {
148 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
149 delete _arg;
150 _ownArg = false;
151 }
152
153 _arg = newArg;
155 }
156
157 return newArg != nullptr;
158}
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Change the normalization set that should be offered to the
163/// content objects getVal() when evaluated.
164
166{
167 RooAbsProxy::changeNormSet(newNormSet) ;
168 _arg->setProxyNormSet(newNormSet) ;
169}
170
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Print the name of the proxy on ostream. If addContents is
175/// true also the value of the contained RooAbsArg is also printed
176
177void RooArgProxy::print(ostream& os, bool addContents) const
178{
179 os << name() << "=" << (_arg?_arg->GetName():"nullptr") ;
180 if (_arg && addContents) {
181 os << "=" ;
183 }
184}
#define ClassImp(name)
Definition Rtypes.h:377
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:74
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:86
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooAbsArg.h:247
RooAbsArg * findNewServer(const RooAbsCollection &newSet, bool 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.
RooAbsArg * first() const
RooAbsProxy is the abstact interface for proxy classes.
Definition RooAbsProxy.h:37
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
RooArgProxy is the 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:52
RooAbsArg * _owner
Pointer to owner of proxy.
Definition RooArgProxy.h:78
~RooArgProxy() override
Destructor.
bool _ownArg
If true proxy owns contents.
Definition RooArgProxy.h:84
virtual void changeDataSet(const RooArgSet *newNormSet)
Change the normalization set that should be offered to the content objects getVal() when evaluated.
bool _isFund
If true proxy contains an lvalue.
Definition RooArgProxy.h:83
bool _valueServer
If true contents is value server of owner.
Definition RooArgProxy.h:81
RooArgProxy()
Default constructor.
Definition RooArgProxy.h:30
RooAbsArg * _arg
Pointer to content of proxy.
Definition RooArgProxy.h:79
bool _shapeServer
If true contents is shape server of owner.
Definition RooArgProxy.h:82
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