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#include <RooStringView.h>
22
23#include <TList.h>
24#include <TObjString.h>
25#include <TObject.h>
26#include <TString.h>
27
28#include <functional>
29#include <string>
30
31class RooArgSet;
32
33class RooCmdConfig : public TObject {
34public:
35
36 RooCmdConfig(RooStringView methodName);
38
39 /// If flag is true verbose messaging is activated
40 void setVerbose(bool flag) {
41 _verbose = flag ;
42 }
43 /// If flag is true the processing of unrecognized RooCmdArgs
44 /// is not considered an error
45 void allowUndefined(bool flag=true) {
47 }
48 void defineDependency(const char* refArgName, const char* neededArgName) ;
49
50 template<class... Args_t>
51 void defineRequiredArgs(const char* first, Args_t && ... args);
52
53 template<class... Args_t>
54 void defineMutex(const char* head, Args_t && ... tail);
55 void defineMutex(const char*) {} // to end the recursion of defineMutex()
56
57 bool defineInt(const char* name, const char* argName, int intNum, int defValue=0) ;
58 bool defineDouble(const char* name, const char* argName, int doubleNum, double defValue=0.0) ;
59 bool defineString(const char* name, const char* argName, int stringNum, const char* defValue="",bool appendMode=false) ;
60 bool defineObject(const char* name, const char* argName, int setNum, const TObject* obj=nullptr, bool isArray=false) ;
61 bool defineSet(const char* name, const char* argName, int setNum, const RooArgSet* set=nullptr) ;
62
63 bool process(const RooCmdArg& arg) ;
64 template<class... Args_t>
65 bool process(const RooCmdArg& arg, Args_t && ...args);
66 bool process(const RooLinkedList& argList) ;
67 template<typename It_t>
68 bool process(It_t begin, It_t end);
69
70 int getInt(const char* name, int defaultValue=0) const;
71 double getDouble(const char* name, double defaultValue=0.0) const;
72 const char* getString(const char* name, const char* defaultValue="",bool convEmptyToNull=false) const;
73 TObject* getObject(const char* name, TObject* obj=nullptr) const;
74 RooArgSet* getSet(const char* name, RooArgSet* set=nullptr) const;
75 const RooLinkedList& getObjectList(const char* name) const;
76
77 bool ok(bool verbose) const ;
78
79 std::string missingArgs() const ;
80
82 static void stripCmdList(RooLinkedList& cmdList, const char* cmdsToPurge);
83 bool hasProcessed(const char* cmdName) const ;
84
85 void print() const;
86
87
88 template<class ...Args_t>
89 static int decodeIntOnTheFly(
90 const char* callerID, const char* cmdArgName, int intIdx, int defVal, Args_t && ...args);
91
92 template<class ...Args_t>
93 static std::string decodeStringOnTheFly(
94 const char* callerID, const char* cmdArgName, int intIdx, const char* defVal, Args_t && ...args);
95
96 template<class ...Args_t>
98 const char* callerID, const char* cmdArgName, int objIdx, TObject* defVal, Args_t && ...args);
99
100 template<class ...Args_t>
102 const char* callerID, const char* cmdArgName, int objIdx, RooArgSet* defVal, Args_t && ...args);
103
104 static double decodeDoubleOnTheFly(const char* callerID, const char* cmdArgName, int idx, double defVal,
105 std::initializer_list<std::reference_wrapper<const RooCmdArg>> args);
106
107protected:
108
109 template<class T>
110 struct Var {
111 std::string name;
112 std::string argName;
115 int num;
116 };
117
118 std::string _name;
119
120 bool _verbose = false;
121 bool _error = false;
122 bool _allowUndefined = false;
123
124 std::vector<Var<int>> _iList ; ///< Integer list
125 std::vector<Var<double>> _dList ; ///< Double list
126 std::vector<Var<std::string>> _sList ; ///< String list
127 std::vector<Var<RooLinkedList>> _oList ; ///< Object list
128 std::vector<Var<RooArgSet*>> _cList ; ///< RooArgSet list
129
130 TList _rList ; ///< Required cmd list
131 TList _fList ; ///< Forbidden cmd list
132 TList _mList ; ///< Mutex cmd list
133 TList _yList ; ///< Dependency cmd list
134 TList _pList ; ///< Processed cmd list
135
136 ClassDefOverride(RooCmdConfig,0) // Configurable parse of RooCmdArg objects
137};
138
139
140////////////////////////////////////////////////////////////////////////////////
141/// Add condition that any of listed arguments must be processed
142/// for parsing to be declared successful
143template<class... Args_t>
144void RooCmdConfig::defineRequiredArgs(const char* first, Args_t && ... args) {
145 for(auto const& arg : {first, args...}) {
146 if (arg) _rList.Add(new TObjString(arg));
147 }
148}
149
150
151//////////////////////////////////////////////////////////////////////////////////
152/// Define arguments where any pair is mutually exclusive
153template<class... Args_t>
154void RooCmdConfig::defineMutex(const char* head, Args_t && ... tail) {
155 for(auto const& item : {tail...}) {
156 _mList.Add(new TNamed(head,item));
157 _mList.Add(new TNamed(item,head));
158 }
159 defineMutex(tail...);
160}
161
162
163////////////////////////////////////////////////////////////////////////////////
164/// Process given RooCmdArgs
165template<class... Args_t>
166bool RooCmdConfig::process(const RooCmdArg& arg, Args_t && ...args) {
167 bool result = false;
168 for(auto r : {process(arg), process(std::forward<Args_t>(args))...}) result |= r;
169 return result;
170}
171
172
173////////////////////////////////////////////////////////////////////////////////
174/// Process several RooCmdArg using iterators.
175template<typename It_t>
177 bool result = false;
178 for (auto it = begin; it != end; ++it) {
179 result |= process(*it);
180 }
181 return result;
182}
183
184
185////////////////////////////////////////////////////////////////////////////////
186/// Static decoder function allows to retrieve integer property from set of RooCmdArgs
187/// For use in base member initializers in constructors
188
189template<class ...Args_t>
191 const char* callerID, const char* cmdArgName, int intIdx, int defVal, Args_t && ...args)
192{
194 pc.allowUndefined() ;
195 pc.defineInt("theInt",cmdArgName,intIdx,defVal) ;
196 pc.process(std::forward<Args_t>(args)...);
197 return pc.getInt("theInt") ;
198}
199
200
201////////////////////////////////////////////////////////////////////////////////
202/// Static decoder function allows to retrieve string property from set of RooCmdArgs
203/// For use in base member initializers in constructors
204
205template<class ...Args_t>
207 const char* callerID, const char* cmdArgName, int strIdx, const char* defVal, Args_t && ...args)
208{
210 pc.allowUndefined() ;
211 pc.defineString("theString",cmdArgName,strIdx,defVal) ;
212 pc.process(std::forward<Args_t>(args)...);
213 const char* ret = pc.getString("theString",nullptr,true) ;
214
215 return ret ? ret : "";
216}
217
218
219////////////////////////////////////////////////////////////////////////////////
220/// Static decoder function allows to retrieve object property from set of RooCmdArgs
221/// For use in base member initializers in constructors
222
223template<class ...Args_t>
225 const char* callerID, const char* cmdArgName, int objIdx, TObject* defVal, Args_t && ...args)
226{
228 pc.allowUndefined() ;
229 pc.defineObject("theObj",cmdArgName,objIdx,defVal) ;
230 pc.process(std::forward<Args_t>(args)...);
231 return pc.getObject("theObj") ;
232}
233
234
235template<class ...Args_t>
237 const char* callerID, const char* cmdArgName, int objIdx, RooArgSet* defVal, Args_t && ...args)
238{
240 pc.allowUndefined() ;
241 pc.defineSet("theObj",cmdArgName,objIdx,defVal) ;
242 pc.process(std::forward<Args_t>(args)...);
243 return pc.getSet("theObj") ;
244}
245
246
247#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:24
Named container for two doubles, two integers two object points and three string pointers that can be...
Definition RooCmdArg.h:26
Configurable parser for RooCmdArg named arguments.
std::vector< Var< RooArgSet * > > _cList
RooArgSet list.
void defineMutex(const char *)
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.
std::vector< Var< int > > _iList
Integer list.
std::vector< Var< double > > _dList
Double list.
double getDouble(const char *name, double defaultValue=0.0) const
Return double property 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...
bool defineDouble(const char *name, const char *argName, int doubleNum, double defValue=0.0)
Define double property name 'name' mapped to double in slot 'doubleNum' in RooCmdArg with name argNam...
static void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList.
std::string _name
RooArgSet * getSet(const char *name, RooArgSet *set=nullptr) const
Return RooArgSet property registered with name 'name'.
bool defineSet(const char *name, const char *argName, int setNum, const RooArgSet *set=nullptr)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
std::vector< Var< std::string > > _sList
String list.
TList _yList
Dependency cmd list.
TList _fList
Forbidden cmd list.
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.
static std::string decodeStringOnTheFly(const char *callerID, const char *cmdArgName, int intIdx, const char *defVal, Args_t &&...args)
Static decoder function allows to retrieve string property from set of RooCmdArgs For use in base mem...
bool defineObject(const char *name, const char *argName, int setNum, const TObject *obj=nullptr, bool isArray=false)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
const char * getString(const char *name, const char *defaultValue="", bool convEmptyToNull=false) const
Return string property registered with name 'name'.
bool defineString(const char *name, const char *argName, int stringNum, const char *defValue="", bool appendMode=false)
Define double property name 'name' mapped to double in slot 'stringNum' in RooCmdArg with name argNam...
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.
const RooLinkedList & getObjectList(const char *name) const
Return list of objects registered with name 'name'.
TList _mList
Mutex cmd list.
bool defineInt(const char *name, const char *argName, int intNum, int defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
void allowUndefined(bool flag=true)
If flag is true the processing of unrecognized RooCmdArgs is not considered an error.
int getInt(const char *name, int defaultValue=0) const
Return integer property registered with name 'name'.
RooCmdConfig(RooStringView methodName)
Constructor taking descriptive name of owner/user which is used as prefix for any warning or error 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.
TObject * getObject(const char *name, TObject *obj=nullptr) const
Return TObject property registered with name 'name'.
static TObject * decodeObjOnTheFly(const char *callerID, const char *cmdArgName, int objIdx, TObject *defVal, Args_t &&...args)
Static decoder function allows to retrieve object property from set of RooCmdArgs For use in base mem...
static int decodeIntOnTheFly(const char *callerID, const char *cmdArgName, int intIdx, int defVal, Args_t &&...args)
Static decoder function allows to retrieve integer property from set of RooCmdArgs For use in base me...
static RooArgSet * decodeSetOnTheFly(const char *callerID, const char *cmdArgName, int objIdx, RooArgSet *defVal, Args_t &&...args)
void setVerbose(bool flag)
If flag is true verbose messaging is activated.
TList _rList
Required cmd list.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
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
std::string argName