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 "RooFit.h"
18
19#include "RooArgProxy.h"
20#include "RooArgSet.h"
21#include "RooAbsArg.h"
22#include <iostream>
23using namespace std ;
24
25/**
26\file RooArgProxy.cxx
27\class RooArgProxy
28\ingroup Roofitcore
29
30RooArgProxy is the abstract interface for RooAbsArg proxy classes.
31A RooArgProxy is the general mechanism to store references
32to other RooAbsArgs inside a RooAbsArg.
33
34Creating a RooArgProxy adds the proxied object to the proxy owners
35server list (thus receiving value/shape dirty flags from it) and
36registers itself with the owning class. The latter allows the
37owning class to change the proxied pointer when the server it
38points to gets redirected (e.g. in a copy or clone operation).
39**/
40
41
43;
44
45
46////////////////////////////////////////////////////////////////////////////////
47/// Constructor with owner and proxied variable.
48
49RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner,
50 Bool_t valueServer, Bool_t shapeServer, Bool_t proxyOwnsArg) :
51 TNamed(inName,desc), _owner(owner), _arg(0),
52 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
53{
54 _owner->registerProxy(*this) ;
55}
56
57
58
59////////////////////////////////////////////////////////////////////////////////
60/// Constructor with owner and proxied variable. The valueServer and shapeServer booleans
61/// control if the inserted client-server link in the owner propagates value and/or
62/// shape dirty flags. If proxyOwnsArg is true, the proxy takes ownership of its component
63
64RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner, RooAbsArg& arg,
65 Bool_t valueServer, Bool_t shapeServer, Bool_t proxyOwnsArg) :
66 TNamed(inName,desc), _owner(owner), _arg(&arg),
67 _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
68{
69 _owner->registerProxy(*this) ;
71}
72
73
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),
80 _valueServer(other._valueServer), _shapeServer(other._shapeServer),
81 _isFund(other._isFund), _ownArg(other._ownArg)
82{
83 if (_ownArg) {
84 _arg = _arg ? (RooAbsArg*) _arg->Clone() : 0 ;
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_t RooArgProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t 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() ;
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
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Change the normalization set that should be offered to the
140/// content objects getVal() when evaluated.
141
142void RooArgProxy::changeDataSet(const RooArgSet* newNormSet)
143{
144 RooAbsProxy::changeNormSet(newNormSet) ;
145 _arg->setProxyNormSet(newNormSet) ;
146}
147
148
149
150////////////////////////////////////////////////////////////////////////////////
151/// Print the name of the proxy on ostream. If addContents is
152/// true also the value of the contained RooAbsArg is also printed
153
154void RooArgProxy::print(ostream& os, Bool_t addContents) const
155{
156 os << name() << "=" << (_arg?_arg->GetName():"NULL") ;
157 if (_arg && addContents) {
158 os << "=" ;
160 }
161}
#define ClassImp(name)
Definition Rtypes.h:364
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:69
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition RooAbsArg.h:81
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
void addServer(RooAbsArg &server, Bool_t valueProp=kTRUE, Bool_t shapeProp=kFALSE, std::size_t refCount=1)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
virtual Bool_t isFundamental() const
Is this object a fundamental type that can be added to a dataset? Fundamental-type subclasses overrid...
Definition RooAbsArg.h:239
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
RooAbsArg * findNewServer(const RooAbsCollection &newSet, Bool_t 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:30
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
RooArgProxy is the abstract interface for RooAbsArg proxy classes.
Definition RooArgProxy.h:24
RooAbsArg * _owner
Definition RooArgProxy.h:64
virtual void changeDataSet(const RooArgSet *newNormSet)
Change the normalization set that should be offered to the content objects getVal() when evaluated.
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print the name of the proxy on ostream.
virtual const char * name() const
Definition RooArgProxy.h:42
virtual Bool_t changePointer(const RooAbsCollection &newServerSet, Bool_t nameChange=kFALSE, Bool_t factoryInitMode=kFALSE)
Change proxied object to object of same name in given list.
Bool_t _isFund
Definition RooArgProxy.h:69
RooAbsArg * _arg
Definition RooArgProxy.h:65
Bool_t _ownArg
Definition RooArgProxy.h:70
Bool_t _valueServer
Definition RooArgProxy.h:67
virtual ~RooArgProxy()
Destructor.
Bool_t _shapeServer
Definition RooArgProxy.h:68
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:35
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
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47