Logo ROOT  
Reference Guide
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>
23 using namespace std ;
24 
25 /**
26 \file RooArgProxy.cxx
27 \class RooArgProxy
28 \ingroup Roofitcore
29 
30 RooArgProxy is the abstract interface for RooAbsArg proxy classes.
31 A RooArgProxy is the general mechanism to store references
32 to other RooAbsArgs inside a RooAbsArg.
33 
34 Creating a RooArgProxy adds the proxied object to the proxy owners
35 server list (thus receiving value/shape dirty flags from it) and
36 registers itself with the owning class. The latter allows the
37 owning class to change the proxied pointer when the server it
38 points 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 
49 RooArgProxy::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 
64 RooArgProxy::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 
78 RooArgProxy::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 
108 Bool_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 
142 void 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 
154 void RooArgProxy::print(ostream& os, Bool_t addContents) const
155 {
156  os << name() << "=" << (_arg?_arg->GetName():"NULL") ;
157  if (_arg && addContents) {
158  os << "=" ;
160  }
161 }
RooAbsArg::Clone
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:84
RooArgProxy::_isFund
Bool_t _isFund
Definition: RooArgProxy.h:56
RooAbsCollection::first
RooAbsArg * first() const
Definition: RooAbsCollection.h:177
RooFit.h
RooArgSet.h
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
RooArgProxy::changeDataSet
virtual void changeDataSet(const RooArgSet *newNormSet)
Change the normalization set that should be offered to the content objects getVal() when evaluated.
Definition: RooArgProxy.cxx:142
RooArgProxy::_arg
RooAbsArg * _arg
Definition: RooArgProxy.h:52
RooArgProxy::changePointer
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.
Definition: RooArgProxy.cxx:108
RooArgProxy::_valueServer
Bool_t _valueServer
Definition: RooArgProxy.h:54
RooAbsArg.h
bool
RooAbsArg::registerProxy
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1153
RooAbsArg::findNewServer
RooAbsArg * findNewServer(const RooAbsCollection &newSet, Bool_t nameChange) const
Find the new server in the specified set that matches the old server.
Definition: RooAbsArg.cxx:1061
RooArgProxy
RooArgProxy is the abstract interface for RooAbsArg proxy classes.
Definition: RooArgProxy.h:24
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
RooAbsCollection
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Definition: RooAbsCollection.h:31
RooAbsArg::setProxyNormSet
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
Definition: RooAbsArg.cxx:1286
RooPrintable::kValue
@ kValue
Definition: RooPrintable.h:33
RooArgProxy::name
virtual const char * name() const
Definition: RooArgProxy.h:42
RooAbsProxy::changeNormSet
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
Definition: RooAbsProxy.cxx:64
RooArgProxy::_shapeServer
Bool_t _shapeServer
Definition: RooArgProxy.h:55
RooAbsArg::isFundamental
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:243
RooAbsArg::addServer
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.
Definition: RooAbsArg.cxx:388
RooArgProxy::_ownArg
Bool_t _ownArg
Definition: RooArgProxy.h:57
RooArgProxy::_owner
RooAbsArg * _owner
Definition: RooArgProxy.h:51
RooPrintable::kInline
@ kInline
Definition: RooPrintable.h:34
RooArgProxy::RooArgProxy
RooArgProxy()
Definition: RooArgProxy.h:28
RooArgProxy::print
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print the name of the proxy on ostream.
Definition: RooArgProxy.cxx:154
RooPrintable::printStream
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,...
Definition: RooPrintable.cxx:75
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooAbsProxy
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:30
RooArgProxy::~RooArgProxy
virtual ~RooArgProxy()
Destructor.
Definition: RooArgProxy.cxx:95
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooAbsArg::unRegisterProxy
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1181
RooArgProxy.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29