Logo ROOT  
Reference Guide
RooCmdConfig.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
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
18/**
19\file RooCmdConfig.cxx
20\class RooCmdConfig
21\ingroup Roofitcore
22
23Class RooCmdConfig is a configurable parser for RooCmdArg named
24arguments. It maps the contents of named arguments named to integers,
25doubles, strings and TObjects that can be retrieved after processing
26a set of RooCmdArgs. The parser also has options to enforce syntax
27rules such as (conditionally) required arguments, mutually exclusive
28arguments and dependencies between arguments
29**/
30
31#include "RooFit.h"
32
33#include "RooCmdConfig.h"
34#include "RooInt.h"
35#include "RooDouble.h"
36#include "RooArgSet.h"
37#include "RooStringVar.h"
38#include "RooTObjWrap.h"
39#include "RooAbsData.h"
40#include "TObjString.h"
41#include "RooMsgService.h"
42
43#include "Riostream.h"
44
45
46using namespace std;
47
49 ;
50
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// Constructor taking descriptive name of owner/user which
55/// is used as prefix for any warning or error messages
56/// generated by this parser
57
58RooCmdConfig::RooCmdConfig(const char* methodName) :
59 TObject(),
60 _name(methodName)
61{
63 _error = kFALSE ;
65
71
77}
78
79
80
81////////////////////////////////////////////////////////////////////////////////
82/// Copy constructor
83
85{
86 _name = other._name ;
87 _verbose = other._verbose ;
88 _error = other._error ;
90
101
102 other._iIter->Reset() ;
103 RooInt* ri ;
104 while((ri=(RooInt*)other._iIter->Next())) {
105 _iList.Add(ri->Clone()) ;
106 }
107
108 other._dIter->Reset() ;
109 RooDouble* rd ;
110 while((rd=(RooDouble*)other._dIter->Next())) {
111 _dList.Add(rd->Clone()) ;
112 }
113
114 other._sIter->Reset() ;
115 RooStringVar* rs ;
116 while((rs=(RooStringVar*)other._sIter->Next())) {
117 _sList.Add(rs->Clone()) ;
118 }
119
120 other._oIter->Reset() ;
121 RooTObjWrap* os ;
122 while((os=(RooTObjWrap*)other._oIter->Next())) {
123 _oList.Add(os->Clone()) ;
124 }
125
126 other._cIter->Reset() ;
127 RooTObjWrap* cs ;
128 while((cs=(RooTObjWrap*)other._cIter->Next())) {
129 _cList.Add(cs->Clone()) ;
130 }
131
132 other._rIter->Reset() ;
133 TObjString* rr ;
134 while((rr=(TObjString*)other._rIter->Next())) {
135 _rList.Add(rr->Clone()) ;
136 }
137
138 other._fIter->Reset() ;
139 TObjString* ff ;
140 while((ff=(TObjString*)other._fIter->Next())) {
141 _fList.Add(ff->Clone()) ;
142 }
143
144 other._mIter->Reset() ;
145 TObjString* mm ;
146 while((mm=(TObjString*)other._mIter->Next())) {
147 _mList.Add(mm->Clone()) ;
148 }
149
150 other._yIter->Reset() ;
151 TObjString* yy ;
152 while((yy=(TObjString*)other._yIter->Next())) {
153 _yList.Add(yy->Clone()) ;
154 }
155
156 other._pIter->Reset() ;
157 TObjString* pp ;
158 while((pp=(TObjString*)other._pIter->Next())) {
159 _pList.Add(pp->Clone()) ;
160 }
161
162}
163
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Destructor
168
170{
171 delete _iIter ;
172 delete _dIter ;
173 delete _sIter ;
174 delete _oIter ;
175 delete _cIter ;
176 delete _rIter ;
177 delete _fIter ;
178 delete _mIter ;
179 delete _yIter ;
180 delete _pIter ;
181
182 _iList.Delete() ;
183 _dList.Delete() ;
184 _sList.Delete() ;
185 _cList.Delete() ;
186 _oList.Delete() ;
187 _rList.Delete() ;
188 _fList.Delete() ;
189 _mList.Delete() ;
190 _yList.Delete() ;
191 _pList.Delete() ;
192}
193
194
195
196////////////////////////////////////////////////////////////////////////////////
197/// Add condition that any of listed arguments must be processed
198/// for parsing to be declared successful
199
200void 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)
204{
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)) ;
213}
214
215
216
217////////////////////////////////////////////////////////////////////////////////
218/// Return string with names of arguments that were required, but not
219/// processed
220
221const char* RooCmdConfig::missingArgs() const
222{
223 static TString ret ;
224 ret="" ;
225
226 _rIter->Reset() ;
227 TObjString* s ;
229 while((s=(TObjString*)_rIter->Next())) {
230 if (first) {
231 first=kFALSE ;
232 } else {
233 ret.Append(", ") ;
234 }
235 ret.Append(s->String()) ;
236 }
237
238 return ret.Length() ? ret.Data() : 0 ;
239}
240
241
242
243////////////////////////////////////////////////////////////////////////////////
244/// Define that processing argument name refArgName requires processing
245/// of argument named neededArgName to successfully complete parsing
246
247void RooCmdConfig::defineDependency(const char* refArgName, const char* neededArgName)
248{
249 TNamed* dep = new TNamed(refArgName,neededArgName) ;
250 _yList.Add(dep) ;
251}
252
253
254
255////////////////////////////////////////////////////////////////////////////////
256/// Define arguments named argName1 and argName2 mutually exclusive
257
258void RooCmdConfig::defineMutex(const char* argName1, const char* argName2)
259{
260 TNamed* mutex1 = new TNamed(argName1,argName2) ;
261 TNamed* mutex2 = new TNamed(argName2,argName1) ;
262 _mList.Add(mutex1) ;
263 _mList.Add(mutex2) ;
264}
265
266
267
268////////////////////////////////////////////////////////////////////////////////
269/// Define arguments named argName1,argName2 and argName3 mutually exclusive
270
271void RooCmdConfig::defineMutex(const char* argName1, const char* argName2, const char* argName3)
272{
273 defineMutex(argName1,argName2) ;
274 defineMutex(argName1,argName3) ;
275 defineMutex(argName2,argName3) ;
276}
277
278
279////////////////////////////////////////////////////////////////////////////////
280/// Define arguments named argName1,argName2,argName3 and argName4 mutually exclusive
281
282void RooCmdConfig::defineMutex(const char* argName1, const char* argName2, const char* argName3, const char* argName4)
283{
284 defineMutex(argName1,argName2) ;
285 defineMutex(argName1,argName3) ;
286 defineMutex(argName1,argName4) ;
287 defineMutex(argName2,argName3) ;
288 defineMutex(argName2,argName4) ;
289 defineMutex(argName3,argName4) ;
290}
291
292
293
294////////////////////////////////////////////////////////////////////////////////
295/// Define arguments named argName1,argName2,argName3 and argName4 mutually exclusive
296
297void RooCmdConfig::defineMutex(const char* argName1, const char* argName2, const char* argName3, const char* argName4, const char* argName5)
298{
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) ;
309}
310
311
312
313////////////////////////////////////////////////////////////////////////////////
314/// Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName
315/// Define default value for this int property to be defVal in case named argument is not processed
316
317Bool_t RooCmdConfig::defineInt(const char* name, const char* argName, Int_t intNum, Int_t defVal)
318{
319 if (_iList.FindObject(name)) {
320 coutE(InputArguments) << "RooCmdConfig::defintInt: name '" << name << "' already defined" << endl ;
321 return kTRUE ;
322 }
323
324 RooInt* ri = new RooInt(defVal) ;
325 ri->SetName(name) ;
326 ri->SetTitle(argName) ;
327 ri->SetUniqueID(intNum) ;
328
329 _iList.Add(ri) ;
330 return kFALSE ;
331}
332
333
334
335////////////////////////////////////////////////////////////////////////////////
336/// Define Double_t property name 'name' mapped to Double_t in slot 'doubleNum' in RooCmdArg with name argName
337/// Define default value for this Double_t property to be defVal in case named argument is not processed
338
339Bool_t RooCmdConfig::defineDouble(const char* name, const char* argName, Int_t doubleNum, Double_t defVal)
340{
341 if (_dList.FindObject(name)) {
342 coutE(InputArguments) << "RooCmdConfig::defineDouble: name '" << name << "' already defined" << endl ;
343 return kTRUE ;
344 }
345
346 RooDouble* rd = new RooDouble(defVal) ;
347 rd->SetName(name) ;
348 rd->SetTitle(argName) ;
349 rd->SetUniqueID(doubleNum) ;
350
351 _dList.Add(rd) ;
352 return kFALSE ;
353}
354
355
356
357////////////////////////////////////////////////////////////////////////////////
358/// Define Double_t property name 'name' mapped to Double_t in slot 'stringNum' in RooCmdArg with name argName
359/// Define default value for this Double_t property to be defVal in case named argument is not processed
360/// If appendMode is true, values found in multiple matching RooCmdArg arguments will be concatenated
361/// in the output string. If it is false, only the value of the last processed instance is retained
362
363Bool_t RooCmdConfig::defineString(const char* name, const char* argName, Int_t stringNum, const char* defVal, Bool_t appendMode)
364{
365 if (_sList.FindObject(name)) {
366 coutE(InputArguments) << "RooCmdConfig::defineString: name '" << name << "' already defined" << endl ;
367 return kTRUE ;
368 }
369
370 RooStringVar* rs = new RooStringVar(name,argName,defVal,64000) ;
371 if (appendMode) {
372 rs->setAttribute("RooCmdConfig::AppendMode") ;
373 }
374 rs->SetUniqueID(stringNum) ;
375
376 _sList.Add(rs) ;
377 return kFALSE ;
378}
379
380
381
382////////////////////////////////////////////////////////////////////////////////
383/// Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName
384/// Define default value for this TObject property to be defVal in case named argument is not processed.
385/// If isArray is true, an array of TObjects is harvested in case multiple matching named arguments are processed.
386/// If isArray is false, only the TObject in the last processed named argument is retained
387
388Bool_t RooCmdConfig::defineObject(const char* name, const char* argName, Int_t setNum, const TObject* defVal, Bool_t isArray)
389{
390
391 if (_oList.FindObject(name)) {
392 coutE(InputArguments) << "RooCmdConfig::defineObject: name '" << name << "' already defined" << endl ;
393 return kTRUE ;
394 }
395
396 RooTObjWrap* os = new RooTObjWrap((TObject*)defVal,isArray) ;
397 os->SetName(name) ;
398 os->SetTitle(argName) ;
399 os->SetUniqueID(setNum) ;
400
401 _oList.Add(os) ;
402 return kFALSE ;
403}
404
405
406
407////////////////////////////////////////////////////////////////////////////////
408/// Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName
409/// Define default value for this TObject property to be defVal in case named argument is not processed.
410/// If isArray is true, an array of TObjects is harvested in case multiple matching named arguments are processed.
411/// If isArray is false, only the TObject in the last processed named argument is retained
412
413Bool_t RooCmdConfig::defineSet(const char* name, const char* argName, Int_t setNum, const RooArgSet* defVal)
414{
415
416 if (_cList.FindObject(name)) {
417 coutE(InputArguments) << "RooCmdConfig::defineObject: name '" << name << "' already defined" << endl ;
418 return kTRUE ;
419 }
420
421 RooTObjWrap* cs = new RooTObjWrap((TObject*)defVal) ;
422 cs->SetName(name) ;
423 cs->SetTitle(argName) ;
424 cs->SetUniqueID(setNum) ;
425
426 _cList.Add(cs) ;
427 return kFALSE ;
428}
429
430
431
432////////////////////////////////////////////////////////////////////////////////
433/// Print configuration of parser
434
436{
437 // Find registered integer fields for this opcode
438 _iIter->Reset() ;
439 RooInt* ri ;
440 while((ri=(RooInt*)_iIter->Next())) {
441 cout << ri->GetName() << "[Int_t] = " << *ri << endl ;
442 }
443
444 // Find registered double fields for this opcode
445 _dIter->Reset() ;
446 RooDouble* rd ;
447 while((rd=(RooDouble*)_dIter->Next())) {
448 cout << rd->GetName() << "[Double_t] = " << *rd << endl ;
449 }
450
451 // Find registered string fields for this opcode
452 _sIter->Reset() ;
453 RooStringVar* rs ;
454 while((rs=(RooStringVar*)_sIter->Next())) {
455 cout << rs->GetName() << "[string] = \"" << rs->getVal() << "\"" << endl ;
456 }
457
458 // Find registered argset fields for this opcode
459 _oIter->Reset() ;
460 RooTObjWrap* ro ;
461 while((ro=(RooTObjWrap*)_oIter->Next())) {
462 cout << ro->GetName() << "[TObject] = " ;
463 if (ro->obj()) {
464 cout << ro->obj()->GetName() << endl ;
465 } else {
466
467 cout << "(null)" << endl ;
468 }
469 }
470}
471
472
473
474////////////////////////////////////////////////////////////////////////////////
475/// Process given list with RooCmdArgs
476
478{
479 Bool_t ret(kFALSE) ;
480 TIterator* iter = argList.MakeIterator() ;
481 RooCmdArg* arg ;
482 while((arg=(RooCmdArg*)iter->Next())) {
483 ret |= process(*arg) ;
484 }
485 delete iter ;
486 return ret ;
487}
488
489
490
491////////////////////////////////////////////////////////////////////////////////
492/// Process given RooCmdArgs
493
494Bool_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)
496{
497 Bool_t ret(kFALSE) ;
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) ;
506 return ret ;
507}
508
509
510
511////////////////////////////////////////////////////////////////////////////////
512/// Process given RooCmdArg
513
515{
516 // Retrive command code
517 const char* opc = arg.opcode() ;
518
519 // Ignore empty commands
520 if (!opc) return kFALSE ;
521
522 // Check if not forbidden
523 if (_fList.FindObject(opc)) {
524 coutE(InputArguments) << _name << " ERROR: argument " << opc << " not allowed in this context" << endl ;
525 _error = kTRUE ;
526 return kTRUE ;
527 }
528
529 // Check if this code generates any dependencies
530 TObject* dep = _yList.FindObject(opc) ;
531 if (dep) {
532 // Dependent command found, add to required list if not already processed
533 if (!_pList.FindObject(dep->GetTitle())) {
534 _rList.Add(new TObjString(dep->GetTitle())) ;
535 if (_verbose) {
536 cout << "RooCmdConfig::process: " << opc << " has unprocessed dependent " << dep->GetTitle()
537 << ", adding to required list" << endl ;
538 }
539 } else {
540 if (_verbose) {
541 cout << "RooCmdConfig::process: " << opc << " dependent " << dep->GetTitle() << " is already processed" << endl ;
542 }
543 }
544 }
545
546 // Check for mutexes
547 TObject * mutex = _mList.FindObject(opc) ;
548 if (mutex) {
549 if (_verbose) {
550 cout << "RooCmdConfig::process: " << opc << " excludes " << mutex->GetTitle()
551 << ", adding to forbidden list" << endl ;
552 }
553 _fList.Add(new TObjString(mutex->GetTitle())) ;
554 }
555
556
557 Bool_t anyField(kFALSE) ;
558
559 // Find registered integer fields for this opcode
560 _iIter->Reset() ;
561 RooInt* ri ;
562 while((ri=(RooInt*)_iIter->Next())) {
563 if (!TString(opc).CompareTo(ri->GetTitle())) {
564 *ri = arg.getInt(ri->GetUniqueID()) ;
565 anyField = kTRUE ;
566 if (_verbose) {
567 cout << "RooCmdConfig::process " << ri->GetName() << "[Int_t]" << " set to " << *ri << endl ;
568 }
569 }
570 }
571
572 // Find registered double fields for this opcode
573 _dIter->Reset() ;
574 RooDouble* rd ;
575 while((rd=(RooDouble*)_dIter->Next())) {
576 if (!TString(opc).CompareTo(rd->GetTitle())) {
577 *rd = arg.getDouble(rd->GetUniqueID()) ;
578 anyField = kTRUE ;
579 if (_verbose) {
580 cout << "RooCmdConfig::process " << rd->GetName() << "[Double_t]" << " set to " << *rd << endl ;
581 }
582 }
583 }
584
585 // Find registered string fields for this opcode
586 _sIter->Reset() ;
587 RooStringVar* rs ;
588 while((rs=(RooStringVar*)_sIter->Next())) {
589 if (!TString(opc).CompareTo(rs->GetTitle())) {
590
591 const char* oldStr = rs->getVal() ;
592
593 if (oldStr && strlen(oldStr)>0 && rs->getAttribute("RooCmdConfig::AppendMode")) {
594 rs->setVal(Form("%s,%s",rs->getVal(),arg.getString(rs->GetUniqueID()))) ;
595 } else {
596 rs->setVal(arg.getString(rs->GetUniqueID())) ;
597 }
598 anyField = kTRUE ;
599 if (_verbose) {
600 cout << "RooCmdConfig::process " << rs->GetName() << "[string]" << " set to " << rs->getVal() << endl ;
601 }
602 }
603 }
604
605 // Find registered TObject fields for this opcode
606 _oIter->Reset() ;
607 RooTObjWrap* os ;
608 while((os=(RooTObjWrap*)_oIter->Next())) {
609 if (!TString(opc).CompareTo(os->GetTitle())) {
610 os->setObj((TObject*)arg.getObject(os->GetUniqueID())) ;
611 anyField = kTRUE ;
612 if (_verbose) {
613 cout << "RooCmdConfig::process " << os->GetName() << "[TObject]" << " set to " ;
614 if (os->obj()) {
615 cout << os->obj()->GetName() << endl ;
616 } else {
617 cout << "(null)" << endl ;
618 }
619 }
620 }
621 }
622
623 // Find registered RooArgSet fields for this opcode
624 _cIter->Reset() ;
625 RooTObjWrap* cs ;
626 while((cs=(RooTObjWrap*)_cIter->Next())) {
627 if (!TString(opc).CompareTo(cs->GetTitle())) {
628 cs->setObj((TObject*)arg.getSet(cs->GetUniqueID())) ;
629 anyField = kTRUE ;
630 if (_verbose) {
631 cout << "RooCmdConfig::process " << cs->GetName() << "[RooArgSet]" << " set to " ;
632 if (cs->obj()) {
633 cout << cs->obj()->GetName() << endl ;
634 } else {
635 cout << "(null)" << endl ;
636 }
637 }
638 }
639 }
640
641 Bool_t multiArg = !TString("MultiArg").CompareTo(opc) ;
642
643 if (!anyField && !_allowUndefined && !multiArg) {
644 coutE(InputArguments) << _name << " ERROR: unrecognized command: " << opc << endl ;
645 }
646
647
648 // Remove command from required-args list (if it was there)
649 TObject* obj;
650 while ( (obj = _rList.FindObject(opc)) ) {
651 _rList.Remove(obj);
652 }
653
654 // Add command the processed list
655 TNamed *pcmd = new TNamed(opc,opc) ;
656 _pList.Add(pcmd) ;
657
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())) ;
666 }
667 depRet |= process(subArgCopy) ;
668 }
669 }
670 }
671
672 return ((anyField||_allowUndefined)?kFALSE:kTRUE)||depRet ;
673}
674
675
676
677////////////////////////////////////////////////////////////////////////////////
678/// Return true if RooCmdArg with name 'cmdName' has been processed
679
680Bool_t RooCmdConfig::hasProcessed(const char* cmdName) const
681{
682 return _pList.FindObject(cmdName) ? kTRUE : kFALSE ;
683}
684
685
686
687////////////////////////////////////////////////////////////////////////////////
688/// Return integer property registered with name 'name'. If no
689/// property is registered, return defVal
690
692{
694 return ri ? (Int_t)(*ri) : defVal ;
695}
696
697
698
699////////////////////////////////////////////////////////////////////////////////
700/// Return Double_t property registered with name 'name'. If no
701/// property is registered, return defVal
702
704{
706 return rd ? (Double_t)(*rd) : defVal ;
707}
708
709
710
711////////////////////////////////////////////////////////////////////////////////
712/// Return string property registered with name 'name'. If no
713/// property is registered, return defVal. If convEmptyToNull
714/// is true, empty string will be returned as null pointers
715
716const char* RooCmdConfig::getString(const char* name, const char* defVal, Bool_t convEmptyToNull)
717{
719 return rs ? ((convEmptyToNull && strlen(rs->getVal())==0) ? 0 : ((const char*)rs->getVal()) ) : defVal ;
720}
721
722
723
724////////////////////////////////////////////////////////////////////////////////
725/// Return TObject property registered with name 'name'. If no
726/// property is registered, return defVal
727
729{
731 return ro ? ro->obj() : defVal ;
732}
733
734
735////////////////////////////////////////////////////////////////////////////////
736/// Return RooArgSet property registered with name 'name'. If no
737/// property is registered, return defVal
738
740{
742 return ro ? ((RooArgSet*)ro->obj()) : defVal ;
743}
744
745
746
747////////////////////////////////////////////////////////////////////////////////
748/// Return list of objects registered with name 'name'
749
751{
752 static RooLinkedList defaultDummy ;
754 return ro ? ro->objList() : defaultDummy ;
755}
756
757
758
759////////////////////////////////////////////////////////////////////////////////
760/// Return true of parsing was successful
761
763{
764 if (_rList.GetSize()==0 && !_error) return kTRUE ;
765
766 if (verbose) {
767 const char* margs = missingArgs() ;
768 if (margs) {
769 coutE(InputArguments) << _name << " ERROR: missing arguments: " << margs << endl ;
770 } else {
771 coutE(InputArguments) << _name << " ERROR: illegal combination of arguments and/or missing arguments" << endl ;
772 }
773 }
774 return kFALSE ;
775}
776
777
778
779////////////////////////////////////////////////////////////////////////////////
780/// Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList
781
782void RooCmdConfig::stripCmdList(RooLinkedList& cmdList, const char* cmdsToPurge)
783{
784 // Sanity check
785 if (!cmdsToPurge) return ;
786
787 // Copy command list for parsing
788 char buf[1024] ;
789 strlcpy(buf,cmdsToPurge,1024) ;
790
791 char* name = strtok(buf,",") ;
792 while(name) {
793 TObject* cmd = cmdList.FindObject(name) ;
794 if (cmd) cmdList.Remove(cmd) ;
795 name = strtok(0,",") ;
796 }
797
798}
799
800
801
802////////////////////////////////////////////////////////////////////////////////
803/// Utility function to filter commands listed in cmdNameList from cmdInList. Filtered arguments are put in the returned list.
804/// If removeFromInList is true then these commands are removed from the input list
805
806RooLinkedList RooCmdConfig::filterCmdList(RooLinkedList& cmdInList, const char* cmdNameList, Bool_t removeFromInList)
807{
808 RooLinkedList filterList ;
809 if (!cmdNameList) return filterList ;
810
811 // Copy command list for parsing
812 char buf[1024] ;
813 strlcpy(buf,cmdNameList,1024) ;
814
815 char* name = strtok(buf,",") ;
816 while(name) {
817 TObject* cmd = cmdInList.FindObject(name) ;
818 if (cmd) {
819 if (removeFromInList) {
820 cmdInList.Remove(cmd) ;
821 }
822 filterList.Add(cmd) ;
823 }
824 name = strtok(0,",") ;
825 }
826 return filterList ;
827}
828
829
830
831////////////////////////////////////////////////////////////////////////////////
832/// Static decoder function allows to retrieve integer property from set of RooCmdArgs
833/// For use in base member initializers in constructors
834
835Int_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)
839{
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") ;
847}
848
849
850
851////////////////////////////////////////////////////////////////////////////////
852/// Static decoder function allows to retrieve string property from set of RooCmdArgs
853/// For use in base member initializers in constructors
854
855std::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)
859{
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) ;
867
868 if (ret)
869 return std::string(ret);
870
871 return std::string();
872}
873
874
875
876////////////////////////////////////////////////////////////////////////////////
877/// Static decoder function allows to retrieve object property from set of RooCmdArgs
878/// For use in base member initializers in constructors
879
880TObject* 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)
884{
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") ;
892}
#define coutE(a)
Definition: RooMsgService.h:34
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
char * Form(const char *fmt,...)
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:83
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:261
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:284
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:28
Double_t getDouble(Int_t idx) const
Definition: RooCmdArg.h:85
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:200
RooLinkedList _argList
Definition: RooCmdArg.h:118
Bool_t _procSubArgs
Definition: RooCmdArg.h:116
Bool_t _prefixSubArgs
Definition: RooCmdArg.h:119
Int_t getInt(Int_t idx) const
Definition: RooCmdArg.h:81
const char * opcode() const
Definition: RooCmdArg.h:62
const char * getString(Int_t idx) const
Definition: RooCmdArg.h:89
const TObject * getObject(Int_t idx) const
Definition: RooCmdArg.h:93
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:27
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name 'name'.
~RooCmdConfig()
Destructor.
Bool_t defineInt(const char *name, const char *argName, Int_t intNum, Int_t defValue=0)
Define integer property name 'name' mapped to integer in slot 'intNum' in RooCmdArg with name argName...
static std::string decodeStringOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, const char *defVal, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Static decoder function allows to retrieve string property from set of RooCmdArgs For use in base mem...
TIterator * _rIter
Definition: RooCmdConfig.h:125
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
static TObject * decodeObjOnTheFly(const char *callerID, const char *cmdArgName, Int_t objIdx, TObject *defVal, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Static decoder function allows to retrieve object property from set of RooCmdArgs For use in base mem...
static Int_t decodeIntOnTheFly(const char *callerID, const char *cmdArgName, Int_t intIdx, Int_t defVal, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg())
Static decoder function allows to retrieve integer property from set of RooCmdArgs For use in base me...
TIterator * _iIter
Definition: RooCmdConfig.h:120
Bool_t defineObject(const char *name, const char *argName, Int_t setNum, const TObject *obj=0, Bool_t isArray=kFALSE)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
TIterator * _fIter
Definition: RooCmdConfig.h:126
TIterator * _oIter
Definition: RooCmdConfig.h:123
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name 'name'.
TIterator * _pIter
Definition: RooCmdConfig.h:129
TIterator * _sIter
Definition: RooCmdConfig.h:122
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
Bool_t defineDouble(const char *name, const char *argName, Int_t doubleNum, Double_t defValue=0.)
Define Double_t property name 'name' mapped to Double_t in slot 'doubleNum' in RooCmdArg with name ar...
TIterator * _mIter
Definition: RooCmdConfig.h:127
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name 'name'.
void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList.
Bool_t defineSet(const char *name, const char *argName, Int_t setNum, const RooArgSet *set=0)
Define TObject property name 'name' mapped to object in slot 'setNum' in RooCmdArg with name argName ...
Bool_t defineString(const char *name, const char *argName, Int_t stringNum, const char *defValue="", Bool_t appendMode=kFALSE)
Define Double_t property name 'name' mapped to Double_t in slot 'stringNum' in RooCmdArg with name ar...
RooArgSet * getSet(const char *name, RooArgSet *set=0)
Return RooArgSet property registered with name 'name'.
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
TIterator * _yIter
Definition: RooCmdConfig.h:128
RooCmdConfig(const char *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_t removeFromInList=kTRUE)
Utility function to filter commands listed in cmdNameList from cmdInList.
Bool_t _verbose
Definition: RooCmdConfig.h:104
TIterator * _cIter
Definition: RooCmdConfig.h:124
TIterator * _dIter
Definition: RooCmdConfig.h:121
Bool_t _allowUndefined
Definition: RooCmdConfig.h:106
void defineRequiredArgs(const char *argName1, const char *argName2=0, const char *argName3=0, const char *argName4=0, const char *argName5=0, const char *argName6=0, const char *argName7=0, const char *argName8=0)
Add condition that any of listed arguments must be processed for parsing to be declared successful.
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
const char * missingArgs() const
Return string with names of arguments that were required, but not processed.
void print()
Print configuration of parser.
TString _name
Definition: RooCmdConfig.h:102
Bool_t hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
RooDouble is a minimal implementation of a TObject holding a Double_t value.
Definition: RooDouble.h:22
RooInt is a minimal implementation of a TObject holding a Int_t value.
Definition: RooInt.h:22
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:36
Int_t GetSize() const
Definition: RooLinkedList.h:61
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:63
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
RooStringVar implements a string values RooAbsArg.
Definition: RooStringVar.h:23
virtual void setVal(const char *newVal)
Set value to given TString.
virtual const char * getVal() const
Return value of object. Calculated if dirty, otherwise cached value is returned.
Definition: RooStringVar.h:34
RooInt is a minimal implementation of a TNamed holding a TObject.
Definition: RooTObjWrap.h:23
TObject * obj() const
Definition: RooTObjWrap.h:32
const RooLinkedList & objList() const
Definition: RooTObjWrap.h:33
void setObj(TObject *inObj)
Definition: RooTObjWrap.h:35
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
virtual void Add(TObject *obj)
Definition: TList.h:87
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:819
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:575
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:719
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Collectable string class.
Definition: TObjString.h:28
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:144
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:375
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:705
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:401
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
const char * Data() const
Definition: TString.h:364
TString & Append(const char *cs)
Definition: TString.h:559
@ InputArguments
Definition: RooGlobalFunc.h:68
static constexpr double s
static constexpr double mm
static constexpr double pc
Definition: first.py:1