41template<
class Collection>
42typename Collection::const_iterator findVar(Collection
const& coll,
const char *
name) {
43 return std::find_if(coll.begin(), coll.end(), [
name](
auto const&
v){ return v.name == name; });
49using std::cout, std::endl;
71void cloneList(
TList const& inList,
TList & outList) {
73 for(
auto * elem : inList) {
74 outList.
Add(elem->Clone()) ;
87 _verbose(other._verbose),
89 _allowUndefined(other._allowUndefined),
146 coutE(InputArguments) <<
"RooCmdConfig::defineInt: name '" <<
name <<
"' already defined" << endl ;
153 ri.argName = argName;
168 coutE(InputArguments) <<
"RooCmdConfig::defineDouble: name '" <<
name <<
"' already defined" << endl ;
175 rd.argName = argName;
192 coutE(InputArguments) <<
"RooCmdConfig::defineString: name '" <<
name <<
"' already defined" << endl ;
199 rs.argName = argName;
201 rs.appendMode = appendMode;
218 coutE(InputArguments) <<
"RooCmdConfig::defineObject: name '" <<
name <<
"' already defined" << endl ;
225 os.argName = argName;
226 os.val.Add(
const_cast<TObject*
>(defVal));
227 os.appendMode = isArray;
244 coutE(InputArguments) <<
"RooCmdConfig::defineObject: name '" <<
name <<
"' already defined" << endl ;
251 cs.argName = argName;
265 for(
auto const& ri :
_iList) {
266 cout << ri.name <<
"[int] = " << ri.val << endl ;
270 for(
auto const& rd :
_dList) {
271 cout << rd.name <<
"[double] = " << rd.val << endl ;
275 for(
auto const& rs :
_sList) {
276 cout << rs.name <<
"[string] = \"" << rs.val <<
"\"" << endl ;
280 for(
auto const& ro :
_oList) {
281 cout << ro.name <<
"[TObject] = " ;
282 auto const * obj = ro.val.At(0);
284 cout << obj->GetName() << endl ;
287 cout <<
"(null)" << endl ;
300 for(
auto * arg : static_range_cast<RooCmdArg*>(argList)) {
314 const char* opc = arg.
opcode() ;
317 if (!opc)
return false ;
321 coutE(InputArguments) <<
_name <<
" ERROR: argument " << opc <<
" not allowed in this context" << endl ;
333 cout <<
"RooCmdConfig::process: " << opc <<
" has unprocessed dependent " << dep->
GetTitle()
334 <<
", adding to required list" << endl ;
338 cout <<
"RooCmdConfig::process: " << opc <<
" dependent " << dep->
GetTitle() <<
" is already processed" << endl ;
347 cout <<
"RooCmdConfig::process: " << opc <<
" excludes " << mutex->
GetTitle()
348 <<
", adding to forbidden list" << endl ;
354 bool anyField(
false) ;
359 ri.val = arg.
getInt(ri.num) ;
362 cout <<
"RooCmdConfig::process " << ri.name <<
"[int]" <<
" set to " << ri.val << endl ;
373 cout <<
"RooCmdConfig::process " << rd.name <<
"[double]" <<
" set to " << rd.val << endl ;
380 if (rs.argName == opc) {
383 auto const * newStr = arg.
getString(rs.num);
385 if (!rs.val.empty() && rs.appendMode) {
387 rs.val += newStr ? newStr :
"(null)";
389 if(newStr) rs.val = newStr;
393 std::cout <<
"RooCmdConfig::process " << rs.name <<
"[string]" <<
" set to " << rs.val << std::endl ;
401 if(!os.appendMode) os.val.Clear();
405 cout <<
"RooCmdConfig::process " << os.name <<
"[TObject]" <<
" set to " ;
407 cout << os.val.At(0)->GetName() << endl ;
409 cout <<
"(null)" << endl ;
421 cout <<
"RooCmdConfig::process " << cs.name <<
"[RooArgSet]" <<
" set to " ;
423 cout << cs.val->GetName() << endl ;
425 cout <<
"(null)" << endl ;
434 coutE(InputArguments) <<
_name <<
" ERROR: unrecognized command: " << opc << endl ;
448 bool depRet = false ;
450 for (
int ia=0 ; ia<arg.
subArgs().GetSize() ; ia++) {
452 if (strlen(subArg->
GetName())>0) {
457 depRet |=
process(subArgCopy) ;
484 return found !=
_iList.end() ? found->val : defVal;
496 return found !=
_dList.end() ? found->val : defVal;
509 if(found ==
_sList.end())
return defVal;
510 return (convEmptyToNull && found->val.empty()) ? nullptr : found->val.c_str();
522 return found !=
_oList.end() ? found->val.At(0) : defVal ;
533 return found !=
_cList.end() ? found->val : defVal ;
545 return found !=
_oList.end() ? found->val : defaultDummy ;
559 if (!margs.empty()) {
560 coutE(InputArguments) <<
_name <<
" ERROR: missing arguments: " << margs << endl ;
562 coutE(InputArguments) <<
_name <<
" ERROR: illegal combination of arguments and/or missing arguments" << endl ;
576 if (!cmdsToPurge) return ;
596 if (!cmdNameList)
return filterList ;
601 if (removeFromInList) {
604 filterList.
Add(cmd) ;
616 std::initializer_list<std::reference_wrapper<const RooCmdArg>> args) {
620 pc.
process(args.begin(), args.end());
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Named container for two doubles, two integers two object points and three string pointers that can be...
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
double getDouble(Int_t idx) const
Return double stored in slot idx.
RooLinkedList const & subArgs() const
Return list of sub-arguments in this RooCmdArg.
Int_t getInt(Int_t idx) const
bool prefixSubArgs() const
const char * opcode() const
const char * getString(Int_t idx) const
Return string stored in slot idx.
const TObject * getObject(Int_t idx) const
Return TObject stored in slot idx.
Configurable parser for RooCmdArg named arguments.
std::vector< Var< RooArgSet * > > _cList
RooArgSet list.
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.
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.
bool ok(bool verbose) const
Return true of parsing was successful.
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'.
TList _rList
Required cmd list.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
TObject * At(int index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
TObject * FindObject(const char *name) const override
Return pointer to object with given name.
virtual bool Remove(TObject *arg)
Remove object from collection.
The RooStringView is a wrapper around a C-style string that can also be constructed from a std::strin...
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
TObject * Remove(TObject *obj) override
Remove object from the list.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
Collectable string class.
Mother of all ROOT objects.
virtual const char * GetTitle() const
Returns title of object.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
std::vector< std::string > Split(std::string_view str, std::string_view delims, bool skipEmpty=false)
Splits a string at each character in delims.