ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 \file RooArgProxy.cxx
28 \class RooArgProxy
29 \ingroup Roofitcore
30 
31 RooArgProxy is the abstact interface for RooAbsArg proxy classes.
32 A RooArgProxy is the general mechanism to store references
33 to other RooAbsArgs inside a RooAbsArg
34 
35 Creating a RooArgProxy adds the proxied object to the proxy owners
36 server list (thus receiving value/shape dirty flags from it) and
37 registers itself with the owning class. The latter allows the
38 owning class to change the proxied pointer when the server it
39 points to gets redirected (e.g. in a copy or clone operation)
40 **/
41 
42 
44 ;
45 
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Constructor with owner and proxied variable.
49 
50 RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner,
51  Bool_t valueServer, Bool_t shapeServer, Bool_t proxyOwnsArg) :
52  TNamed(inName,desc), _owner(owner), _arg(0),
53  _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
54 {
55  _owner->registerProxy(*this) ;
56 }
57 
58 
59 
60 ////////////////////////////////////////////////////////////////////////////////
61 /// Constructor with owner and proxied variable. The valueServer and shapeServer booleans
62 /// control if the inserted client-server link in the owner propagates value and/or
63 /// shape dirty flags. If proxyOwnsArg is true, the proxy takes ownership of its component
64 
65 RooArgProxy::RooArgProxy(const char* inName, const char* desc, RooAbsArg* owner, RooAbsArg& arg,
66  Bool_t valueServer, Bool_t shapeServer, Bool_t proxyOwnsArg) :
67  TNamed(inName,desc), _owner(owner), _arg(&arg),
68  _valueServer(valueServer), _shapeServer(shapeServer), _ownArg(proxyOwnsArg)
69 {
70  _owner->registerProxy(*this) ;
72 }
73 
74 
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Copy constructor
78 
79 RooArgProxy::RooArgProxy(const char* inName, RooAbsArg* owner, const RooArgProxy& other) :
80  TNamed(inName,inName), RooAbsProxy(other), _owner(owner), _arg(other._arg),
81  _valueServer(other._valueServer), _shapeServer(other._shapeServer),
82  _isFund(other._isFund), _ownArg(other._ownArg)
83 {
84  if (_ownArg) {
85  _arg = _arg ? (RooAbsArg*) _arg->Clone() : 0 ;
86  }
87 
88  _owner->registerProxy(*this) ;
89 }
90 
91 
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// Destructor
95 
97 {
98  if (_owner) _owner->unRegisterProxy(*this) ;
99  if (_ownArg) delete _arg ;
100 }
101 
102 
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Change proxied object to object of same name in given list. If nameChange is true
106 /// the replacement object can have a different name and is identified as the replacement object by
107 /// the existence of a boolean attribute "origName:MyName" where MyName is the name of this instance
108 
109 Bool_t RooArgProxy::changePointer(const RooAbsCollection& newServerList, Bool_t nameChange, Bool_t factoryInitMode)
110 {
111  RooAbsArg* newArg ;
112  Bool_t initEmpty = _arg ? kFALSE : kTRUE ;
113  if (_arg) {
114  newArg= _arg->findNewServer(newServerList, nameChange);
115  if (newArg==_owner) newArg = 0 ;
116  } else if (factoryInitMode) {
117  newArg = newServerList.first() ;
119  } else {
120  newArg = 0 ;
121  }
122  if (newArg) {
123  _arg = newArg ;
124  _isFund = _arg->isFundamental() ;
125  }
126  if (initEmpty && !factoryInitMode) return kTRUE ;
127  return newArg?kTRUE:kFALSE ;
128 }
129 
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Change the normalization set that should be offered to the
134 /// content objects getVal() when evaluated.
135 
136 void RooArgProxy::changeDataSet(const RooArgSet* newNormSet)
137 {
138  RooAbsProxy::changeNormSet(newNormSet) ;
139  _arg->setProxyNormSet(newNormSet) ;
140 }
141 
142 
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Print the name of the proxy on ostream. If addContents is
146 /// true also the value of the contained RooAbsArg is also printed
147 
148 void RooArgProxy::print(ostream& os, Bool_t addContents) const
149 {
150  os << name() << "=" << (_arg?_arg->GetName():"NULL") ;
151  if (_arg && addContents) {
152  os << "=" ;
154  }
155 }
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.
void unRegisterProxy(RooArgProxy &proxy)
Remove proxy from proxy list.
Definition: RooAbsArg.cxx:1173
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 'enum ContentsOptions' values and in the style given by 'enum StyleOption'.
Bool_t _isFund
Definition: RooArgProxy.h:56
void registerProxy(RooArgProxy &proxy)
Register an RooArgProxy in the proxy list.
Definition: RooAbsArg.cxx:1145
virtual Bool_t isFundamental() const
Definition: RooAbsArg.h:157
virtual const char * name() const
Definition: RooArgProxy.h:42
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
void setProxyNormSet(const RooArgSet *nset)
Forward a change in the cached normalization argset to all the registered proxies.
Definition: RooAbsArg.cxx:1278
ClassImp(RooArgProxy)
RooAbsArg * first() const
Bool_t _valueServer
Definition: RooArgProxy.h:54
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
Bool_t _shapeServer
Definition: RooArgProxy.h:55
RooAbsProxy is the abstact interface for proxy classes.
Definition: RooAbsProxy.h:32
Bool_t _ownArg
Definition: RooArgProxy.h:57
virtual void changeNormSet(const RooArgSet *newNormSet)
Destructor.
Definition: RooAbsProxy.cxx:65
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
RooArgProxy is the abstact interface for RooAbsArg proxy classes.
Definition: RooArgProxy.h:24
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:1051
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:362
virtual void print(std::ostream &os, Bool_t addContents=kFALSE) const
Print the name of the proxy on ostream.
const Bool_t kTRUE
Definition: Rtypes.h:91
RooAbsArg * _owner
Definition: RooArgProxy.h:51
virtual ~RooArgProxy()
Destructor.
Definition: RooArgProxy.cxx:96