Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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.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=nullptr, bool isArray=false) ;
59 bool defineSet(const char* name, const char* argName, Int_t setNum, const RooArgSet* set=nullptr) ;
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.0) ;
70 const char* getString(const char* name, const char* defaultValue="",bool convEmptyToNull=false) ;
71 TObject* getObject(const char* name, TObject* obj=nullptr) ;
72 RooArgSet* getSet(const char* name, RooArgSet* set=nullptr) ;
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 static void stripCmdList(RooLinkedList& cmdList, const char* cmdsToPurge);
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 template<class ...Args_t>
100 const char* callerID, const char* cmdArgName, Int_t objIdx, RooArgSet* defVal, Args_t && ...args);
101
102 static double decodeDoubleOnTheFly(const char* callerID, const char* cmdArgName, int idx, double defVal,
103 std::initializer_list<std::reference_wrapper<const RooCmdArg>> args);
104
105protected:
106
107 template<class T>
108 struct Var {
109 std::string name;
110 std::string argName;
113 int num;
114 };
115
117
118 bool _verbose = false;
119 bool _error = false;
120 bool _allowUndefined = false;
121
122 std::vector<Var<int>> _iList ; ///< Integer list
123 std::vector<Var<double>> _dList ; ///< Double list
124 std::vector<Var<std::string>> _sList ; ///< String list
125 std::vector<Var<RooLinkedList>> _oList ; ///< Object list
126 std::vector<Var<RooArgSet*>> _cList ; ///< RooArgSet list
127
128 TList _rList ; ///< Required cmd list
129 TList _fList ; ///< Forbidden cmd list
130 TList _mList ; ///< Mutex cmd list
131 TList _yList ; ///< Dependency cmd list
132 TList _pList ; ///< Processed cmd list
133
134 ClassDefOverride(RooCmdConfig,0) // Configurable parse of RooCmdArg objects
135};
136
137
138////////////////////////////////////////////////////////////////////////////////
139/// Add condition that any of listed arguments must be processed
140/// for parsing to be declared successful
141template<class... Args_t>
142void RooCmdConfig::defineRequiredArgs(const char* first, Args_t && ... args) {
143 for(auto const& arg : {first, args...}) {
144 if (arg) _rList.Add(new TObjString(arg));
145 }
146}
147
148
149//////////////////////////////////////////////////////////////////////////////////
150/// Define arguments where any pair is mutually exclusive
151template<class... Args_t>
152void RooCmdConfig::defineMutex(const char* head, Args_t && ... tail) {
153 for(auto const& item : {tail...}) {
154 _mList.Add(new TNamed(head,item));
155 _mList.Add(new TNamed(item,head));
156 }
157 defineMutex(tail...);
158}
159
160
161////////////////////////////////////////////////////////////////////////////////
162/// Process given RooCmdArgs
163template<class... Args_t>
164bool RooCmdConfig::process(const RooCmdArg& arg, Args_t && ...args) {
165 bool result = false;
166 for(auto r : {process(arg), process(std::forward<Args_t>(args))...}) result |= r;
167 return result;
168}
169
170
171////////////////////////////////////////////////////////////////////////////////
172/// Process several RooCmdArg using iterators.
173template<typename It_t>
174bool RooCmdConfig::process(It_t begin, It_t end) {
175 bool result = false;
176 for (auto it = begin; it != end; ++it) {
177 result |= process(*it);
178 }
179 return result;
180}
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// Static decoder function allows to retrieve integer property from set of RooCmdArgs
185/// For use in base member initializers in constructors
186
187template<class ...Args_t>
189 const char* callerID, const char* cmdArgName, Int_t intIdx, Int_t defVal, Args_t && ...args)
190{
191 RooCmdConfig pc(callerID) ;
192 pc.allowUndefined() ;
193 pc.defineInt("theInt",cmdArgName,intIdx,defVal) ;
194 pc.process(std::forward<Args_t>(args)...);
195 return pc.getInt("theInt") ;
196}
197
198
199////////////////////////////////////////////////////////////////////////////////
200/// Static decoder function allows to retrieve string property from set of RooCmdArgs
201/// For use in base member initializers in constructors
202
203template<class ...Args_t>
205 const char* callerID, const char* cmdArgName, Int_t strIdx, const char* defVal, Args_t && ...args)
206{
207 RooCmdConfig pc(callerID) ;
208 pc.allowUndefined() ;
209 pc.defineString("theString",cmdArgName,strIdx,defVal) ;
210 pc.process(std::forward<Args_t>(args)...);
211 const char* ret = pc.getString("theString",nullptr,true) ;
212
213 return ret ? ret : "";
214}
215
216
217////////////////////////////////////////////////////////////////////////////////
218/// Static decoder function allows to retrieve object property from set of RooCmdArgs
219/// For use in base member initializers in constructors
220
221template<class ...Args_t>
223 const char* callerID, const char* cmdArgName, Int_t objIdx, TObject* defVal, Args_t && ...args)
224{
225 RooCmdConfig pc(callerID) ;
226 pc.allowUndefined() ;
227 pc.defineObject("theObj",cmdArgName,objIdx,defVal) ;
228 pc.process(std::forward<Args_t>(args)...);
229 return pc.getObject("theObj") ;
230}
231
232
233template<class ...Args_t>
235 const char* callerID, const char* cmdArgName, Int_t objIdx, RooArgSet* defVal, Args_t && ...args)
236{
237 RooCmdConfig pc(callerID) ;
238 pc.allowUndefined() ;
239 pc.defineSet("theObj",cmdArgName,objIdx,defVal) ;
240 pc.process(std::forward<Args_t>(args)...);
241 return pc.getSet("theObj") ;
242}
243
244
245#endif
int Int_t
Definition RtypesCore.h:45
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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:55
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.
bool defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=nullptr, bool isArray=false)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
std::vector< Var< RooArgSet * > > _cList
RooArgSet list.
void defineMutex(const char *)
double getDouble(const char *name, double defaultValue=0.0)
Return double property registered with name 'name'.
RooArgSet * getSet(const char *name, RooArgSet *set=nullptr)
Return RooArgSet property registered with name 'name'.
void defineMutex(const char *head, Args_t &&... tail)
Define arguments where any pair is mutually exclusive.
bool process(const RooCmdArg &arg)
Process given RooCmdArg.
TList _pList
Processed cmd list.
bool hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
std::vector< Var< RooLinkedList > > _oList
Object list.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
std::vector< Var< int > > _iList
Integer list.
std::vector< Var< double > > _dList
Double list.
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...
static void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList.
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...
std::vector< Var< std::string > > _sList
String list.
TList _yList
Dependency cmd list.
TList _fList
Forbidden cmd list.
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.
bool ok(bool verbose) const
Return true of parsing was successful.
TObject * getObject(const char *name, TObject *obj=nullptr)
Return TObject property registered with name 'name'.
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.
TList _mList
Mutex cmd list.
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.
bool defineSet(const char *name, const char *argName, Int_t setNum, const RooArgSet *set=nullptr)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
static RooArgSet * decodeSetOnTheFly(const char *callerID, const char *cmdArgName, Int_t objIdx, RooArgSet *defVal, Args_t &&...args)
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...
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...
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.
bool defineDouble(const char *name, const char *argName, Int_t doubleNum, double defValue=0.0)
Define double property name 'name' mapped to double in slot 'doubleNum' in RooCmdArg with name argNam...
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...
void setVerbose(bool flag)
If flag is true verbose messaging is activated.
TList _rList
Required cmd list.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
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:41
Basic string class.
Definition TString.h:139
Definition first.py:1
std::string argName