48 ClassImp(RooCmdConfig);
58 RooCmdConfig::RooCmdConfig(
const char* methodName) :
64 _allowUndefined = kFALSE ;
66 _iIter = _iList.MakeIterator() ;
67 _dIter = _dList.MakeIterator() ;
68 _sIter = _sList.MakeIterator() ;
69 _oIter = _oList.MakeIterator() ;
70 _cIter = _cList.MakeIterator() ;
72 _rIter = _rList.MakeIterator() ;
73 _fIter = _fList.MakeIterator() ;
74 _mIter = _mList.MakeIterator() ;
75 _yIter = _yList.MakeIterator() ;
76 _pIter = _pList.MakeIterator() ;
84 RooCmdConfig::RooCmdConfig(
const RooCmdConfig& other) : TObject(other)
87 _verbose = other._verbose ;
88 _error = other._error ;
89 _allowUndefined = other._allowUndefined ;
91 _iIter = _iList.MakeIterator() ;
92 _dIter = _dList.MakeIterator() ;
93 _sIter = _sList.MakeIterator() ;
94 _oIter = _oList.MakeIterator() ;
95 _cIter = _cList.MakeIterator() ;
96 _rIter = _rList.MakeIterator() ;
97 _fIter = _fList.MakeIterator() ;
98 _mIter = _mList.MakeIterator() ;
99 _yIter = _yList.MakeIterator() ;
100 _pIter = _pList.MakeIterator() ;
102 other._iIter->Reset() ;
104 while((ri=(RooInt*)other._iIter->Next())) {
105 _iList.Add(ri->Clone()) ;
108 other._dIter->Reset() ;
110 while((rd=(RooDouble*)other._dIter->Next())) {
111 _dList.Add(rd->Clone()) ;
114 other._sIter->Reset() ;
116 while((rs=(RooStringVar*)other._sIter->Next())) {
117 _sList.Add(rs->Clone()) ;
120 other._oIter->Reset() ;
122 while((os=(RooTObjWrap*)other._oIter->Next())) {
123 _oList.Add(os->Clone()) ;
126 other._cIter->Reset() ;
128 while((cs=(RooTObjWrap*)other._cIter->Next())) {
129 _cList.Add(cs->Clone()) ;
132 other._rIter->Reset() ;
134 while((rr=(TObjString*)other._rIter->Next())) {
135 _rList.Add(rr->Clone()) ;
138 other._fIter->Reset() ;
140 while((ff=(TObjString*)other._fIter->Next())) {
141 _fList.Add(ff->Clone()) ;
144 other._mIter->Reset() ;
146 while((mm=(TObjString*)other._mIter->Next())) {
147 _mList.Add(mm->Clone()) ;
150 other._yIter->Reset() ;
152 while((yy=(TObjString*)other._yIter->Next())) {
153 _yList.Add(yy->Clone()) ;
156 other._pIter->Reset() ;
158 while((pp=(TObjString*)other._pIter->Next())) {
159 _pList.Add(pp->Clone()) ;
169 RooCmdConfig::~RooCmdConfig()
200 void RooCmdConfig::defineRequiredArgs(
const char* argName1,
const char* argName2,
201 const char* argName3,
const char* argName4,
202 const char* argName5,
const char* argName6,
203 const char* argName7,
const char* argName8)
205 if (argName1) _rList.Add(
new TObjString(argName1)) ;
206 if (argName2) _rList.Add(
new TObjString(argName2)) ;
207 if (argName3) _rList.Add(
new TObjString(argName3)) ;
208 if (argName4) _rList.Add(
new TObjString(argName4)) ;
209 if (argName5) _rList.Add(
new TObjString(argName5)) ;
210 if (argName6) _rList.Add(
new TObjString(argName6)) ;
211 if (argName7) _rList.Add(
new TObjString(argName7)) ;
212 if (argName8) _rList.Add(
new TObjString(argName8)) ;
221 const char* RooCmdConfig::missingArgs()
const
228 Bool_t first(kTRUE) ;
229 while((s=(TObjString*)_rIter->Next())) {
235 ret.Append(s->String()) ;
238 return ret.Length() ? ret.Data() : 0 ;
247 void RooCmdConfig::defineDependency(
const char* refArgName,
const char* neededArgName)
249 TNamed* dep =
new TNamed(refArgName,neededArgName) ;
258 void RooCmdConfig::defineMutex(
const char* argName1,
const char* argName2)
260 TNamed* mutex1 =
new TNamed(argName1,argName2) ;
261 TNamed* mutex2 =
new TNamed(argName2,argName1) ;
271 void RooCmdConfig::defineMutex(
const char* argName1,
const char* argName2,
const char* argName3)
273 defineMutex(argName1,argName2) ;
274 defineMutex(argName1,argName3) ;
275 defineMutex(argName2,argName3) ;
282 void RooCmdConfig::defineMutex(
const char* argName1,
const char* argName2,
const char* argName3,
const char* argName4)
284 defineMutex(argName1,argName2) ;
285 defineMutex(argName1,argName3) ;
286 defineMutex(argName1,argName4) ;
287 defineMutex(argName2,argName3) ;
288 defineMutex(argName2,argName4) ;
289 defineMutex(argName3,argName4) ;
297 void RooCmdConfig::defineMutex(
const char* argName1,
const char* argName2,
const char* argName3,
const char* argName4,
const char* argName5)
299 defineMutex(argName1,argName2) ;
300 defineMutex(argName1,argName3) ;
301 defineMutex(argName1,argName4) ;
302 defineMutex(argName1,argName4) ;
303 defineMutex(argName2,argName3) ;
304 defineMutex(argName2,argName4) ;
305 defineMutex(argName2,argName4) ;
306 defineMutex(argName3,argName4) ;
307 defineMutex(argName3,argName5) ;
308 defineMutex(argName4,argName5) ;
317 Bool_t RooCmdConfig::defineInt(
const char* name,
const char* argName, Int_t intNum, Int_t defVal)
319 if (_iList.FindObject(name)) {
320 coutE(InputArguments) <<
"RooCmdConfig::defintInt: name '" << name <<
"' already defined" << endl ;
324 RooInt* ri =
new RooInt(defVal) ;
326 ri->SetTitle(argName) ;
327 ri->SetUniqueID(intNum) ;
339 Bool_t RooCmdConfig::defineDouble(
const char* name,
const char* argName, Int_t doubleNum, Double_t defVal)
341 if (_dList.FindObject(name)) {
342 coutE(InputArguments) <<
"RooCmdConfig::defineDouble: name '" << name <<
"' already defined" << endl ;
346 RooDouble* rd =
new RooDouble(defVal) ;
348 rd->SetTitle(argName) ;
349 rd->SetUniqueID(doubleNum) ;
363 Bool_t RooCmdConfig::defineString(
const char* name,
const char* argName, Int_t stringNum,
const char* defVal, Bool_t appendMode)
365 if (_sList.FindObject(name)) {
366 coutE(InputArguments) <<
"RooCmdConfig::defineString: name '" << name <<
"' already defined" << endl ;
370 RooStringVar* rs =
new RooStringVar(name,argName,defVal,64000) ;
372 rs->setAttribute(
"RooCmdConfig::AppendMode") ;
374 rs->SetUniqueID(stringNum) ;
388 Bool_t RooCmdConfig::defineObject(
const char* name,
const char* argName, Int_t setNum,
const TObject* defVal, Bool_t isArray)
391 if (_oList.FindObject(name)) {
392 coutE(InputArguments) <<
"RooCmdConfig::defineObject: name '" << name <<
"' already defined" << endl ;
396 RooTObjWrap* os =
new RooTObjWrap((TObject*)defVal,isArray) ;
398 os->SetTitle(argName) ;
399 os->SetUniqueID(setNum) ;
413 Bool_t RooCmdConfig::defineSet(
const char* name,
const char* argName, Int_t setNum,
const RooArgSet* defVal)
416 if (_cList.FindObject(name)) {
417 coutE(InputArguments) <<
"RooCmdConfig::defineObject: name '" << name <<
"' already defined" << endl ;
421 RooTObjWrap* cs =
new RooTObjWrap((TObject*)defVal) ;
423 cs->SetTitle(argName) ;
424 cs->SetUniqueID(setNum) ;
435 void RooCmdConfig::print()
440 while((ri=(RooInt*)_iIter->Next())) {
441 cout << ri->GetName() <<
"[Int_t] = " << *ri << endl ;
447 while((rd=(RooDouble*)_dIter->Next())) {
448 cout << rd->GetName() <<
"[Double_t] = " << *rd << endl ;
454 while((rs=(RooStringVar*)_sIter->Next())) {
455 cout << rs->GetName() <<
"[string] = \"" << rs->getVal() <<
"\"" << endl ;
461 while((ro=(RooTObjWrap*)_oIter->Next())) {
462 cout << ro->GetName() <<
"[TObject] = " ;
464 cout << ro->obj()->GetName() << endl ;
467 cout <<
"(null)" << endl ;
477 Bool_t RooCmdConfig::process(
const RooLinkedList& argList)
480 TIterator* iter = argList.MakeIterator() ;
482 while((arg=(RooCmdArg*)iter->Next())) {
483 ret |= process(*arg) ;
494 Bool_t RooCmdConfig::process(
const RooCmdArg& arg1,
const RooCmdArg& arg2,
const RooCmdArg& arg3,
const RooCmdArg& arg4,
495 const RooCmdArg& arg5,
const RooCmdArg& arg6,
const RooCmdArg& arg7,
const RooCmdArg& arg8)
498 ret |= process(arg1) ;
499 ret |= process(arg2) ;
500 ret |= process(arg3) ;
501 ret |= process(arg4) ;
502 ret |= process(arg5) ;
503 ret |= process(arg6) ;
504 ret |= process(arg7) ;
505 ret |= process(arg8) ;
514 Bool_t RooCmdConfig::process(
const RooCmdArg& arg)
517 const char* opc = arg.opcode() ;
520 if (!opc)
return kFALSE ;
523 if (_fList.FindObject(opc)) {
524 coutE(InputArguments) << _name <<
" ERROR: argument " << opc <<
" not allowed in this context" << endl ;
530 TObject* dep = _yList.FindObject(opc) ;
533 if (!_pList.FindObject(dep->GetTitle())) {
534 _rList.Add(
new TObjString(dep->GetTitle())) ;
536 cout <<
"RooCmdConfig::process: " << opc <<
" has unprocessed dependent " << dep->GetTitle()
537 <<
", adding to required list" << endl ;
541 cout <<
"RooCmdConfig::process: " << opc <<
" dependent " << dep->GetTitle() <<
" is already processed" << endl ;
547 TObject * mutex = _mList.FindObject(opc) ;
550 cout <<
"RooCmdConfig::process: " << opc <<
" excludes " << mutex->GetTitle()
551 <<
", adding to forbidden list" << endl ;
553 _fList.Add(
new TObjString(mutex->GetTitle())) ;
557 Bool_t anyField(kFALSE) ;
562 while((ri=(RooInt*)_iIter->Next())) {
563 if (!TString(opc).CompareTo(ri->GetTitle())) {
564 *ri = arg.getInt(ri->GetUniqueID()) ;
567 cout <<
"RooCmdConfig::process " << ri->GetName() <<
"[Int_t]" <<
" set to " << *ri << endl ;
575 while((rd=(RooDouble*)_dIter->Next())) {
576 if (!TString(opc).CompareTo(rd->GetTitle())) {
577 *rd = arg.getDouble(rd->GetUniqueID()) ;
580 cout <<
"RooCmdConfig::process " << rd->GetName() <<
"[Double_t]" <<
" set to " << *rd << endl ;
588 while((rs=(RooStringVar*)_sIter->Next())) {
589 if (!TString(opc).CompareTo(rs->GetTitle())) {
591 const char* oldStr = rs->getVal() ;
593 if (oldStr && strlen(oldStr)>0 && rs->getAttribute(
"RooCmdConfig::AppendMode")) {
594 rs->setVal(Form(
"%s,%s",rs->getVal(),arg.getString(rs->GetUniqueID()))) ;
596 rs->setVal(arg.getString(rs->GetUniqueID())) ;
600 cout <<
"RooCmdConfig::process " << rs->GetName() <<
"[string]" <<
" set to " << rs->getVal() << endl ;
608 while((os=(RooTObjWrap*)_oIter->Next())) {
609 if (!TString(opc).CompareTo(os->GetTitle())) {
610 os->setObj((TObject*)arg.getObject(os->GetUniqueID())) ;
613 cout <<
"RooCmdConfig::process " << os->GetName() <<
"[TObject]" <<
" set to " ;
615 cout << os->obj()->GetName() << endl ;
617 cout <<
"(null)" << endl ;
626 while((cs=(RooTObjWrap*)_cIter->Next())) {
627 if (!TString(opc).CompareTo(cs->GetTitle())) {
628 cs->setObj((TObject*)arg.getSet(cs->GetUniqueID())) ;
631 cout <<
"RooCmdConfig::process " << cs->GetName() <<
"[RooArgSet]" <<
" set to " ;
633 cout << cs->obj()->GetName() << endl ;
635 cout <<
"(null)" << endl ;
641 Bool_t multiArg = !TString(
"MultiArg").CompareTo(opc) ;
643 if (!anyField && !_allowUndefined && !multiArg) {
644 coutE(InputArguments) << _name <<
" ERROR: unrecognized command: " << opc << endl ;
650 while ( (obj = _rList.FindObject(opc)) ) {
655 TNamed *pcmd =
new TNamed(opc,opc) ;
658 Bool_t depRet = kFALSE ;
659 if (arg._procSubArgs) {
660 for (Int_t ia=0 ; ia<arg._argList.GetSize() ; ia++) {
661 RooCmdArg* subArg =
static_cast<RooCmdArg*
>(arg._argList.At(ia)) ;
662 if (strlen(subArg->GetName())>0) {
663 RooCmdArg subArgCopy(*subArg) ;
664 if (arg._prefixSubArgs) {
665 subArgCopy.SetName(Form(
"%s::%s",arg.GetName(),subArg->GetName())) ;
667 depRet |= process(subArgCopy) ;
672 return ((anyField||_allowUndefined)?kFALSE:kTRUE)||depRet ;
680 Bool_t RooCmdConfig::hasProcessed(
const char* cmdName)
const
682 return _pList.FindObject(cmdName) ? kTRUE : kFALSE ;
691 Int_t RooCmdConfig::getInt(
const char* name, Int_t defVal)
693 RooInt* ri = (RooInt*) _iList.FindObject(name) ;
694 return ri ? (Int_t)(*ri) : defVal ;
703 Double_t RooCmdConfig::getDouble(
const char* name, Double_t defVal)
705 RooDouble* rd = (RooDouble*) _dList.FindObject(name) ;
706 return rd ? (Double_t)(*rd) : defVal ;
716 const char* RooCmdConfig::getString(
const char* name,
const char* defVal, Bool_t convEmptyToNull)
718 RooStringVar* rs = (RooStringVar*) _sList.FindObject(name) ;
719 return rs ? ((convEmptyToNull && strlen(rs->getVal())==0) ? 0 : ((
const char*)rs->getVal()) ) : defVal ;
728 TObject* RooCmdConfig::getObject(
const char* name, TObject* defVal)
730 RooTObjWrap* ro = (RooTObjWrap*) _oList.FindObject(name) ;
731 return ro ? ro->obj() : defVal ;
739 RooArgSet* RooCmdConfig::getSet(
const char* name, RooArgSet* defVal)
741 RooTObjWrap* ro = (RooTObjWrap*) _cList.FindObject(name) ;
742 return ro ? ((RooArgSet*)ro->obj()) : defVal ;
750 const RooLinkedList& RooCmdConfig::getObjectList(
const char* name)
752 static RooLinkedList defaultDummy ;
753 RooTObjWrap* ro = (RooTObjWrap*) _oList.FindObject(name) ;
754 return ro ? ro->objList() : defaultDummy ;
762 Bool_t RooCmdConfig::ok(Bool_t verbose)
const
764 if (_rList.GetSize()==0 && !_error)
return kTRUE ;
767 const char* margs = missingArgs() ;
769 coutE(InputArguments) << _name <<
" ERROR: missing arguments: " << margs << endl ;
771 coutE(InputArguments) << _name <<
" ERROR: illegal combination of arguments and/or missing arguments" << endl ;
782 void RooCmdConfig::stripCmdList(RooLinkedList& cmdList,
const char* cmdsToPurge)
785 if (!cmdsToPurge) return ;
789 strlcpy(buf,cmdsToPurge,1024) ;
791 char* name = strtok(buf,
",") ;
793 TObject* cmd = cmdList.FindObject(name) ;
794 if (cmd) cmdList.Remove(cmd) ;
795 name = strtok(0,
",") ;
806 RooLinkedList RooCmdConfig::filterCmdList(RooLinkedList& cmdInList,
const char* cmdNameList, Bool_t removeFromInList)
808 RooLinkedList filterList ;
809 if (!cmdNameList)
return filterList ;
813 strlcpy(buf,cmdNameList,1024) ;
815 char* name = strtok(buf,
",") ;
817 TObject* cmd = cmdInList.FindObject(name) ;
819 if (removeFromInList) {
820 cmdInList.Remove(cmd) ;
822 filterList.Add(cmd) ;
824 name = strtok(0,
",") ;
835 Int_t RooCmdConfig::decodeIntOnTheFly(
const char* callerID,
const char* cmdArgName, Int_t intIdx, Int_t defVal,
const RooCmdArg& arg1,
836 const RooCmdArg& arg2,
const RooCmdArg& arg3,
const RooCmdArg& arg4,
837 const RooCmdArg& arg5,
const RooCmdArg& arg6,
const RooCmdArg& arg7,
838 const RooCmdArg& arg8,
const RooCmdArg& arg9)
840 RooCmdConfig pc(callerID) ;
841 pc.allowUndefined() ;
842 pc.defineInt(
"theInt",cmdArgName,intIdx,defVal) ;
843 pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
844 pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
845 pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
846 return pc.getInt(
"theInt") ;
855 std::string RooCmdConfig::decodeStringOnTheFly(
const char* callerID,
const char* cmdArgName, Int_t strIdx,
const char* defVal,
const RooCmdArg& arg1,
856 const RooCmdArg& arg2,
const RooCmdArg& arg3,
const RooCmdArg& arg4,
857 const RooCmdArg& arg5,
const RooCmdArg& arg6,
const RooCmdArg& arg7,
858 const RooCmdArg& arg8,
const RooCmdArg& arg9)
860 RooCmdConfig pc(callerID) ;
861 pc.allowUndefined() ;
862 pc.defineString(
"theString",cmdArgName,strIdx,defVal) ;
863 pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
864 pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
865 pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
866 const char* ret = pc.getString(
"theString",0,kTRUE) ;
869 return std::string(ret);
871 return std::string();
880 TObject* RooCmdConfig::decodeObjOnTheFly(
const char* callerID,
const char* cmdArgName, Int_t objIdx, TObject* defVal,
const RooCmdArg& arg1,
881 const RooCmdArg& arg2,
const RooCmdArg& arg3,
const RooCmdArg& arg4,
882 const RooCmdArg& arg5,
const RooCmdArg& arg6,
const RooCmdArg& arg7,
883 const RooCmdArg& arg8,
const RooCmdArg& arg9)
885 RooCmdConfig pc(callerID) ;
886 pc.allowUndefined() ;
887 pc.defineObject(
"theObj",cmdArgName,objIdx,defVal) ;
888 pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
889 pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
890 pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
891 return (TObject*) pc.getObject(
"theObj") ;