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 
23 Class RooCmdConfig is a configurable parser for RooCmdArg named
24 arguments. It maps the contents of named arguments named to integers,
25 doubles, strings and TObjects that can be retrieved after processing
26 a set of RooCmdArgs. The parser also has options to enforce syntax
27 rules such as (conditionally) required arguments, mutually exclusive
28 arguments 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 
47 using 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 
57 RooCmdConfig::RooCmdConfig(const char* methodName) :
58  TObject(),
59  _name(methodName)
60 {
61  _verbose = kFALSE ;
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 
199 void 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 
220 const char* RooCmdConfig::missingArgs() const
221 {
222  static TString ret ;
223  ret="" ;
224 
225  _rIter->Reset() ;
226  TObjString* s ;
227  Bool_t first(kTRUE) ;
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 
246 void 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 
257 void 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 
270 void 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 
281 void 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 
296 void 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 
316 Bool_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 
338 Bool_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 
362 Bool_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 
387 Bool_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 
412 Bool_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  TIterator* iter = argList.MakeIterator() ;
480  RooCmdArg* arg ;
481  while((arg=(RooCmdArg*)iter->Next())) {
482  ret |= process(*arg) ;
483  }
484  delete iter ;
485  return ret ;
486 }
487 
488 
489 
490 ////////////////////////////////////////////////////////////////////////////////
491 /// Process given RooCmdArgs
492 
493 Bool_t RooCmdConfig::process(const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
494  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
495 {
496  Bool_t ret(kFALSE) ;
497  ret |= process(arg1) ;
498  ret |= process(arg2) ;
499  ret |= process(arg3) ;
500  ret |= process(arg4) ;
501  ret |= process(arg5) ;
502  ret |= process(arg6) ;
503  ret |= process(arg7) ;
504  ret |= process(arg8) ;
505  return ret ;
506 }
507 
508 
509 
510 ////////////////////////////////////////////////////////////////////////////////
511 /// Process given RooCmdArg
512 
514 {
515  // Retrive command code
516  const char* opc = arg.opcode() ;
517 
518  // Ignore empty commands
519  if (!opc) return kFALSE ;
520 
521  // Check if not forbidden
522  if (_fList.FindObject(opc)) {
523  coutE(InputArguments) << _name << " ERROR: argument " << opc << " not allowed in this context" << endl ;
524  _error = kTRUE ;
525  return kTRUE ;
526  }
527 
528  // Check if this code generates any dependencies
529  TObject* dep = _yList.FindObject(opc) ;
530  if (dep) {
531  // Dependent command found, add to required list if not already processed
532  if (!_pList.FindObject(dep->GetTitle())) {
533  _rList.Add(new TObjString(dep->GetTitle())) ;
534  if (_verbose) {
535  cout << "RooCmdConfig::process: " << opc << " has unprocessed dependent " << dep->GetTitle()
536  << ", adding to required list" << endl ;
537  }
538  } else {
539  if (_verbose) {
540  cout << "RooCmdConfig::process: " << opc << " dependent " << dep->GetTitle() << " is already processed" << endl ;
541  }
542  }
543  }
544 
545  // Check for mutexes
546  TObject * mutex = _mList.FindObject(opc) ;
547  if (mutex) {
548  if (_verbose) {
549  cout << "RooCmdConfig::process: " << opc << " excludes " << mutex->GetTitle()
550  << ", adding to forbidden list" << endl ;
551  }
552  _fList.Add(new TObjString(mutex->GetTitle())) ;
553  }
554 
555 
556  Bool_t anyField(kFALSE) ;
557 
558  // Find registered integer fields for this opcode
559  _iIter->Reset() ;
560  RooInt* ri ;
561  while((ri=(RooInt*)_iIter->Next())) {
562  if (!TString(opc).CompareTo(ri->GetTitle())) {
563  *ri = arg.getInt(ri->GetUniqueID()) ;
564  anyField = kTRUE ;
565  if (_verbose) {
566  cout << "RooCmdConfig::process " << ri->GetName() << "[Int_t]" << " set to " << *ri << endl ;
567  }
568  }
569  }
570 
571  // Find registered double fields for this opcode
572  _dIter->Reset() ;
573  RooDouble* rd ;
574  while((rd=(RooDouble*)_dIter->Next())) {
575  if (!TString(opc).CompareTo(rd->GetTitle())) {
576  *rd = arg.getDouble(rd->GetUniqueID()) ;
577  anyField = kTRUE ;
578  if (_verbose) {
579  cout << "RooCmdConfig::process " << rd->GetName() << "[Double_t]" << " set to " << *rd << endl ;
580  }
581  }
582  }
583 
584  // Find registered string fields for this opcode
585  _sIter->Reset() ;
586  RooStringVar* rs ;
587  while((rs=(RooStringVar*)_sIter->Next())) {
588  if (!TString(opc).CompareTo(rs->GetTitle())) {
589 
590  const char* oldStr = rs->getVal() ;
591 
592  if (oldStr && strlen(oldStr)>0 && rs->getAttribute("RooCmdConfig::AppendMode")) {
593  rs->setVal(Form("%s,%s",rs->getVal(),arg.getString(rs->GetUniqueID()))) ;
594  } else {
595  rs->setVal(arg.getString(rs->GetUniqueID())) ;
596  }
597  anyField = kTRUE ;
598  if (_verbose) {
599  cout << "RooCmdConfig::process " << rs->GetName() << "[string]" << " set to " << rs->getVal() << endl ;
600  }
601  }
602  }
603 
604  // Find registered TObject fields for this opcode
605  _oIter->Reset() ;
606  RooTObjWrap* os ;
607  while((os=(RooTObjWrap*)_oIter->Next())) {
608  if (!TString(opc).CompareTo(os->GetTitle())) {
609  os->setObj((TObject*)arg.getObject(os->GetUniqueID())) ;
610  anyField = kTRUE ;
611  if (_verbose) {
612  cout << "RooCmdConfig::process " << os->GetName() << "[TObject]" << " set to " ;
613  if (os->obj()) {
614  cout << os->obj()->GetName() << endl ;
615  } else {
616  cout << "(null)" << endl ;
617  }
618  }
619  }
620  }
621 
622  // Find registered RooArgSet fields for this opcode
623  _cIter->Reset() ;
624  RooTObjWrap* cs ;
625  while((cs=(RooTObjWrap*)_cIter->Next())) {
626  if (!TString(opc).CompareTo(cs->GetTitle())) {
627  cs->setObj((TObject*)arg.getSet(cs->GetUniqueID())) ;
628  anyField = kTRUE ;
629  if (_verbose) {
630  cout << "RooCmdConfig::process " << cs->GetName() << "[RooArgSet]" << " set to " ;
631  if (cs->obj()) {
632  cout << cs->obj()->GetName() << endl ;
633  } else {
634  cout << "(null)" << endl ;
635  }
636  }
637  }
638  }
639 
640  Bool_t multiArg = !TString("MultiArg").CompareTo(opc) ;
641 
642  if (!anyField && !_allowUndefined && !multiArg) {
643  coutE(InputArguments) << _name << " ERROR: unrecognized command: " << opc << endl ;
644  }
645 
646 
647  // Remove command from required-args list (if it was there)
648  TObject* obj;
649  while ( (obj = _rList.FindObject(opc)) ) {
650  _rList.Remove(obj);
651  }
652 
653  // Add command the processed list
654  TNamed *pcmd = new TNamed(opc,opc) ;
655  _pList.Add(pcmd) ;
656 
657  Bool_t depRet = kFALSE ;
658  if (arg._procSubArgs) {
659  for (Int_t ia=0 ; ia<arg._argList.GetSize() ; ia++) {
660  RooCmdArg* subArg = static_cast<RooCmdArg*>(arg._argList.At(ia)) ;
661  if (strlen(subArg->GetName())>0) {
662  RooCmdArg subArgCopy(*subArg) ;
663  if (arg._prefixSubArgs) {
664  subArgCopy.SetName(Form("%s::%s",arg.GetName(),subArg->GetName())) ;
665  }
666  depRet |= process(subArgCopy) ;
667  }
668  }
669  }
670 
671  return ((anyField||_allowUndefined)?kFALSE:kTRUE)||depRet ;
672 }
673 
674 
675 
676 ////////////////////////////////////////////////////////////////////////////////
677 /// Return true if RooCmdArg with name 'cmdName' has been processed
678 
679 Bool_t RooCmdConfig::hasProcessed(const char* cmdName) const
680 {
681  return _pList.FindObject(cmdName) ? kTRUE : kFALSE ;
682 }
683 
684 
685 
686 ////////////////////////////////////////////////////////////////////////////////
687 /// Return integer property registered with name 'name'. If no
688 /// property is registered, return defVal
689 
690 Int_t RooCmdConfig::getInt(const char* name, Int_t defVal)
691 {
692  RooInt* ri = (RooInt*) _iList.FindObject(name) ;
693  return ri ? (Int_t)(*ri) : defVal ;
694 }
695 
696 
697 
698 ////////////////////////////////////////////////////////////////////////////////
699 /// Return Double_t property registered with name 'name'. If no
700 /// property is registered, return defVal
701 
703 {
705  return rd ? (Double_t)(*rd) : defVal ;
706 }
707 
708 
709 
710 ////////////////////////////////////////////////////////////////////////////////
711 /// Return string property registered with name 'name'. If no
712 /// property is registered, return defVal. If convEmptyToNull
713 /// is true, empty string will be returned as null pointers
714 
715 const char* RooCmdConfig::getString(const char* name, const char* defVal, Bool_t convEmptyToNull)
716 {
718  return rs ? ((convEmptyToNull && strlen(rs->getVal())==0) ? 0 : ((const char*)rs->getVal()) ) : defVal ;
719 }
720 
721 
722 
723 ////////////////////////////////////////////////////////////////////////////////
724 /// Return TObject property registered with name 'name'. If no
725 /// property is registered, return defVal
726 
728 {
730  return ro ? ro->obj() : defVal ;
731 }
732 
733 
734 ////////////////////////////////////////////////////////////////////////////////
735 /// Return RooArgSet property registered with name 'name'. If no
736 /// property is registered, return defVal
737 
739 {
741  return ro ? ((RooArgSet*)ro->obj()) : defVal ;
742 }
743 
744 
745 
746 ////////////////////////////////////////////////////////////////////////////////
747 /// Return list of objects registered with name 'name'
748 
750 {
751  static RooLinkedList defaultDummy ;
753  return ro ? ro->objList() : defaultDummy ;
754 }
755 
756 
757 
758 ////////////////////////////////////////////////////////////////////////////////
759 /// Return true of parsing was successful
760 
762 {
763  if (_rList.GetSize()==0 && !_error) return kTRUE ;
764 
765  if (verbose) {
766  const char* margs = missingArgs() ;
767  if (margs) {
768  coutE(InputArguments) << _name << " ERROR: missing arguments: " << margs << endl ;
769  } else {
770  coutE(InputArguments) << _name << " ERROR: illegal combination of arguments and/or missing arguments" << endl ;
771  }
772  }
773  return kFALSE ;
774 }
775 
776 
777 
778 ////////////////////////////////////////////////////////////////////////////////
779 /// Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList
780 
781 void RooCmdConfig::stripCmdList(RooLinkedList& cmdList, const char* cmdsToPurge)
782 {
783  // Sanity check
784  if (!cmdsToPurge) return ;
785 
786  // Copy command list for parsing
787  char buf[1024] ;
788  strlcpy(buf,cmdsToPurge,1024) ;
789 
790  char* name = strtok(buf,",") ;
791  while(name) {
792  TObject* cmd = cmdList.FindObject(name) ;
793  if (cmd) cmdList.Remove(cmd) ;
794  name = strtok(0,",") ;
795  }
796 
797 }
798 
799 
800 
801 ////////////////////////////////////////////////////////////////////////////////
802 /// Utility function to filter commands listed in cmdNameList from cmdInList. Filtered arguments are put in the returned list.
803 /// If removeFromInList is true then these commands are removed from the input list
804 
805 RooLinkedList RooCmdConfig::filterCmdList(RooLinkedList& cmdInList, const char* cmdNameList, Bool_t removeFromInList)
806 {
807  RooLinkedList filterList ;
808  if (!cmdNameList) return filterList ;
809 
810  // Copy command list for parsing
811  char buf[1024] ;
812  strlcpy(buf,cmdNameList,1024) ;
813 
814  char* name = strtok(buf,",") ;
815  while(name) {
816  TObject* cmd = cmdInList.FindObject(name) ;
817  if (cmd) {
818  if (removeFromInList) {
819  cmdInList.Remove(cmd) ;
820  }
821  filterList.Add(cmd) ;
822  }
823  name = strtok(0,",") ;
824  }
825  return filterList ;
826 }
827 
828 
829 
830 ////////////////////////////////////////////////////////////////////////////////
831 /// Static decoder function allows to retrieve integer property from set of RooCmdArgs
832 /// For use in base member initializers in constructors
833 
834 Int_t RooCmdConfig::decodeIntOnTheFly(const char* callerID, const char* cmdArgName, Int_t intIdx, Int_t defVal, const RooCmdArg& arg1,
835  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
836  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
837  const RooCmdArg& arg8, const RooCmdArg& arg9)
838 {
839  RooCmdConfig pc(callerID) ;
840  pc.allowUndefined() ;
841  pc.defineInt("theInt",cmdArgName,intIdx,defVal) ;
842  pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
843  pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
844  pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
845  return pc.getInt("theInt") ;
846 }
847 
848 
849 
850 ////////////////////////////////////////////////////////////////////////////////
851 /// Static decoder function allows to retrieve string property from set of RooCmdArgs
852 /// For use in base member initializers in constructors
853 
854 std::string RooCmdConfig::decodeStringOnTheFly(const char* callerID, const char* cmdArgName, Int_t strIdx, const char* defVal, const RooCmdArg& arg1,
855  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
856  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
857  const RooCmdArg& arg8, const RooCmdArg& arg9)
858 {
859  RooCmdConfig pc(callerID) ;
860  pc.allowUndefined() ;
861  pc.defineString("theString",cmdArgName,strIdx,defVal) ;
862  pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
863  pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
864  pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
865  const char* ret = pc.getString("theString",0,kTRUE) ;
866 
867  if (ret)
868  return std::string(ret);
869 
870  return std::string();
871 }
872 
873 
874 
875 ////////////////////////////////////////////////////////////////////////////////
876 /// Static decoder function allows to retrieve object property from set of RooCmdArgs
877 /// For use in base member initializers in constructors
878 
879 TObject* RooCmdConfig::decodeObjOnTheFly(const char* callerID, const char* cmdArgName, Int_t objIdx, TObject* defVal, const RooCmdArg& arg1,
880  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
881  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
882  const RooCmdArg& arg8, const RooCmdArg& arg9)
883 {
884  RooCmdConfig pc(callerID) ;
885  pc.allowUndefined() ;
886  pc.defineObject("theObj",cmdArgName,objIdx,defVal) ;
887  pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
888  pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
889  pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
890  return (TObject*) pc.getObject("theObj") ;
891 }
RooAbsArg::Clone
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:85
RooCmdConfig::print
void print()
Print configuration of parser.
Definition: RooCmdConfig.cxx:434
RooLinkedList::MakeIterator
TIterator * MakeIterator(Bool_t forward=kTRUE) const
Create a TIterator for this list.
Definition: RooLinkedList.cxx:747
RooCmdArg
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
first
Definition: first.py:1
RooCmdArg::_argList
RooLinkedList _argList
Definition: RooCmdArg.h:117
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooCmdConfig.h
RooStringVar.h
RooStringVar::getVal
const char * getVal() const
Definition: RooStringVar.h:34
RooCmdConfig::_yIter
TIterator * _yIter
Definition: RooCmdConfig.h:128
RooCmdArg::getSet
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:200
RooCmdConfig::hasProcessed
Bool_t hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
Definition: RooCmdConfig.cxx:679
RooMsgService.h
RooCmdArg::getInt
Int_t getInt(Int_t idx) const
Definition: RooCmdArg.h:80
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
RooCmdConfig::_oIter
TIterator * _oIter
Definition: RooCmdConfig.h:123
RooFit.h
RooFit::InputArguments
@ InputArguments
Definition: RooGlobalFunc.h:68
RooArgSet.h
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:469
TString::Data
const char * Data() const
Definition: TString.h:369
RooTObjWrap::setObj
void setObj(TObject *inObj)
Definition: RooTObjWrap.h:35
RooTObjWrap.h
RooCmdConfig::defineObject
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 ...
Definition: RooCmdConfig.cxx:387
RooCmdArg::getObject
const TObject * getObject(Int_t idx) const
Definition: RooCmdArg.h:92
RooCmdConfig::_error
Bool_t _error
Definition: RooCmdConfig.h:105
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
Form
char * Form(const char *fmt,...)
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
TObjString.h
RooCmdConfig::_verbose
Bool_t _verbose
Definition: RooCmdConfig.h:104
RooCmdConfig::process
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
Definition: RooCmdConfig.cxx:513
RooCmdConfig::_rList
TList _rList
Definition: RooCmdConfig.h:114
RooLinkedList::GetSize
Int_t GetSize() const
Definition: RooLinkedList.h:60
RooCmdConfig::_name
TString _name
Definition: RooCmdConfig.h:102
RooCmdConfig::_dIter
TIterator * _dIter
Definition: RooCmdConfig.h:121
coutE
#define coutE(a)
Definition: RooMsgService.h:33
RooCmdConfig::filterCmdList
RooLinkedList filterCmdList(RooLinkedList &cmdInList, const char *cmdNameList, Bool_t removeFromInList=kTRUE)
Utility function to filter commands listed in cmdNameList from cmdInList.
Definition: RooCmdConfig.cxx:805
RooCmdArg::_procSubArgs
Bool_t _procSubArgs
Definition: RooCmdArg.h:115
RooTObjWrap
RooInt is a minimal implementation of a TNamed holding a TObject.
Definition: RooTObjWrap.h:23
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
RooLinkedList::At
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
Definition: RooLinkedList.cxx:496
Int_t
int Int_t
Definition: RtypesCore.h:45
TObject::GetUniqueID
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:377
RooCmdConfig::RooCmdConfig
RooCmdConfig(const char *methodName)
Constructor taking descriptive name of owner/user which is used as prefix for any warning or error me...
Definition: RooCmdConfig.cxx:57
RooCmdConfig::defineDouble
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...
Definition: RooCmdConfig.cxx:338
TGeant4Unit::pc
static constexpr double pc
Definition: TGeant4SystemOfUnits.h:130
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
RooCmdArg::_prefixSubArgs
Bool_t _prefixSubArgs
Definition: RooCmdArg.h:118
RooCmdConfig::defineRequiredArgs
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.
Definition: RooCmdConfig.cxx:199
RooCmdArg::getString
const char * getString(Int_t idx) const
Definition: RooCmdArg.h:88
RooCmdConfig::defineSet
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 ...
Definition: RooCmdConfig.cxx:412
RooCmdConfig::_sList
TList _sList
Definition: RooCmdConfig.h:110
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
RooCmdArg::getDouble
Double_t getDouble(Int_t idx) const
Definition: RooCmdArg.h:84
RooCmdConfig::_mList
TList _mList
Definition: RooCmdConfig.h:116
RooCmdConfig::_rIter
TIterator * _rIter
Definition: RooCmdConfig.h:125
TString
Basic string class.
Definition: TString.h:136
RooLinkedList::FindObject
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
Definition: RooLinkedList.cxx:539
RooCmdConfig::getString
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name 'name'.
Definition: RooCmdConfig.cxx:715
RooCmdConfig::_mIter
TIterator * _mIter
Definition: RooCmdConfig.h:127
RooTObjWrap::obj
TObject * obj() const
Definition: RooTObjWrap.h:32
bool
TIterator
Iterator abstract base class.
Definition: TIterator.h:30
RooCmdConfig::defineMutex
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Definition: RooCmdConfig.cxx:257
RooInt
RooInt is a minimal implementation of a TObject holding a Int_t value.
Definition: RooInt.h:22
RooCmdConfig::getInt
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
Definition: RooCmdConfig.cxx:690
RooCmdConfig::_pIter
TIterator * _pIter
Definition: RooCmdConfig.h:129
RooCmdConfig::~RooCmdConfig
~RooCmdConfig()
Destructor.
Definition: RooCmdConfig.cxx:168
RooCmdConfig
Class RooCmdConfig is a configurable parser for RooCmdArg named arguments.
Definition: RooCmdConfig.h:27
RooCmdConfig::_cList
TList _cList
Definition: RooCmdConfig.h:112
TObjString
Collectable string class.
Definition: TObjString.h:28
RooTObjWrap::objList
const RooLinkedList & objList() const
Definition: RooTObjWrap.h:33
TList::MakeIterator
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:721
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
RooCmdConfig::_pList
TList _pList
Definition: RooCmdConfig.h:118
RooCmdConfig::decodeObjOnTheFly
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...
Definition: RooCmdConfig.cxx:879
RooDouble
RooDouble is a minimal implementation of a TObject holding a Double_t value.
Definition: RooDouble.h:22
RooCmdConfig::getSet
RooArgSet * getSet(const char *name, RooArgSet *set=0)
Return RooArgSet property registered with name 'name'.
Definition: RooCmdConfig.cxx:738
RooCmdConfig::_fIter
TIterator * _fIter
Definition: RooCmdConfig.h:126
RooCmdConfig::getObject
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name 'name'.
Definition: RooCmdConfig.cxx:727
RooStringVar::setVal
void setVal(const char *newVal)
Definition: RooStringVar.h:35
RooCmdConfig::_oList
TList _oList
Definition: RooCmdConfig.h:111
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TString::Append
TString & Append(const char *cs)
Definition: TString.h:564
TNamed::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:74
RooLinkedList
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
RooCmdConfig::stripCmdList
void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList.
Definition: RooCmdConfig.cxx:781
RooCmdConfig::getObjectList
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
Definition: RooCmdConfig.cxx:749
TObject::Clone
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:146
RooCmdConfig::_fList
TList _fList
Definition: RooCmdConfig.h:115
RooCmdConfig::defineString
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...
Definition: RooCmdConfig.cxx:362
RooLinkedList::Add
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
RooCmdConfig::_allowUndefined
Bool_t _allowUndefined
Definition: RooCmdConfig.h:106
RooCmdConfig::_yList
TList _yList
Definition: RooCmdConfig.h:117
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TGeant4Unit::mm
static constexpr double mm
Definition: TGeant4SystemOfUnits.h:108
RooCmdConfig::defineDependency
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
Definition: RooCmdConfig.cxx:246
TIterator::Next
virtual TObject * Next()=0
RooCmdConfig::_iList
TList _iList
Definition: RooCmdConfig.h:108
TIterator::Reset
virtual void Reset()=0
RooCmdConfig::defineInt
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...
Definition: RooCmdConfig.cxx:316
RooCmdConfig::_dList
TList _dList
Definition: RooCmdConfig.h:109
TString::CompareTo
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
RooCmdConfig::decodeStringOnTheFly
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...
Definition: RooCmdConfig.cxx:854
RooAbsData.h
Double_t
double Double_t
Definition: RtypesCore.h:59
RooStringVar
RooStringVar is a RooAbsArg implementing string values.
Definition: RooStringVar.h:23
TList::Remove
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:821
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
RooInt.h
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
RooAbsArg::setAttribute
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:259
RooCmdConfig::decodeIntOnTheFly
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...
Definition: RooCmdConfig.cxx:834
name
char name[80]
Definition: TGX11.cxx:110
RooCmdConfig::ok
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
Definition: RooCmdConfig.cxx:761
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooDouble.h
RooCmdArg::opcode
const char * opcode() const
Definition: RooCmdArg.h:61
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
RooCmdConfig::getDouble
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name 'name'.
Definition: RooCmdConfig.cxx:702
RooCmdConfig::missingArgs
const char * missingArgs() const
Return string with names of arguments that were required, but not processed.
Definition: RooCmdConfig.cxx:220
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
TObject::SetUniqueID
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:707
RooLinkedList::Remove
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
Definition: RooLinkedList.cxx:455
int
RooCmdConfig::_iIter
TIterator * _iIter
Definition: RooCmdConfig.h:120
RooAbsArg::getAttribute
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:282
RooCmdConfig::_sIter
TIterator * _sIter
Definition: RooCmdConfig.h:122
RooCmdConfig::_cIter
TIterator * _cIter
Definition: RooCmdConfig.h:124