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
54
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),
63 _owner(owner),
64 _arg(&arg),
65 _valueServer(valueServer),
66 _shapeServer(shapeServer),
67 _isFund(_arg->isFundamental()),
68 _ownArg(proxyOwnsArg)
69{
70 _owner->registerProxy(*this) ;
71}
72
73
74
75////////////////////////////////////////////////////////////////////////////////
76/// Copy constructor
77
79 TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg),
80 _valueServer(other._valueServer), _shapeServer(other._shapeServer),
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
109{
110 RooAbsArg* newArg = nullptr;
111 const bool initEmpty = _arg == nullptr;
112
113 if (_arg) {
115 if (newArg==_owner) newArg = nullptr;
116 } else if (factoryInitMode) {
117 newArg = newServerList.first() ;
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 ;
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;
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
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}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
const_iterator end() const
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:192
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.
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:24
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:49