Logo ROOT  
Reference Guide
RooCmdConfig.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooCmdConfig.h,v 1.12 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_CONFIG
18#define ROO_CMD_CONFIG
19
20#include <RooCmdArg.h>
21
22#include <TList.h>
23#include <TObjString.h>
24#include <TObject.h>
25#include <TString.h>
26
27#include <string>
28
29class RooArgSet;
30
31class RooCmdConfig : public TObject {
32public:
33
34 RooCmdConfig(const char* methodName);
35 RooCmdConfig(const RooCmdConfig& other) ;
36
37 /// If flag is true verbose messaging is activated
38 void setVerbose(bool flag) {
39 _verbose = flag ;
40 }
41 /// If flag is true the processing of unrecognized RooCmdArgs
42 /// is not considered an error
43 void allowUndefined(bool flag=true) {
44 _allowUndefined = flag ;
45 }
46 void defineDependency(const char* refArgName, const char* neededArgName) ;
47
48 template<class... Args_t>
49 void defineRequiredArgs(const char* first, Args_t && ... args);
50
51 template<class... Args_t>
52 void defineMutex(const char* head, Args_t && ... tail);
53 void defineMutex(const char*) {} // to end the recursion of defineMutex()
54
55 bool defineInt(const char* name, const char* argName, Int_t intNum, Int_t defValue=0) ;
56 bool defineDouble(const char* name, const char* argName, Int_t doubleNum, double defValue=0.) ;
57 bool defineString(const char* name, const char* argName, Int_t stringNum, const char* defValue="",bool appendMode=false) ;
58 bool defineObject(const char* name, const char* argName, Int_t setNum, const TObject* obj=0, bool isArray=false) ;
59 bool defineSet(const char* name, const char* argName, Int_t setNum, const RooArgSet* set=0) ;
60
61 bool process(const RooCmdArg& arg) ;
62 template<class... Args_t>
63 bool process(const RooCmdArg& arg, Args_t && ...args);
64 bool process(const RooLinkedList& argList) ;
65 template<typename It_t>
66 bool process(It_t begin, It_t end);
67
68 Int_t getInt(const char* name, Int_t defaultValue=0) ;
69 double getDouble(const char* name, double defaultValue=0) ;
70 const char* getString(const char* name, const char* defaultValue="",bool convEmptyToNull=false) ;
71 TObject* getObject(const char* name, TObject* obj=0) ;
72 RooArgSet* getSet(const char* name, RooArgSet* set=0) ;
73 const RooLinkedList& getObjectList(const char* name) ;
74
75 bool ok(bool verbose) const ;
76
77 std::string missingArgs() const ;
78
79 RooLinkedList filterCmdList(RooLinkedList& cmdInList, const char* cmdNameList, bool removeFromInList=true) const;
80 void stripCmdList(RooLinkedList& cmdList, const char* cmdsToPurge) const;
81 bool hasProcessed(const char* cmdName) const ;
82
83 void print() const;
84
85
86 template<class ...Args_t>
88 const char* callerID, const char* cmdArgName, Int_t intIdx, Int_t defVal, Args_t && ...args);
89
90 template<class ...Args_t>
91 static std::string decodeStringOnTheFly(
92 const char* callerID, const char* cmdArgName, Int_t intIdx, const char* defVal, Args_t && ...args);
93
94 template<class ...Args_t>
96 const char* callerID, const char* cmdArgName, Int_t objIdx, TObject* defVal, Args_t && ...args);
97
98 static double decodeDoubleOnTheFly(const char* callerID, const char* cmdArgName, int idx, double defVal,
99 std::initializer_list<std::reference_wrapper<const RooCmdArg>> args);
100
101protected:
102
103 template<class T>
104 struct Var {
105 std::string name;
106 std::string argName;
109 int num;
110 };
111
113
114 bool _verbose = false;
115 bool _error = false;
116 bool _allowUndefined = false;
117
118 std::vector<Var<int>> _iList ; ///< Integer list
119 std::vector<Var<double>> _dList ; ///< Double list
120 std::vector<Var<std::string>> _sList ; ///< String list
121 std::vector<Var<RooLinkedList>> _oList ; ///< Object list
122 std::vector<Var<RooArgSet*>> _cList ; ///< RooArgSet list
123
124 TList _rList ; ///< Required cmd list
125 TList _fList ; ///< Forbidden cmd list
126 TList _mList ; ///< Mutex cmd list
127 TList _yList ; ///< Dependency cmd list
128 TList _pList ; ///< Processed cmd list
129
130 ClassDefOverride(RooCmdConfig,0) // Configurable parse of RooCmdArg objects
131};
132
133
134////////////////////////////////////////////////////////////////////////////////
135/// Add condition that any of listed arguments must be processed
136/// for parsing to be declared successful
137template<class... Args_t>
138void RooCmdConfig::defineRequiredArgs(const char* first, Args_t && ... args) {
139 for(auto const& arg : {first, args...}) {
140 if (arg) _rList.Add(new TObjString(arg));
141 }
142}
143
144
145//////////////////////////////////////////////////////////////////////////////////
146/// Define arguments where any pair is mutually exclusive
147template<class... Args_t>
148void RooCmdConfig::defineMutex(const char* head, Args_t && ... tail) {
149 for(auto const& item : {tail...}) {
150 _mList.Add(new TNamed(head,item));
151 _mList.Add(new TNamed(item,head));
152 }
153 defineMutex(tail...);
154}
155
156
157////////////////////////////////////////////////////////////////////////////////
158/// Process given RooCmdArgs
159template<class... Args_t>
160bool RooCmdConfig::process(const RooCmdArg& arg, Args_t && ...args) {
161 bool result = false;
162 for(auto r : {process(arg), process(std::forward<Args_t>(args))...}) result |= r;
163 return result;
164}
165
166
167////////////////////////////////////////////////////////////////////////////////
168/// Process several RooCmdArg using iterators.
169template<typename It_t>
170bool RooCmdConfig::process(It_t begin, It_t end) {
171 bool result = false;
172 for (auto it = begin; it != end; ++it) {
173 result |= process(*it);
174 }
175 return result;
176}
177
178
179////////////////////////////////////////////////////////////////////////////////
180/// Static decoder function allows to retrieve integer property from set of RooCmdArgs
181/// For use in base member initializers in constructors
182
183template<class ...Args_t>
185 const char* callerID, const char* cmdArgName, Int_t intIdx, Int_t defVal, Args_t && ...args)
186{
187 RooCmdConfig pc(callerID) ;
188 pc.allowUndefined() ;
189 pc.defineInt("theInt",cmdArgName,intIdx,defVal) ;
190 pc.process(std::forward<Args_t>(args)...);
191 return pc.getInt("theInt") ;
192}
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Static decoder function allows to retrieve string property from set of RooCmdArgs
197/// For use in base member initializers in constructors
198
199template<class ...Args_t>
201 const char* callerID, const char* cmdArgName, Int_t strIdx, const char* defVal, Args_t && ...args)
202{
203 RooCmdConfig pc(callerID) ;
204 pc.allowUndefined() ;
205 pc.defineString("theString",cmdArgName,strIdx,defVal) ;
206 pc.process(std::forward<Args_t>(args)...);
207 const char* ret = pc.getString("theString",0,true) ;
208
209 return ret ? ret : "";
210}
211
212
213////////////////////////////////////////////////////////////////////////////////
214/// Static decoder function allows to retrieve object property from set of RooCmdArgs
215/// For use in base member initializers in constructors
216
217template<class ...Args_t>
219 const char* callerID, const char* cmdArgName, Int_t objIdx, TObject* defVal, Args_t && ...args)
220{
221 RooCmdConfig pc(callerID) ;
222 pc.allowUndefined() ;
223 pc.defineObject("theObj",cmdArgName,objIdx,defVal) ;
224 pc.process(std::forward<Args_t>(args)...);
225 return pc.getObject("theObj") ;
226}
227
228
229#endif
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 char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
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
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:31
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name 'name'.
std::vector< Var< RooArgSet * > > _cList
RooArgSet list.
Definition: RooCmdConfig.h:122
void defineMutex(const char *)
Definition: RooCmdConfig.h:53
void defineMutex(const char *head, Args_t &&... tail)
Define arguments where any pair is mutually exclusive.
Definition: RooCmdConfig.h:148
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
TList _pList
Processed cmd list.
Definition: RooCmdConfig.h:128
bool hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
std::vector< Var< RooLinkedList > > _oList
Object list.
Definition: RooCmdConfig.h:121
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
std::vector< Var< int > > _iList
Integer list.
Definition: RooCmdConfig.h:118
std::vector< Var< double > > _dList
Double list.
Definition: RooCmdConfig.h:119
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
void print() const
Print configuration of parser.
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
double getDouble(const char *name, double defaultValue=0)
Return double property registered with name 'name'.
bool defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
RooArgSet * getSet(const char *name, RooArgSet *set=0)
Return RooArgSet property registered with name 'name'.
std::vector< Var< std::string > > _sList
String list.
Definition: RooCmdConfig.h:120
TList _yList
Dependency cmd list.
Definition: RooCmdConfig.h:127
bool defineDouble(const char *name, const char *argName, Int_t doubleNum, double defValue=0.)
Define double property name 'name' mapped to double in slot 'doubleNum' in RooCmdArg with name argNam...
TList _fList
Forbidden cmd list.
Definition: RooCmdConfig.h:125
bool defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", bool appendMode=false)
Define double property name 'name' mapped to double in slot 'stringNum' in RooCmdArg with name argNam...
void defineRequiredArgs(const char *first, Args_t &&... args)
Add condition that any of listed arguments must be processed for parsing to be declared successful.
Definition: RooCmdConfig.h:138
bool ok(bool verbose) const
Return true of parsing was successful.
void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge) const
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList.
RooCmdConfig(const char *methodName)
Constructor taking descriptive name of owner/user which is used as prefix for any warning or error me...
static double decodeDoubleOnTheFly(const char *callerID, const char *cmdArgName, int idx, double defVal, std::initializer_list< std::reference_wrapper< const RooCmdArg > > args)
Find a given double in a list of RooCmdArg.
bool _allowUndefined
Definition: RooCmdConfig.h:116
TList _mList
Mutex cmd list.
Definition: RooCmdConfig.h:126
const char * getString(const char *name, const char *defaultValue="", bool convEmptyToNull=false)
Return string property registered with name 'name'.
void allowUndefined(bool flag=true)
If flag is true the processing of unrecognized RooCmdArgs is not considered an error.
Definition: RooCmdConfig.h:43
bool defineSet(const char *name, const char *argName, Int_t setNum, const RooArgSet *set=0)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
static std::string decodeStringOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, const char *defVal, Args_t &&...args)
Static decoder function allows to retrieve string property from set of RooCmdArgs For use in base mem...
Definition: RooCmdConfig.h:200
static Int_t decodeIntOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, Int_t defVal, Args_t &&...args)
Static decoder function allows to retrieve integer property from set of RooCmdArgs For use in base me...
Definition: RooCmdConfig.h:184
RooLinkedList filterCmdList(RooLinkedList &cmdInList, const char *cmdNameList, bool removeFromInList=true) const
Utility function to filter commands listed in cmdNameList from cmdInList.
std::string missingArgs() const
Return string with names of arguments that were required, but not processed.
static TObject * decodeObjOnTheFly(const char *callerID, const char *cmdArgName, Int_t objIdx, TObject *defVal, Args_t &&...args)
Static decoder function allows to retrieve object property from set of RooCmdArgs For use in base mem...
Definition: RooCmdConfig.h:218
bool defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, bool isArray=false)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
void setVerbose(bool flag)
If flag is true verbose messaging is activated.
Definition: RooCmdConfig.h:38
TList _rList
Required cmd list.
Definition: RooCmdConfig.h:124
TString _name
Definition: RooCmdConfig.h:112
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
A doubly linked list.
Definition: TList.h:38
void Add(TObject *obj) override
Definition: TList.h:81
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Collectable string class.
Definition: TObjString.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:136
double T(double x)
Definition: ChebyshevPol.h:34
static constexpr double pc
Definition: first.py:1
std::string name
Definition: RooCmdConfig.h:105
std::string argName
Definition: RooCmdConfig.h:106