Logo ROOT  
Reference Guide
RooTemplateProxy.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooRealProxy.h,v 1.23 2007/07/12 20:30:28 wouter Exp $
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#ifndef ROO_TEMPLATE_PROXY
17#define ROO_TEMPLATE_PROXY
18
19#include "RooAbsReal.h"
20#include "RooArgProxy.h"
21#include "RooAbsRealLValue.h"
22
23/**
24\class RooTemplateProxy
25\ingroup Roofitcore
26
27A RooTemplateProxy is used to hold references to other objects in an expression tree.
28A `RooGaussian(..., x, mean, sigma)` e.g. stores `x, mean, sigma` as `RooRealProxy (=
29RooTemplateProxy<RooAbsReal>`.
30
31This allows access to their current values, to retrieve batches of observable data, and it
32automatically registers these variables as "servers" of the Gaussian.
33
34Renaming or exchanging objects that serve values to the owner of the proxy is handled automatically.
35
36A few typedefs have been defined:
37- `RooRealProxy = RooTemplateProxy<RooAbsReal>`. Any generic object that converts to a real value.
38- `RooPdfProxy = RooTemplateProxy<RooAbsPdf>`. Handle to PDFs.
39- `RooLVarProxy = RooTemplateProxy<RooAbsRealLValue>`. Handle to real values that can be assigned to.
40- `RooRealVarProxy = RooTemplateProxy<RooRealVar>`. Handle to RooRealVars.
41**/
42
43template<class T>
45public:
46
47 // Constructors, assignment etc.
49
50 ////////////////////////////////////////////////////////////////////////////////
51 /// Constructor with owner.
52 RooTemplateProxy(const char* theName, const char* desc, RooAbsArg* owner,
53 Bool_t valueServer=true, Bool_t shapeServer=false, Bool_t proxyOwnsArg=false)
54 : RooArgProxy(theName, desc, owner, valueServer, shapeServer, proxyOwnsArg) { }
55
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Constructor with owner and proxied real-valued object. The propagation
58 /// of value and shape dirty flags of the contained arg to the owner is
59 /// controlled by the valueServer and shapeServer flags. If ownArg is true
60 /// the proxy will take ownership of the contained arg.
61 RooTemplateProxy(const char* theName, const char* desc, RooAbsArg* owner, T& ref,
62 Bool_t valueServer=true, Bool_t shapeServer=false, Bool_t proxyOwnsArg=false) :
63 RooArgProxy(theName, desc, owner, ref, valueServer, shapeServer, proxyOwnsArg) { }
64
65
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Copy constructor.
68 RooTemplateProxy(const char* theName, RooAbsArg* owner, const RooTemplateProxy& other) :
69 RooArgProxy(theName, owner, other) { }
70
71 virtual TObject* Clone(const char* newName=0) const { return new RooTemplateProxy<T>(newName,_owner,*this); }
72
73 inline operator Double_t() const {
74 return arg().getVal(_nset);
75 }
76
77 RooSpan<const double> getValBatch(std::size_t begin, std::size_t batchSize) const {
78 return arg().getValBatch(begin, batchSize, _nset);
79 }
80
81 /// Return reference to object held in proxy.
82 inline const T& arg() const { return static_cast<T&>(*_arg); }
83
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Change object held in proxy into newRef
86 Bool_t setArg(T& newRef) {
87 if (absArg()) {
88 if (TString(arg().GetName()!=newRef.GetName())) {
89 newRef.setAttribute(Form("ORIGNAME:%s",arg().GetName())) ;
90 }
91 return changePointer(RooArgSet(newRef),kTRUE) ;
92 } else {
93 return changePointer(RooArgSet(newRef),kFALSE,kTRUE);
94 }
95 }
96
97
98 /// Assign a new value to the object pointed to by the proxy. This requires the payload to be assignable (RooAbsRealLValue or derived).
99 RooTemplateProxy<T>& operator=(const Double_t& value) { lvptr()->setVal(value) ; return *this ; }
100 /// Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
101 Double_t min(const char* rname=0) const { return lvptr()->getMin(rname) ; }
102 /// Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
103 Double_t max(const char* rname=0) const { return lvptr()->getMax(rname) ; }
104 /// Check if the range has a lower bound. This requires the payload to be RooAbsRealLValue or derived.
105 Bool_t hasMin(const char* rname=0) const { return lvptr()->hasMin(rname) ; }
106 /// Check if the range has a upper bound. This requires the payload to be RooAbsRealLValue or derived.
107 Bool_t hasMax(const char* rname=0) const { return lvptr()->hasMax(rname) ; }
108
109
110private:
111 ////////////////////////////////////////////////////////////////////////////////
112 /// Return l-value pointer to contents. If the contents derive from RooAbsLValue, the function
113 /// simply returns the pointer.
114 /// If the template parameter of this proxy does not derive from RooAbsLValue, then
115 /// - in a debug build, a dynamic_cast is attempted.
116 /// - in a release build, a static_cast is forced, irrespective of what the type of the object actually is. This
117 /// is dangerous, but equivalent to the behaviour before refactoring.
118 /// \deprecated This function is unneccessary if the template parameter is RooAbsRealLValue or a
119 /// derived type, as arg() will always return the correct type.
121 return lvptr_impl(static_cast<T*>(nullptr));
122 }
123
124 /// Overload with RooAbsRealLValue and derived types. Just returns the pointer.
126 return _arg;
127 }
128
129 /// Overload with base types. Attempts a cast.
130 /// \deprecated The payload of this proxy should be at least RooAbsRealLValue or more derived for
131 /// this function to be called safely.
133 R__SUGGEST_ALTERNATIVE("The template argument of RooTemplateProxy needs to derive from RooAbsRealLValue.") {
134#ifdef NDEBUG
135 return static_cast<RooAbsRealLValue*>(_arg);
136#else
137 auto theArg = dynamic_cast<RooAbsRealLValue*>(_arg);
138 assert(theArg);
139 return theArg;
140#endif
141 }
142
143 ClassDef(RooTemplateProxy,1) // Proxy for a RooAbsReal object
144};
145
146/// Compatibility typedef for old uses of this proxy.
151
152#endif
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition: RConfig.hxx:537
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
char * Form(const char *fmt,...)
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:71
RooArgSet * _nset
Definition: RooAbsProxy.h:54
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual Double_t getMax(const char *name=0) const
Get maximum of currently defined range.
Bool_t hasMax(const char *name=0) const
Check if variable has an upper bound.
virtual void setVal(Double_t value)=0
Bool_t hasMin(const char *name=0) const
Check if variable has a lower bound.
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooArgProxy is the abstact interface for RooAbsArg proxy classes.
Definition: RooArgProxy.h:24
RooAbsArg * _owner
Definition: RooArgProxy.h:51
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.
RooAbsArg * absArg() const
Definition: RooArgProxy.h:37
RooAbsArg * _arg
Definition: RooArgProxy.h:52
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
A simple container to hold a batch of data values.
Definition: RooSpan.h:32
A RooTemplateProxy is used to hold references to other objects in an expression tree.
Double_t min(const char *rname=0) const
Query lower limit of range. This requires the payload to be RooAbsRealLValue or derived.
RooTemplateProxy(const char *theName, const char *desc, RooAbsArg *owner, T &ref, Bool_t valueServer=true, Bool_t shapeServer=false, Bool_t proxyOwnsArg=false)
Constructor with owner and proxied real-valued object.
RooAbsRealLValue * lvptr_impl(RooAbsArg *) const R__SUGGEST_ALTERNATIVE("The template argument of RooTemplateProxy needs to derive from RooAbsRealLValue.")
Overload with base types.
RooSpan< const double > getValBatch(std::size_t begin, std::size_t batchSize) const
virtual TObject * Clone(const char *newName=0) const
Make a clone of an object using the Streamer facility.
RooAbsRealLValue * lvptr() const
Return l-value pointer to contents.
Bool_t setArg(T &newRef)
Change object held in proxy into newRef.
RooTemplateProxy(const char *theName, const char *desc, RooAbsArg *owner, Bool_t valueServer=true, Bool_t shapeServer=false, Bool_t proxyOwnsArg=false)
Constructor with owner.
RooTemplateProxy(const char *theName, RooAbsArg *owner, const RooTemplateProxy &other)
Copy constructor.
Bool_t hasMax(const char *rname=0) const
Check if the range has a upper bound. This requires the payload to be RooAbsRealLValue or derived.
Bool_t hasMin(const char *rname=0) const
Check if the range has a lower bound. This requires the payload to be RooAbsRealLValue or derived.
RooTemplateProxy< T > & operator=(const Double_t &value)
Assign a new value to the object pointed to by the proxy. This requires the payload to be assignable ...
const T & arg() const
Return reference to object held in proxy.
Double_t max(const char *rname=0) const
Query upper limit of range. This requires the payload to be RooAbsRealLValue or derived.
RooAbsRealLValue * lvptr_impl(RooAbsRealLValue *) const
Overload with RooAbsRealLValue and derived types. Just returns the pointer.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
double T(double x)
Definition: ChebyshevPol.h:34