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