ROOT  6.06/08
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 "RooArgProxy.h"
21 #include "RooArgSet.h"
22 #include "RooAbsArg.h"
23 #include <iostream>
24 using namespace std ;
25 
26 //////////////////////////////////////////////////////////////////////////////
27 //
28 // BEGIN_HTML
29 // RooArgProxy is the abstact interface for RooAbsArg proxy classes.
30 // A RooArgProxy is the general mechanism to store references
31 // to other RooAbsArgs inside a RooAbsArg
32 //
33 // Creating a RooArgProxy adds the proxied object to the proxy owners
34 // server list (thus receiving value/shape dirty flags from it) and
35 // registers itself with the owning class. The latter allows the
36 // owning class to change the proxied pointer when the server it
37 // points to gets redirected (e.g. in a copy or clone operation)
38 // END_HTML
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),
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 ;
111  Bool_t initEmpty = _arg ? kFALSE : kTRUE ;
112  if (_arg) {
113  newArg= _arg->findNewServer(newServerList, nameChange);
114  if (newArg==_owner) newArg = 0 ;
115  } else if (factoryInitMode) {
116  newArg = newServerList.first() ;
118  } else {
119  newArg = 0 ;
120  }
121  if (newArg) {
122  _arg = newArg ;
123  _isFund = _arg->isFundamental() ;
124  }
125  if (initEmpty && !factoryInitMode) return kTRUE ;
126  return newArg?kTRUE:kFALSE ;
127 }
128 
129 
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Change the normalization set that should be offered to the
133 /// content objects getVal() when evaluated.
134 
135 void RooArgProxy::changeDataSet(const RooArgSet* newNormSet)
136 {
137  RooAbsProxy::changeNormSet(newNormSet) ;
138  _arg->setProxyNormSet(newNormSet) ;
139 }
140 
141 
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Print the name of the proxy on ostream. If addContents is
145 /// true also the value of the contained RooAbsArg is also printed
146 
147 void RooArgProxy::print(ostream& os, Bool_t addContents) const
148 {
149  os << name() << "=" << (_arg?_arg->GetName():"NULL") ;
150  if (_arg && addContents) {
151  os << "=" ;
153  }
154 }
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.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
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, which is interpreted as an OR of &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1172
Bool_t _isFund
Definition: RooArgProxy.h:56
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1144
virtual void changeDataSet(const RooArgSet *newNormSet)
Change the normalization set that should be offered to the content objects getVal() when evaluated...
RooAbsArg * _arg
Definition: RooArgProxy.h:52
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
Definition: RooAbsArg.cxx:1277
STL namespace.
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:1050
Bool_t _valueServer
Definition: RooArgProxy.h:54
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
virtual Bool_t isFundamental() const
Definition: RooAbsArg.h:157
virtual const char * name() const
Definition: RooArgProxy.h:42
Bool_t _shapeServer
Definition: RooArgProxy.h:55
RooAbsArg * first() const
Bool_t _ownArg
Definition: RooArgProxy.h:57
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
Definition: RooAbsProxy.cxx:64
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print the name of the proxy on ostream.
#define ClassImp(name)
Definition: Rtypes.h:279
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
void addServer(RooAbsArg &server, Bool_t valueProp=kTRUE, Bool_t shapeProp=kFALSE)
Register another RooAbsArg as a server to us, ie, declare that we depend on it.
Definition: RooAbsArg.cxx:361
const Bool_t kTRUE
Definition: Rtypes.h:91
RooAbsArg * _owner
Definition: RooArgProxy.h:51
virtual ~RooArgProxy()
Destructor.
Definition: RooArgProxy.cxx:95