ROOT  6.06/09
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 //
20 // BEGIN_HTML
21 // Class RooCmdConfig is a configurable parser for RooCmdArg named
22 // arguments. It maps the contents of named arguments named to integers,
23 // doubles, strings and TObjects that can be retrieved after processing
24 // a set of RooCmdArgs. The parser also has options to enforce syntax
25 // rules such as (conditionally) required arguments, mutually exclusive
26 // arguments and dependencies between arguments
27 // END_HTML
28 //
29 
30 #include "RooFit.h"
31 
32 #include "RooCmdConfig.h"
33 #include "RooInt.h"
34 #include "RooDouble.h"
35 #include "RooArgSet.h"
36 #include "RooStringVar.h"
37 #include "RooTObjWrap.h"
38 #include "RooAbsData.h"
39 #include "TObjString.h"
40 #include "RooMsgService.h"
41 
42 #include "Riostream.h"
43 
44 
45 using namespace std;
46 
48  ;
49 
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 = _rList.FindObject(opc) ;
649  if (obj) {
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 {
704  RooDouble* rd = (RooDouble*) _dList.FindObject(name) ;
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 {
717  RooStringVar* rs = (RooStringVar*) _sList.FindObject(name) ;
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 {
729  RooTObjWrap* ro = (RooTObjWrap*) _oList.FindObject(name) ;
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 {
740  RooTObjWrap* ro = (RooTObjWrap*) _cList.FindObject(name) ;
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 ;
752  RooTObjWrap* ro = (RooTObjWrap*) _oList.FindObject(name) ;
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 const char* 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  static string retBuf = "" ;
860 
861  RooCmdConfig pc(callerID) ;
862  pc.allowUndefined() ;
863  pc.defineString("theString",cmdArgName,strIdx,defVal) ;
864  pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
865  pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
866  pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
867  const char* ret = pc.getString("theString",0,kTRUE) ;
868 
869  if (ret) {
870  retBuf = ret ;
871  } else {
872  retBuf.clear() ;
873  }
874  return retBuf.c_str() ;
875 }
876 
877 
878 
879 ////////////////////////////////////////////////////////////////////////////////
880 /// Static decoder function allows to retrieve object property from set of RooCmdArgs
881 /// For use in base member initializers in constructors
882 
883 TObject* RooCmdConfig::decodeObjOnTheFly(const char* callerID, const char* cmdArgName, Int_t objIdx, TObject* defVal, const RooCmdArg& arg1,
884  const RooCmdArg& arg2, const RooCmdArg& arg3, const RooCmdArg& arg4,
885  const RooCmdArg& arg5, const RooCmdArg& arg6, const RooCmdArg& arg7,
886  const RooCmdArg& arg8, const RooCmdArg& arg9)
887 {
888  RooCmdConfig pc(callerID) ;
889  pc.allowUndefined() ;
890  pc.defineObject("theObj",cmdArgName,objIdx,defVal) ;
891  pc.process(arg1) ; pc.process(arg2) ; pc.process(arg3) ;
892  pc.process(arg4) ; pc.process(arg5) ; pc.process(arg6) ;
893  pc.process(arg7) ; pc.process(arg8) ; pc.process(arg9) ;
894  return (TObject*) pc.getObject("theObj") ;
895 }
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:265
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
TIterator * _dIter
Definition: RooCmdConfig.h:121
ClassImp(RooCmdConfig)
#define coutE(a)
Definition: RooMsgService.h:35
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:404
Bool_t hasProcessed(const char *cmdName) const
Return true if RooCmdArg with name 'cmdName' has been processed.
virtual void Reset()=0
RooCmdConfig(const char *methodName)
Constructor taking descriptive name of owner/user which is used as prefix for any warning or error me...
TIterator * _iIter
Definition: RooCmdConfig.h:120
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...
Ssiz_t Length() const
Definition: TString.h:390
Collectable string class.
Definition: TObjString.h:32
virtual Bool_t Remove(TObject *arg)
Remove object from collection.
static const char * 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...
const char * getString(const char *name, const char *defaultValue="", Bool_t convEmptyToNull=kFALSE)
Return string property registered with name 'name'.
virtual void SetName(const char *name)
Change (i.e.
Definition: TNamed.cxx:128
virtual void setVal(const char *newVal)
Set value to given TString.
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...
const char * opcode() const
Definition: RooCmdArg.h:61
const char * getString(Int_t idx) const
Definition: RooCmdArg.h:88
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 ...
TIterator * _mIter
Definition: RooCmdConfig.h:127
Basic string class.
Definition: TString.h:137
Definition: RooInt.h:22
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:496
void allowUndefined(Bool_t flag=kTRUE)
Definition: RooCmdConfig.h:39
STL namespace.
TObject * getObject(const char *name, TObject *obj=0)
Return TObject property registered with name 'name'.
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:288
Iterator abstract base class.
Definition: TIterator.h:32
Double_t getDouble(Int_t idx) const
Definition: RooCmdArg.h:84
~RooCmdConfig()
Destructor.
void setObj(TObject *inObj)
Definition: RooTObjWrap.h:35
RooLinkedList _argList
Definition: RooCmdArg.h:115
TIterator * _oIter
Definition: RooCmdConfig.h:123
Bool_t _verbose
Definition: RooCmdConfig.h:104
const char * Data() const
Definition: TString.h:349
Bool_t process(const RooCmdArg &arg)
Process given RooCmdArg.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TObject.cxx:203
const char * missingArgs() const
Return string with names of arguments that were required, but not processed.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
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...
TString & Append(const char *cs)
Definition: TString.h:492
Int_t getInt(Int_t idx) const
Definition: RooCmdArg.h:80
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition: TNamed.cxx:63
void defineDependency(const char *refArgName, const char *neededArgName)
Define that processing argument name refArgName requires processing of argument named neededArgName t...
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...
void stripCmdList(RooLinkedList &cmdList, const char *cmdsToPurge)
Utility function that strips command names listed (comma separated) in cmdsToPurge from cmdList...
virtual void SetUniqueID(UInt_t uid)
Set the unique object id.
Definition: TObject.cxx:743
virtual void Add(TObject *arg)
Definition: RooLinkedList.h:62
void defineMutex(const char *argName1, const char *argName2)
Define arguments named argName1 and argName2 mutually exclusive.
Int_t getInt(const char *name, Int_t defaultValue=0)
Return integer property registered with name 'name'.
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...
TIterator * _pIter
Definition: RooCmdConfig.h:129
TObject * obj() const
Definition: RooTObjWrap.h:32
return
Definition: TBase64.cxx:62
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Definition: TList.cxx:674
TIterator * _rIter
Definition: RooCmdConfig.h:125
bool verbose
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
Bool_t ok(Bool_t verbose) const
Return true of parsing was successful.
TString & String()
Definition: TObjString.h:52
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...
virtual const char * getVal() const
Return value of object. Calculated if dirty, otherwise cached value is returned.
Definition: RooStringVar.h:35
RooArgSet * getSet(const char *name, RooArgSet *set=0)
Return RooArgSet property registered with name 'name'.
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
double Double_t
Definition: RtypesCore.h:55
Bool_t _prefixSubArgs
Definition: RooCmdArg.h:116
Bool_t _allowUndefined
Definition: RooCmdConfig.h:106
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
Definition: RooAbsArg.h:75
Double_t getDouble(const char *name, Double_t defaultValue=0)
Return Double_t property registered with name 'name'.
TIterator * _sIter
Definition: RooCmdConfig.h:122
TIterator * _fIter
Definition: RooCmdConfig.h:126
const TObject * getObject(Int_t idx) const
Definition: RooCmdArg.h:92
TObject * At(Int_t index) const
Return object stored in sequential position given by index.
void print()
Print configuration of parser.
const RooLinkedList & getObjectList(const char *name)
Return list of objects registered with name 'name'.
virtual UInt_t GetUniqueID() const
Return the unique object id.
Definition: TObject.cxx:433
#define name(a, b)
Definition: linkTestLib0.cpp:5
TIterator * _cIter
Definition: RooCmdConfig.h:124
Mother of all ROOT objects.
Definition: TObject.h:58
const RooArgSet * getSet(Int_t idx) const
Return RooArgSet stored in slot idx.
Definition: RooCmdArg.cxx:197
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual TObject * Next()=0
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
Definition: TList.cxx:603
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 ...
Int_t GetSize() const
Definition: RooLinkedList.h:60
const RooLinkedList & objList() const
Definition: RooTObjWrap.h:33
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:459
virtual void SetTitle(const char *title="")
Change (i.e. set) the title of the TNamed.
Definition: TNamed.cxx:152
TObject * obj
RooLinkedList filterCmdList(RooLinkedList &cmdInList, const char *cmdNameList, Bool_t removeFromInList=kTRUE)
Utility function to filter commands listed in cmdNameList from cmdInList.
Bool_t _procSubArgs
Definition: RooCmdArg.h:113
TIterator * _yIter
Definition: RooCmdConfig.h:128
TString _name
Definition: RooCmdConfig.h:102
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:385