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