Logo ROOT  
Reference Guide
RooCmdArg.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooCmdArg.h,v 1.10 2007/05/11 09:11:30 verkerke 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
17#ifndef ROO_CMD_ARG
18#define ROO_CMD_ARG
19
20#include "TNamed.h"
21#include "RooLinkedList.h"
22#include <string>
23
24class RooArgSet ;
25
26class RooCmdArg final : public TNamed {
27public:
28
29 RooCmdArg();
30 /// Constructor from payload parameters. Note that the first payload
31 /// parameter has no default value, because otherwise the implicit creation
32 /// of a RooCmdArg from `const char*` would be possible. This would cause
33 /// ambiguity problems in RooFit code. It is not a problem that the first
34 /// parameter always has to be given, because creating a RooCmdArg with only
35 /// a name and no payload doesn't make sense anyway.
36 RooCmdArg(const char* name,
37 Int_t i1, Int_t i2=0,
38 double d1=0, double d2=0,
39 const char* s1=0, const char* s2=0,
40 const TObject* o1=0, const TObject* o2=0, const RooCmdArg* ca=0, const char* s3=0,
41 const RooArgSet* c1=0, const RooArgSet* c2=0) ;
42 RooCmdArg(const RooCmdArg& other) ;
43 RooCmdArg& operator=(const RooCmdArg& other) ;
44 void addArg(const RooCmdArg& arg) ;
45 void setProcessRecArgs(bool flag, bool prefix=true) {
46 // If true flag this object as containing recursive arguments
47 _procSubArgs = flag ;
48 _prefixSubArgs = prefix ;
49 }
50
51 /// Return list of sub-arguments in this RooCmdArg
52 RooLinkedList const& subArgs() const { return _argList ; }
53
54 /// Return list of sub-arguments in this RooCmdArg
56
57 TObject* Clone(const char* newName=0) const override {
58 RooCmdArg* newarg = new RooCmdArg(*this) ;
59 if (newName) { newarg->SetName(newName) ; }
60 return newarg ;
61 }
62
63 ~RooCmdArg() override;
64
65 static const RooCmdArg& none() ;
66
67 const char* opcode() const {
68 // Return operator code
69 return strlen(GetName()) ? GetName() : 0 ;
70 }
71
72 void setInt(Int_t idx,Int_t value) {
73 _i[idx] = value ;
74 }
75 void setDouble(Int_t idx,double value) {
76 _d[idx] = value ;
77 }
78 void setString(Int_t idx,const char* value) {
79 _s[idx] = value ;
80 }
82 _o[idx] = value ;
83 }
84 void setSet(Int_t idx,const RooArgSet& set) ;
85
86 Int_t getInt(Int_t idx) const {
87 // Return integer stored in slot idx
88 return _i[idx] ;
89 }
90 /// Return double stored in slot idx
91 double getDouble(Int_t idx) const {
92 return _d[idx] ;
93 }
94 /// Return string stored in slot idx
95 const char* getString(Int_t idx) const {
96 return (_s[idx].size()>0) ? _s[idx].c_str() : 0 ;
97 }
98 /// Return TObject stored in slot idx
99 const TObject* getObject(Int_t idx) const {
100 return _o[idx] ;
101 }
102
103 const RooArgSet* getSet(Int_t idx) const ;
104
105 void Print(const char* = "") const override;
106
107 template<class T>
108 static T const& take(T && obj) {
109 getNextSharedData().emplace_back(new T{std::move(obj)});
110 return static_cast<T const&>(*getNextSharedData().back());
111 }
112
113 bool procSubArgs() const { return _procSubArgs; }
114 bool prefixSubArgs() const { return _prefixSubArgs; }
115
116private:
117
118 static const RooCmdArg _none ; ///< Static instance of null object
119
120 // Payload
121 double _d[2] ; ///< Payload doubles
122 Int_t _i[2] ; ///< Payload integers
123 std::string _s[3] ; ///< Payload strings
124 TObject* _o[2] ; ///< Payload objects
125 bool _procSubArgs ; ///< If true argument requires recursive processing
126 RooArgSet* _c ; ///< Payload RooArgSets
127 RooLinkedList _argList ; ///< Payload sub-arguments
128 bool _prefixSubArgs ; ///< Prefix sub-arguments with container name?
129
130 using DataCollection = std::vector<std::unique_ptr<TObject>>;
131 std::shared_ptr<DataCollection> _sharedData; ///<!
132
133 // the next RooCmdArg created will take ownership of this data
136
137 ClassDefOverride(RooCmdArg,2) // Generic named argument container
138};
139
140#endif
#define s1(x)
Definition: RSha256.hxx:91
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Definition: RtypesCore.h:45
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition: TGX11.cxx:110
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:26
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:205
RooArgSet * _c
Payload RooArgSets.
Definition: RooCmdArg.h:126
double getDouble(Int_t idx) const
Return double stored in slot idx.
Definition: RooCmdArg.h:91
void Print(const char *="") const override
Print contents.
Definition: RooCmdArg.cxx:225
RooLinkedList _argList
Payload sub-arguments.
Definition: RooCmdArg.h:127
static T const & take(T &&obj)
Definition: RooCmdArg.h:108
void addArg(const RooCmdArg &arg)
Utility function to add nested RooCmdArg to payload of this RooCmdArg.
Definition: RooCmdArg.cxx:195
std::shared_ptr< DataCollection > _sharedData
!
Definition: RooCmdArg.h:131
Int_t _i[2]
Payload integers.
Definition: RooCmdArg.h:122
RooLinkedList const & subArgs() const
Return list of sub-arguments in this RooCmdArg.
Definition: RooCmdArg.h:52
void setObject(Int_t idx, TObject *value)
Definition: RooCmdArg.h:81
void setInt(Int_t idx, Int_t value)
Definition: RooCmdArg.h:72
RooCmdArg & operator=(const RooCmdArg &other)
Assignment operator.
Definition: RooCmdArg.cxx:145
static const RooCmdArg & none()
Return reference to null argument.
Definition: RooCmdArg.cxx:51
static DataCollection _nextSharedData
Definition: RooCmdArg.h:134
Int_t getInt(Int_t idx) const
Definition: RooCmdArg.h:86
void setSet(Int_t idx, const RooArgSet &set)
Definition: RooCmdArg.cxx:213
bool procSubArgs() const
Definition: RooCmdArg.h:113
RooLinkedList & subArgs()
Return list of sub-arguments in this RooCmdArg.
Definition: RooCmdArg.h:55
std::string _s[3]
Payload strings.
Definition: RooCmdArg.h:123
bool prefixSubArgs() const
Definition: RooCmdArg.h:114
bool _procSubArgs
If true argument requires recursive processing.
Definition: RooCmdArg.h:125
RooCmdArg()
Default constructor.
Definition: RooCmdArg.cxx:60
TObject * _o[2]
Payload objects.
Definition: RooCmdArg.h:124
TObject * Clone(const char *newName=0) const override
Make a clone of an object using the Streamer facility.
Definition: RooCmdArg.h:57
const char * opcode() const
Definition: RooCmdArg.h:67
static const RooCmdArg _none
Static instance of null object.
Definition: RooCmdArg.h:118
double _d[2]
Payload doubles.
Definition: RooCmdArg.h:121
std::vector< std::unique_ptr< TObject > > DataCollection
Definition: RooCmdArg.h:130
bool _prefixSubArgs
Prefix sub-arguments with container name?
Definition: RooCmdArg.h:128
void setProcessRecArgs(bool flag, bool prefix=true)
Definition: RooCmdArg.h:45
~RooCmdArg() override
Destructor.
Definition: RooCmdArg.cxx:184
const char * getString(Int_t idx) const
Return string stored in slot idx.
Definition: RooCmdArg.h:95
void setDouble(Int_t idx, double value)
Definition: RooCmdArg.h:75
void setString(Int_t idx, const char *value)
Definition: RooCmdArg.h:78
const TObject * getObject(Int_t idx) const
Return TObject stored in slot idx.
Definition: RooCmdArg.h:99
static DataCollection & getNextSharedData()
Definition: RooCmdArg.cxx:235
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Mother of all ROOT objects.
Definition: TObject.h:37
return c1
Definition: legend1.C:41
return c2
Definition: legend2.C:14
double T(double x)
Definition: ChebyshevPol.h:34