Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
43 #include "Riostream.h"
44 
45 
46 using namespace std;
47 
48 ClassImp(RooCmdConfig);
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 
58 RooCmdConfig::RooCmdConfig(const char* methodName) :
59  TObject(),
60  _name(methodName)
61 {
62  _verbose = kFALSE ;
63  _error = kFALSE ;
64  _allowUndefined = kFALSE ;
65 
66  _iIter = _iList.MakeIterator() ;
67  _dIter = _dList.MakeIterator() ;
68  _sIter = _sList.MakeIterator() ;
69  _oIter = _oList.MakeIterator() ;
70  _cIter = _cList.MakeIterator() ;
71 
72  _rIter = _rList.MakeIterator() ;
73  _fIter = _fList.MakeIterator() ;
74  _mIter = _mList.MakeIterator() ;
75  _yIter = _yList.MakeIterator() ;
76  _pIter = _pList.MakeIterator() ;
77 }
78 
79 
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Copy constructor
83 
84 RooCmdConfig::RooCmdConfig(const RooCmdConfig& other) : TObject(other)
85 {
86  _name = other._name ;
87  _verbose = other._verbose ;
88  _error = other._error ;
89  _allowUndefined = other._allowUndefined ;
90 
91  _iIter = _iList.MakeIterator() ;
92  _dIter = _dList.MakeIterator() ;
93  _sIter = _sList.MakeIterator() ;
94  _oIter = _oList.MakeIterator() ;
95  _cIter = _cList.MakeIterator() ;
96  _rIter = _rList.MakeIterator() ;
97  _fIter = _fList.MakeIterator() ;
98  _mIter = _mList.MakeIterator() ;
99  _yIter = _yList.MakeIterator() ;
100  _pIter = _pList.MakeIterator() ;
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 
169 RooCmdConfig::~RooCmdConfig()
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 
200 void RooCmdConfig::defineRequiredArgs(const char* argName1, const char* argName2,
201  const char* argName3, const char* argName4,
202  const char* argName5, const char* argName6,
203  const char* argName7, const char* argName8)
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 
221 const char* RooCmdConfig::missingArgs() const
222 {
223  static TString ret ;
224  ret="" ;
225 
226  _rIter->Reset() ;
227  TObjString* s ;
228  Bool_t first(kTRUE) ;
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 
247 void 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 
258 void 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 
271 void 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 
282 void 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 
297 void 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 
317 Bool_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 
339 Bool_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 
363 Bool_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 
388 Bool_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 
413 Bool_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 
435 void RooCmdConfig::print()
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 
477 Bool_t RooCmdConfig::process(const RooLinkedList& argList)
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 
494 Bool_t RooCmdConfig::process(const RooCmdArg& arg1, const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
495  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7, const RooCmdArg& arg8)
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 
514 Bool_t RooCmdConfig::process(const RooCmdArg& arg)
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 
680 Bool_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 
691 Int_t RooCmdConfig::getInt(const char* name, Int_t defVal)
692 {
693  RooInt* ri = (RooInt*) _iList.FindObject(name) ;
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 
703 Double_t RooCmdConfig::getDouble(const char* name, Double_t defVal)
704 {
705  RooDouble* rd = (RooDouble*) _dList.FindObject(name) ;
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 
716 const char* RooCmdConfig::getString(const char* name, const char* defVal, Bool_t convEmptyToNull)
717 {
718  RooStringVar* rs = (RooStringVar*) _sList.FindObject(name) ;
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 
728 TObject* RooCmdConfig::getObject(const char* name, TObject* defVal)
729 {
730  RooTObjWrap* ro = (RooTObjWrap*) _oList.FindObject(name) ;
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 
739 RooArgSet* RooCmdConfig::getSet(const char* name, RooArgSet* defVal)
740 {
741  RooTObjWrap* ro = (RooTObjWrap*) _cList.FindObject(name) ;
742  return ro ? ((RooArgSet*)ro->obj()) : defVal ;
743 }
744 
745 
746 
747 ////////////////////////////////////////////////////////////////////////////////
748 /// Return list of objects registered with name 'name'
749 
750 const RooLinkedList& RooCmdConfig::getObjectList(const char* name)
751 {
752  static RooLinkedList defaultDummy ;
753  RooTObjWrap* ro = (RooTObjWrap*) _oList.FindObject(name) ;
754  return ro ? ro->objList() : defaultDummy ;
755 }
756 
757 
758 
759 ////////////////////////////////////////////////////////////////////////////////
760 /// Return true of parsing was successful
761 
762 Bool_t RooCmdConfig::ok(Bool_t verbose) const
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 
782 void 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 
806 RooLinkedList 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 
835 Int_t RooCmdConfig::decodeIntOnTheFly(const char* callerID, const char* cmdArgName, Int_t intIdx, Int_t defVal, const RooCmdArg& arg1,
836  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
837  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
838  const RooCmdArg& arg8, const RooCmdArg& arg9)
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 
855 std::string RooCmdConfig::decodeStringOnTheFly(const char* callerID, const char* cmdArgName, Int_t strIdx, const char* defVal, const RooCmdArg& arg1,
856  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
857  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
858  const RooCmdArg& arg8, const RooCmdArg& arg9)
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 
880 TObject* RooCmdConfig::decodeObjOnTheFly(const char* callerID, const char* cmdArgName, Int_t objIdx, TObject* defVal, const RooCmdArg& arg1,
881  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
882  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
883  const RooCmdArg& arg8, const RooCmdArg& arg9)
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 }