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);
37 RooCmdConfig(const RooCmdConfig& other) ;
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) {
46 _allowUndefined = flag ;
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 *defVal = nullptr,
61 bool isArray = false);
62 bool defineSet(const char *name, const char *argName, int setNum, const RooArgSet *defVal = nullptr);
63
64 bool process(const RooCmdArg& arg) ;
65 template<class... Args_t>
66 bool process(const RooCmdArg& arg, Args_t && ...args);
67 bool process(const RooLinkedList& argList) ;
68 template<typename It_t>
69 bool process(It_t begin, It_t end);
70
71 int getInt(const char *name, int defVal = 0) const;
72 double getDouble(const char *name, double defVal = 0.0) const;
73 const char *getString(const char *name, const char *defVal = "", bool convEmptyToNull = false) const;
74 TObject *getObject(const char *name, TObject *defVal = nullptr) const;
75 RooArgSet *getSet(const char *name, RooArgSet *defVal = nullptr) const;
76 const RooLinkedList& getObjectList(const char* name) const;
77
78 bool ok(bool verbose) const ;
79
80 std::string missingArgs() const ;
81
82 RooLinkedList filterCmdList(RooLinkedList& cmdInList, const char* cmdNameList, bool removeFromInList=true) const;
83 static void stripCmdList(RooLinkedList& cmdList, const char* cmdsToPurge);
84 bool hasProcessed(const char* cmdName) const ;
85
86 void print() const;
87
88
89 template<class ...Args_t>
90 static int decodeIntOnTheFly(
91 const char* callerID, const char* cmdArgName, int intIdx, int defVal, Args_t && ...args);
92
93 template<class ...Args_t>
94 static std::string decodeStringOnTheFly(
95 const char* callerID, const char* cmdArgName, int strIdx, const char* defVal, Args_t && ...args);
96
97 template<class ...Args_t>
99 const char* callerID, const char* cmdArgName, int objIdx, TObject* defVal, Args_t && ...args);
100
101 template<class ...Args_t>
103 const char* callerID, const char* cmdArgName, int objIdx, RooArgSet* defVal, Args_t && ...args);
104
105 static double decodeDoubleOnTheFly(const char* callerID, const char* cmdArgName, int idx, double defVal,
106 std::initializer_list<std::reference_wrapper<const RooCmdArg>> args);
107
108protected:
109
110 template<class T>
111 struct Var {
112 std::string name;
113 std::string argName;
114 T val{};
115 bool appendMode = false;
116 int num = 0;
117 };
118
119 std::string _name;
120
121 bool _verbose = false;
122 bool _error = false;
123 bool _allowUndefined = false;
124
125 std::vector<Var<int>> _iList ; ///< Integer list
126 std::vector<Var<double>> _dList ; ///< Double list
127 std::vector<Var<std::string>> _sList ; ///< String list
128 std::vector<Var<RooLinkedList>> _oList ; ///< Object list
129 std::vector<Var<RooArgSet*>> _cList ; ///< RooArgSet list
130
131 TList _rList ; ///< Required cmd list
132 TList _fList ; ///< Forbidden cmd list
133 TList _mList ; ///< Mutex cmd list
134 TList _yList ; ///< Dependency cmd list
135 TList _pList ; ///< Processed cmd list
136
137 ClassDefOverride(RooCmdConfig,0) // Configurable parse of RooCmdArg objects
138};
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Add condition that any of listed arguments must be processed
143/// for parsing to be declared successful
144template<class... Args_t>
145void RooCmdConfig::defineRequiredArgs(const char* first, Args_t && ... args) {
146 for(auto const& arg : {first, args...}) {
147 if (arg) _rList.Add(new TObjString(arg));
148 }
149}
150
151
152//////////////////////////////////////////////////////////////////////////////////
153/// Define arguments where any pair is mutually exclusive
154template<class... Args_t>
155void RooCmdConfig::defineMutex(const char* head, Args_t && ... tail) {
156 for(auto const& item : {tail...}) {
157 _mList.Add(new TNamed(head,item));
158 _mList.Add(new TNamed(item,head));
159 }
160 defineMutex(tail...);
161}
162
163
164////////////////////////////////////////////////////////////////////////////////
165/// Process given RooCmdArgs
166template<class... Args_t>
167bool RooCmdConfig::process(const RooCmdArg& arg, Args_t && ...args) {
168 bool result = false;
169 for(auto r : {process(arg), process(std::forward<Args_t>(args))...}) result |= r;
170 return result;
171}
172
173
174////////////////////////////////////////////////////////////////////////////////
175/// Process several RooCmdArg using iterators.
176template<typename It_t>
177bool RooCmdConfig::process(It_t begin, It_t end) {
178 bool result = false;
179 for (auto it = begin; it != end; ++it) {
180 result |= process(*it);
181 }
182 return result;
183}
184
185
186////////////////////////////////////////////////////////////////////////////////
187/// Static decoder function allows to retrieve integer property from set of RooCmdArgs
188/// For use in base member initializers in constructors
189
190template<class ...Args_t>
192 const char* callerID, const char* cmdArgName, int intIdx, int defVal, Args_t && ...args)
193{
194 RooCmdConfig pc(callerID) ;
195 pc.allowUndefined() ;
196 pc.defineInt("theInt",cmdArgName,intIdx,defVal) ;
197 pc.process(std::forward<Args_t>(args)...);
198 return pc.getInt("theInt") ;
199}
200
201
202////////////////////////////////////////////////////////////////////////////////
203/// Static decoder function allows to retrieve string property from set of RooCmdArgs
204/// For use in base member initializers in constructors
205
206template<class ...Args_t>
208 const char* callerID, const char* cmdArgName, int strIdx, const char* defVal, Args_t && ...args)
209{
210 RooCmdConfig pc(callerID) ;
211 pc.allowUndefined() ;
212 pc.defineString("theString",cmdArgName,strIdx,defVal) ;
213 pc.process(std::forward<Args_t>(args)...);
214 const char* ret = pc.getString("theString",nullptr,true) ;
215
216 return ret ? ret : "";
217}
218
219
220////////////////////////////////////////////////////////////////////////////////
221/// Static decoder function allows to retrieve object property from set of RooCmdArgs
222/// For use in base member initializers in constructors
223
224template<class ...Args_t>
226 const char* callerID, const char* cmdArgName, int objIdx, TObject* defVal, Args_t && ...args)
227{
228 RooCmdConfig pc(callerID) ;
229 pc.allowUndefined() ;
230 pc.defineObject("theObj",cmdArgName,objIdx,defVal) ;
231 pc.process(std::forward<Args_t>(args)...);
232 return pc.getObject("theObj") ;
233}
234
235
236template<class ...Args_t>
238 const char* callerID, const char* cmdArgName, int objIdx, RooArgSet* defVal, Args_t && ...args)
239{
240 RooCmdConfig pc(callerID) ;
241 pc.allowUndefined() ;
242 pc.defineSet("theObj",cmdArgName,objIdx,defVal) ;
243 pc.process(std::forward<Args_t>(args)...);
244 return pc.getSet("theObj") ;
245}
246
247
248#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:347
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:142
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.
bool defineSet(const char *name, const char *argName, int setNum, const RooArgSet *defVal=nullptr)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
void defineMutex(const char *)
double getDouble(const char *name, double defVal=0.0) const
Return double 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 getInt(const char *name, int defVal=0) const
Return integer property registered with name 'name'.
RooArgSet * getSet(const char *name, RooArgSet *defVal=nullptr) const
Return RooArgSet property registered with name 'name'.
std::vector< Var< int > > _iList
Integer list.
std::vector< Var< double > > _dList
Double list.
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
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.
TObject * getObject(const char *name, TObject *defVal=nullptr) const
Return TObject 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'.
const char * getString(const char *name, const char *defVal="", bool convEmptyToNull=false) const
Return string property 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.
static std::string decodeStringOnTheFly(const char *callerID, const char *cmdArgName, int strIdx, const char *defVal, Args_t &&...args)
Static decoder function allows to retrieve string property from set of RooCmdArgs For use in base mem...
RooCmdConfig(RooStringView methodName)
Constructor taking descriptive name of owner/user which is used as prefix for any warning or error me...
bool defineObject(const char *name, const char *argName, int setNum, const TObject *defVal=nullptr, bool isArray=false)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
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 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 TObject pointers in a vector.
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:42
std::string argName