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
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,
62 bool valueServer, bool shapeServer, bool proxyOwnsArg) :
63 TNamed(inName,desc), _owner(owner), _arg(&arg),
64 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
65{
66 _owner->registerProxy(*this) ;
68}
69
70
71
72////////////////////////////////////////////////////////////////////////////////
73/// Copy constructor
74
75RooArgProxy::RooArgProxy(const char* inName, RooAbsArg* owner, const RooArgProxy& other) :
76 TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg),
77 _valueServer(other._valueServer), _shapeServer(other._shapeServer),
78 _isFund(other._isFund), _ownArg(other._ownArg)
79{
80 if (_ownArg) {
81 _arg = _arg ? (RooAbsArg*) _arg->Clone() : nullptr ;
82 }
83
84 _owner->registerProxy(*this) ;
85}
86
87
88
89////////////////////////////////////////////////////////////////////////////////
90/// Destructor
91
93{
94 if (_owner) _owner->unRegisterProxy(*this) ;
95 if (_ownArg) delete _arg ;
96}
97
98
99
100////////////////////////////////////////////////////////////////////////////////
101/// Change proxied object to object of same name in given list. If nameChange is true
102/// the replacement object can have a different name and is identified as the replacement object by
103/// the existence of a boolean attribute "origName:MyName" where MyName is the name of this instance
104
105bool RooArgProxy::changePointer(const RooAbsCollection& newServerList, bool nameChange, bool factoryInitMode)
106{
107 RooAbsArg* newArg = nullptr;
108 const bool initEmpty = _arg == nullptr;
109
110 if (_arg) {
111 newArg = _arg->findNewServer(newServerList, nameChange);
112 if (newArg==_owner) newArg = nullptr;
113 } else if (factoryInitMode) {
114 newArg = newServerList.first() ;
116 }
117
118 if (newArg) {
119 if (_ownArg) {
120 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
121 delete _arg;
122 _ownArg = false;
123 }
124
125 _arg = newArg ;
127 }
128
129 if (initEmpty && !factoryInitMode) return true;
130 return newArg != nullptr;
131}
132
133bool RooArgProxy::changePointer(std::unordered_map<RooAbsArg *, RooAbsArg *> const &replacements)
134{
135 if (!_arg)
136 return true;
137
138 RooAbsArg *newArg = nullptr;
139
140 auto newArgFound = replacements.find(_arg);
141 if (newArgFound != replacements.end()) {
142 newArg = newArgFound->second;
143 }
144
145 if (newArg) {
146 if (_ownArg) {
147 // We refer to an object that somebody gave to us. Now, we are not owning it, any more.
148 delete _arg;
149 _ownArg = false;
150 }
151
152 _arg = newArg;
154 }
155
156 return newArg != nullptr;
157}
158
159
160////////////////////////////////////////////////////////////////////////////////
161/// Change the normalization set that should be offered to the
162/// content objects getVal() when evaluated.
163
165{
166 RooAbsProxy::changeNormSet(newNormSet) ;
167 _arg->setProxyNormSet(newNormSet) ;
168}
169
170
171
172////////////////////////////////////////////////////////////////////////////////
173/// Print the name of the proxy on ostream. If addContents is
174/// true also the value of the contained RooAbsArg is also printed
175
176void RooArgProxy::print(ostream& os, bool addContents) const
177{
178 os << name() << "=" << (_arg?_arg->GetName():"nullptr") ;
179 if (_arg && addContents) {
180 os << "=" ;
182 }
183}
#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:79
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:91
virtual bool isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooAbsArg.h:251
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
RooAbsProxy is the 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