Logo ROOT   6.18/05
Reference Guide
RooArgSet.cxx
Go to the documentation of this file.
1/***************************************************************************** * Project: RooFit *
2 * Package: RooFitCore *
3 * @(#)root/roofitcore:$Id$
4 * Authors: *
5 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
6 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
7 * *
8 * Copyright (c) 2000-2005, Regents of the University of California *
9 * and Stanford University. All rights reserved. *
10 * *
11 * Redistribution and use in source and binary forms, *
12 * with or without modification, are permitted according to the terms *
13 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
14 *****************************************************************************/
15
16//////////////////////////////////////////////////////////////////////////////
17/// \class RooArgSet
18/// RooArgSet is a container object that can hold multiple RooAbsArg objects.
19/// The container has set semantics which means that:
20///
21/// - Every object it contains must have a unique name returned by GetName().
22///
23/// - Contained objects are not ordered, although the set can be traversed
24/// using an iterator returned by createIterator(). The iterator does not
25/// necessarily follow the object insertion order.
26///
27/// - Objects can be retrieved by name only, and not by index.
28///
29///
30/// Ownership of contents
31/// -------------------------
32/// Unowned objects are inserted with the add() method. Owned objects
33/// are added with addOwned() or addClone(). A RooArgSet either owns all
34/// of it contents, or none, which is determined by the first `add`
35/// call. Once an ownership status is selected, inappropriate `add` calls
36/// will return error status. Clearing the list via removeAll() resets the
37/// ownership status. Arguments supplied in the constructor are always added
38/// as unowned elements.
39///
40///
41
42#include "RooArgSet.h"
43
44#include "Riostream.h"
45#include "TClass.h"
46#include "RooErrorHandler.h"
47#include "RooStreamParser.h"
48#include "RooFormula.h"
49#include "RooAbsRealLValue.h"
51#include "RooStringVar.h"
52#include "RooTrace.h"
53#include "RooArgList.h"
54#include "RooSentinel.h"
55#include "RooMsgService.h"
56#include "ROOT/RMakeUnique.hxx"
57
58#include <iomanip>
59
60using namespace std ;
61
62#if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3)
63char* operator+( streampos&, char* );
64#endif
65
67
68
69
70#ifndef USEMEMPOOLFORARGSET
72#else
73
74#include "MemPoolForRooSets.h"
75
78 static auto * memPool = new RooArgSet::MemPool();
79 return memPool;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Clear memory pool on exit to avoid reported memory leaks
84
86{
87 auto pool = memPool();
88 memPool()->teardown();
89
90 //Here, the pool might have to leak if RooArgSets are still alive.
91 if (pool->empty())
92 delete pool;
93}
94
95
96////////////////////////////////////////////////////////////////////////////////
97/// Overloaded new operator guarantees that all RooArgSets allocated with new
98/// have a unique address, a property that is exploited in several places
99/// in roofit to quickly index contents on normalization set pointers.
100/// The memory pool only allocates space for the class itself. The elements
101/// stored in the set are stored outside the pool.
102
103void* RooArgSet::operator new (size_t bytes)
104{
105 //This will fail if a derived class uses this operator
106 assert(sizeof(RooArgSet) == bytes);
107
108 return memPool()->allocate(bytes);
109}
110
111
112////////////////////////////////////////////////////////////////////////////////
113/// Overloaded new operator with placement does not guarante that all
114/// RooArgSets allocated with new have a unique address, but uses the global
115/// operator.
116
117void* RooArgSet::operator new (size_t bytes, void* ptr) noexcept
118{
119 return ::operator new (bytes, ptr);
120}
121
122
123////////////////////////////////////////////////////////////////////////////////
124/// Memory is owned by pool, we need to do nothing to release it
125
126void RooArgSet::operator delete (void* ptr)
127{
128 // Decrease use count in pool that ptr is on
129 if (memPool()->deallocate(ptr))
130 return;
131
132 std::cerr << __func__ << " " << ptr << " is not in any of the pools." << std::endl;
133
134 // Not part of any pool; use global op delete:
135 ::operator delete(ptr);
136}
137
138#endif
139
140
141////////////////////////////////////////////////////////////////////////////////
142/// Default constructor
143
146{
148}
149
150
151
152////////////////////////////////////////////////////////////////////////////////
153/// Constructor from a RooArgList. If the list contains multiple
154/// objects with the same name, only the first is store in the set.
155/// Warning messages will be printed for dropped items.
156
159{
160 add(list,kTRUE) ; // verbose to catch duplicate errors
162}
163
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Constructor from a RooArgList. If the list contains multiple
168/// objects with the same name, only the first is store in the set.
169/// Warning messages will be printed for dropped items.
170
171RooArgSet::RooArgSet(const RooArgList& list, const RooAbsArg* var1) :
173{
174 if (var1 && !list.contains(*var1)) {
175 add(*var1,kTRUE) ;
176 }
177 add(list,kTRUE) ; // verbose to catch duplicate errors
179}
180
181
182
183////////////////////////////////////////////////////////////////////////////////
184/// Empty set constructor
185
188{
190}
191
192
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Construct a set from two existing sets
197
198RooArgSet::RooArgSet(const RooArgSet& set1, const RooArgSet& set2, const char *name) : RooAbsCollection(name)
199{
200 add(set1) ;
201 add(set2) ;
203}
204
205
206
207
208////////////////////////////////////////////////////////////////////////////////
209/// Constructor for set containing 1 initial object
210
212 const char *name) :
214{
215 add(var1);
217}
218
219
220
221////////////////////////////////////////////////////////////////////////////////
222/// Constructor for set containing 2 initial objects
223
224RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
225 const char *name) :
227{
228 add(var1); add(var2);
230}
231
232
233
234////////////////////////////////////////////////////////////////////////////////
235/// Constructor for set containing 3 initial objects
236
237RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
238 const RooAbsArg& var3,
239 const char *name) :
241{
242 add(var1); add(var2); add(var3);
244}
245
246
247
248////////////////////////////////////////////////////////////////////////////////
249/// Constructor for set containing 4 initial objects
250
251RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
252 const RooAbsArg& var3, const RooAbsArg& var4,
253 const char *name) :
255{
256 add(var1); add(var2); add(var3); add(var4);
258}
259
260
261
262////////////////////////////////////////////////////////////////////////////////
263/// Constructor for set containing 5 initial objects
264
266 const RooAbsArg& var2, const RooAbsArg& var3,
267 const RooAbsArg& var4, const RooAbsArg& var5,
268 const char *name) :
270{
271 add(var1); add(var2); add(var3); add(var4); add(var5);
273}
274
275
276
277////////////////////////////////////////////////////////////////////////////////
278/// Constructor for set containing 6 initial objects
279
280RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
281 const RooAbsArg& var3, const RooAbsArg& var4,
282 const RooAbsArg& var5, const RooAbsArg& var6,
283 const char *name) :
285{
286 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6);
288}
289
290
291
292////////////////////////////////////////////////////////////////////////////////
293/// Constructor for set containing 7 initial objects
294
295RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
296 const RooAbsArg& var3, const RooAbsArg& var4,
297 const RooAbsArg& var5, const RooAbsArg& var6,
298 const RooAbsArg& var7,
299 const char *name) :
301{
302 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;
304}
305
306
307
308////////////////////////////////////////////////////////////////////////////////
309/// Constructor for set containing 8 initial objects
310
311RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
312 const RooAbsArg& var3, const RooAbsArg& var4,
313 const RooAbsArg& var5, const RooAbsArg& var6,
314 const RooAbsArg& var7, const RooAbsArg& var8,
315 const char *name) :
317{
318 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7) ;add(var8) ;
320}
321
322
323
324////////////////////////////////////////////////////////////////////////////////
325/// Constructor for set containing 9 initial objects
326
327RooArgSet::RooArgSet(const RooAbsArg& var1, const RooAbsArg& var2,
328 const RooAbsArg& var3, const RooAbsArg& var4,
329 const RooAbsArg& var5, const RooAbsArg& var6,
330 const RooAbsArg& var7, const RooAbsArg& var8,
331 const RooAbsArg& var9, const char *name) :
333{
334 add(var1); add(var2); add(var3); add(var4); add(var5); add(var6); add(var7); add(var8); add(var9);
336}
337
338
339
340////////////////////////////////////////////////////////////////////////////////
341/// Constructor from a root TCollection. Elements in the collection that
342/// do not inherit from RooAbsArg will be skipped. A warning message
343/// will be printed for every skipped item.
344
345RooArgSet::RooArgSet(const TCollection& tcoll, const char* name) :
347{
348 TIterator* iter = tcoll.MakeIterator() ;
349 TObject* obj ;
350 while((obj=iter->Next())) {
351 if (!dynamic_cast<RooAbsArg*>(obj)) {
352 coutW(InputArguments) << "RooArgSet::RooArgSet(TCollection) element " << obj->GetName()
353 << " is not a RooAbsArg, ignored" << endl ;
354 continue ;
355 }
356 add(*(RooAbsArg*)obj) ;
357 }
358 delete iter ;
360}
361
362
363
364////////////////////////////////////////////////////////////////////////////////
365/// Copy constructor. Note that a copy of a set is always non-owning,
366/// even the source set is owning. To create an owning copy of
367/// a set (owning or not), use the snaphot() method.
368
369RooArgSet::RooArgSet(const RooArgSet& other, const char *name)
370 : RooAbsCollection(other,name)
371{
373}
374
375
376
377////////////////////////////////////////////////////////////////////////////////
378/// Destructor
379
381{
383}
384
385
386
387////////////////////////////////////////////////////////////////////////////////
388/// Add element to non-owning set. The operation will fail if
389/// a similarly named object already exists in the set, or
390/// the set is specified to own its elements. Eventual error messages
391/// can be suppressed with the silent flag
392
394{
395 return checkForDup(var,silent)? kFALSE : RooAbsCollection::add(var,silent) ;
396}
397
398
399
400////////////////////////////////////////////////////////////////////////////////
401/// Add element to an owning set. The operation will fail if
402/// a similarly named object already exists in the set, or
403/// the set is not specified to own its elements. Eventual error messages
404/// can be suppressed with the silent flag
405
407{
408 return checkForDup(var,silent)? kFALSE : RooAbsCollection::addOwned(var,silent) ;
409}
410
411
412
413////////////////////////////////////////////////////////////////////////////////
414/// Add clone of specified element to an owning set. If sucessful, the
415/// set will own the clone, not the original. The operation will fail if
416/// a similarly named object already exists in the set, or
417/// the set is not specified to own its elements. Eventual error messages
418/// can be suppressed with the silent flag
419
421{
422 return checkForDup(var,silent)? 0 : RooAbsCollection::addClone(var,silent) ;
423}
424
425
426
427////////////////////////////////////////////////////////////////////////////////
428/// Array operator. Named element must exist in set, otherwise
429/// code will abort.
430///
431/// When used as lvalue in assignment operations, the element contained in
432/// the list will not be changed, only the value of the existing element!
433
435{
436 RooAbsArg* arg = find(name) ;
437 if (!arg) {
438 coutE(InputArguments) << "RooArgSet::operator[](" << GetName() << ") ERROR: no element named " << name << " in set" << endl ;
440 }
441 return *arg ;
442}
443
444
445
446////////////////////////////////////////////////////////////////////////////////
447/// Check if element with var's name is already in set
448
450{
451 RooAbsArg *other = find(var);
452 if (other) {
453 if (other != &var) {
454 if (!silent) {
455 // print a warning if this variable is not the same one we
456 // already have
457 coutE(InputArguments) << "RooArgSet::checkForDup: ERROR argument with name " << var.GetName() << " is already in this set" << endl;
458 }
459 }
460 // don't add duplicates
461 return kTRUE;
462 }
463 return kFALSE ;
464}
465
466
467
468////////////////////////////////////////////////////////////////////////////////
469/// Get value of a RooAbsReal stored in set with given name. If none is found, value of defVal is returned.
470/// No error messages are printed unless the verbose flag is set
471
473{
474 RooAbsArg* raa = find(name) ;
475 if (!raa) {
476 if (verbose) coutE(InputArguments) << "RooArgSet::getRealValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
477 return defVal ;
478 }
479 RooAbsReal* rar = dynamic_cast<RooAbsReal*>(raa) ;
480 if (!rar) {
481 if (verbose) coutE(InputArguments) << "RooArgSet::getRealValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsReal" << endl ;
482 return defVal ;
483 }
484 return rar->getVal() ;
485}
486
487
488
489////////////////////////////////////////////////////////////////////////////////
490/// Set value of a RooAbsRealLValye stored in set with given name to newVal
491/// No error messages are printed unless the verbose flag is set
492
494{
495 RooAbsArg* raa = find(name) ;
496 if (!raa) {
497 if (verbose) coutE(InputArguments) << "RooArgSet::setRealValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
498 return kTRUE ;
499 }
500 RooAbsRealLValue* rar = dynamic_cast<RooAbsRealLValue*>(raa) ;
501 if (!rar) {
502 if (verbose) coutE(InputArguments) << "RooArgSet::setRealValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsRealLValue" << endl ;
503 return kTRUE;
504 }
505 rar->setVal(newVal) ;
506 return kFALSE ;
507}
508
509
510
511////////////////////////////////////////////////////////////////////////////////
512/// Get state name of a RooAbsCategory stored in set with given name. If none is found, value of defVal is returned.
513/// No error messages are printed unless the verbose flag is set
514
515const char* RooArgSet::getCatLabel(const char* name, const char* defVal, Bool_t verbose) const
516{
517 RooAbsArg* raa = find(name) ;
518 if (!raa) {
519 if (verbose) coutE(InputArguments) << "RooArgSet::getCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
520 return defVal ;
521 }
522 RooAbsCategory* rac = dynamic_cast<RooAbsCategory*>(raa) ;
523 if (!rac) {
524 if (verbose) coutE(InputArguments) << "RooArgSet::getCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
525 return defVal ;
526 }
527 return rac->getLabel() ;
528}
529
530
531
532////////////////////////////////////////////////////////////////////////////////
533/// Set state name of a RooAbsCategoryLValue stored in set with given name to newVal.
534/// No error messages are printed unless the verbose flag is set
535
536Bool_t RooArgSet::setCatLabel(const char* name, const char* newVal, Bool_t verbose)
537{
538 RooAbsArg* raa = find(name) ;
539 if (!raa) {
540 if (verbose) coutE(InputArguments) << "RooArgSet::setCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
541 return kTRUE ;
542 }
543 RooAbsCategoryLValue* rac = dynamic_cast<RooAbsCategoryLValue*>(raa) ;
544 if (!rac) {
545 if (verbose) coutE(InputArguments) << "RooArgSet::setCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
546 return kTRUE ;
547 }
548 rac->setLabel(newVal) ;
549 return kFALSE ;
550}
551
552
553
554////////////////////////////////////////////////////////////////////////////////
555/// Get index value of a RooAbsCategory stored in set with given name. If none is found, value of defVal is returned.
556/// No error messages are printed unless the verbose flag is set
557
559{
560 RooAbsArg* raa = find(name) ;
561 if (!raa) {
562 if (verbose) coutE(InputArguments) << "RooArgSet::getCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
563 return defVal ;
564 }
565 RooAbsCategory* rac = dynamic_cast<RooAbsCategory*>(raa) ;
566 if (!rac) {
567 if (verbose) coutE(InputArguments) << "RooArgSet::getCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
568 return defVal ;
569 }
570 return rac->getIndex() ;
571}
572
573
574
575////////////////////////////////////////////////////////////////////////////////
576/// Set index value of a RooAbsCategoryLValue stored in set with given name to newVal.
577/// No error messages are printed unless the verbose flag is set
578
580{
581 RooAbsArg* raa = find(name) ;
582 if (!raa) {
583 if (verbose) coutE(InputArguments) << "RooArgSet::setCatLabel(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
584 return kTRUE ;
585 }
586 RooAbsCategoryLValue* rac = dynamic_cast<RooAbsCategoryLValue*>(raa) ;
587 if (!rac) {
588 if (verbose) coutE(InputArguments) << "RooArgSet::setCatLabel(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsCategory" << endl ;
589 return kTRUE ;
590 }
591 rac->setIndex(newVal) ;
592 return kFALSE ;
593}
594
595
596
597////////////////////////////////////////////////////////////////////////////////
598/// Get string value of a RooAbsString stored in set with given name. If none is found, value of defVal is returned.
599/// No error messages are printed unless the verbose flag is set
600
601const char* RooArgSet::getStringValue(const char* name, const char* defVal, Bool_t verbose) const
602{
603 RooAbsArg* raa = find(name) ;
604 if (!raa) {
605 if (verbose) coutE(InputArguments) << "RooArgSet::getStringValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
606 return defVal ;
607 }
608 RooAbsString* ras = dynamic_cast<RooAbsString*>(raa) ;
609 if (!ras) {
610 if (verbose) coutE(InputArguments) << "RooArgSet::getStringValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsString" << endl ;
611 return defVal ;
612 }
613 return ras->getVal() ;
614}
615
616
617
618////////////////////////////////////////////////////////////////////////////////
619/// Set string value of a RooStringVar stored in set with given name to newVal.
620/// No error messages are printed unless the verbose flag is set
621
622Bool_t RooArgSet::setStringValue(const char* name, const char* newVal, Bool_t verbose)
623{
624 RooAbsArg* raa = find(name) ;
625 if (!raa) {
626 if (verbose) coutE(InputArguments) << "RooArgSet::setStringValue(" << GetName() << ") ERROR no object with name '" << name << "' found" << endl ;
627 return kTRUE ;
628 }
629 RooStringVar* ras = dynamic_cast<RooStringVar*>(raa) ;
630 if (!ras) {
631 if (verbose) coutE(InputArguments) << "RooArgSet::setStringValue(" << GetName() << ") ERROR object '" << name << "' is not of type RooAbsString" << endl ;
632 return kTRUE ;
633 }
634 ras->setVal(newVal) ;
635 return kFALSE ;
636}
637
638
639
640////////////////////////////////////////////////////////////////////////////////
641/// Write contents of the argset to specified file.
642/// See writeToStream() for details
643
644void RooArgSet::writeToFile(const char* fileName) const
645{
646 ofstream ofs(fileName) ;
647 if (ofs.fail()) {
648 coutE(InputArguments) << "RooArgSet::writeToFile(" << GetName() << ") error opening file " << fileName << endl ;
649 return ;
650 }
651 writeToStream(ofs,kFALSE) ;
652}
653
654
655
656////////////////////////////////////////////////////////////////////////////////
657/// Read contents of the argset from specified file.
658/// See readFromStream() for details
659
660Bool_t RooArgSet::readFromFile(const char* fileName, const char* flagReadAtt, const char* section, Bool_t verbose)
661{
662 ifstream ifs(fileName) ;
663 if (ifs.fail()) {
664 coutE(InputArguments) << "RooArgSet::readFromFile(" << GetName() << ") error opening file " << fileName << endl ;
665 return kTRUE ;
666 }
667 return readFromStream(ifs,kFALSE,flagReadAtt,section,verbose) ;
668}
669
670
671
672
673////////////////////////////////////////////////////////////////////////////////
674/// Write the contents of the argset in ASCII form to given stream.
675///
676/// A line is written for each element contained in the form
677/// `<argName> = <argValue>`
678///
679/// The `<argValue>` part of each element is written by the arguments'
680/// writeToStream() function.
681/// \param os The stream to write to
682/// \param compact Write only the bare values, separated by ' '. Doing this,
683/// the stream cannot be read back into a RooArgSet, but only into a RooArgList, because the
684/// key names are lost.
685
686void RooArgSet::writeToStream(ostream& os, Bool_t compact, const char* /*section*/) const
687{
688 if (compact) {
689 for (const auto next : _list) {
690 next->writeToStream(os, true);
691 os << " ";
692 }
693 os << endl;
694 } else {
695 for (const auto next : _list) {
696 os << next->GetName() << " = " ;
697 next->writeToStream(os,kFALSE) ;
698 os << endl ;
699 }
700 }
701}
702
703
704
705
706////////////////////////////////////////////////////////////////////////////////
707/// Read the contents of the argset in ASCII form from given stream.
708///
709/// The stream is read to end-of-file and each line is assumed to be
710/// of the form
711/// \code
712/// <argName> = <argValue>
713/// \endcode
714/// Lines starting with argNames not matching any element in the list
715/// will be ignored with a warning message. In addition limited C++ style
716/// preprocessing and flow control is provided. The following constructions
717/// are recognized:
718/// \code
719/// include "include.file"
720/// \endcode
721/// Include given file, recursive inclusion OK
722/// \code
723/// if (<boolean_expression>)
724/// <name> = <value>
725/// ....
726/// else if (<boolean_expression>)
727/// ....
728/// else
729/// ....
730/// endif
731/// \endcode
732///
733/// All expressions are evaluated by RooFormula, and may involve any of
734/// the sets variables.
735/// \code
736/// echo <Message>
737/// \endcode
738/// Print console message while reading from stream
739/// \code
740/// abort
741/// \endcode
742/// Force termination of read sequence with error status
743///
744/// The value of each argument is read by the arguments readFromStream
745/// function.
746
747Bool_t RooArgSet::readFromStream(istream& is, Bool_t compact, const char* flagReadAtt, const char* section, Bool_t verbose)
748{
749 if (compact) {
750 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << ") compact mode not supported" << endl ;
751 return kTRUE ;
752 }
753
754 RooStreamParser parser(is) ;
755 parser.setPunctuation("=") ;
756 TString token ;
757 Bool_t retVal(kFALSE) ;
758
759 // Conditional stack and related state variables
760 // coverity[UNINIT]
761 Bool_t anyCondTrue[100] ;
762 Bool_t condStack[100] ;
763 Bool_t lastLineWasElse=kFALSE ;
764 Int_t condStackLevel=0 ;
765 condStack[0]=kTRUE ;
766
767 // Prepare section processing
768 TString sectionHdr("[") ;
769 if (section) sectionHdr.Append(section) ;
770 sectionHdr.Append("]") ;
771 Bool_t inSection(section?kFALSE:kTRUE) ;
772
773 Bool_t reprocessToken = kFALSE ;
774 while (1) {
775
776 if (is.eof() || is.fail() || parser.atEOF()) {
777 break ;
778 }
779
780 // Read next token until memEnd of file
781 if (!reprocessToken) {
782 token = parser.readToken() ;
783 }
784 reprocessToken = kFALSE ;
785
786 // Skip empty lines
787 if (token.IsNull()) {
788 continue ;
789 }
790
791 // Process include directives
792 if (!token.CompareTo("include")) {
793 if (parser.atEOL()) {
794 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName()
795 << "): no filename found after include statement" << endl ;
796 return kTRUE ;
797 }
798 TString filename = parser.readLine() ;
799 ifstream incfs(filename) ;
800 if (!incfs.good()) {
801 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): cannot open include file " << filename << endl ;
802 return kTRUE ;
803 }
804 coutI(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): processing include file "
805 << filename << endl ;
806 if (readFromStream(incfs,compact,flagReadAtt,inSection?0:section,verbose)) return kTRUE ;
807 continue ;
808 }
809
810 // Process section headers if requested
811 if (*token.Data()=='[') {
812 TString hdr(token) ;
813 const char* last = token.Data() + token.Length() -1 ;
814 if (*last != ']') {
815 hdr.Append(" ") ;
816 hdr.Append(parser.readLine()) ;
817 }
818// parser.putBackToken(token) ;
819// token = parser.readLine() ;
820 if (section) {
821 inSection = !sectionHdr.CompareTo(hdr) ;
822 }
823 continue ;
824 }
825
826 // If section is specified, ignore all data outside specified section
827 if (!inSection) {
828 parser.zapToEnd(kTRUE) ;
829 continue ;
830 }
831
832 // Conditional statement evaluation
833 if (!token.CompareTo("if")) {
834
835 // Extract conditional expressions and check validity
836 TString expr = parser.readLine() ;
837 RooFormula form(expr,expr,*this) ;
838 if (!form.ok()) return kTRUE ;
839
840 // Evaluate expression
841 Bool_t status = form.eval()?kTRUE:kFALSE ;
842 if (lastLineWasElse) {
843 anyCondTrue[condStackLevel] |= status ;
844 lastLineWasElse=kFALSE ;
845 } else {
846 condStackLevel++ ;
847 anyCondTrue[condStackLevel] = status ;
848 }
849 condStack[condStackLevel] = status ;
850
851 if (verbose) cxcoutD(Eval) << "RooArgSet::readFromStream(" << GetName()
852 << "): conditional expression " << expr << " = "
853 << (condStack[condStackLevel]?"true":"false") << endl ;
854 continue ; // go to next line
855 }
856
857 if (!token.CompareTo("else")) {
858 // Must have seen an if statement before
859 if (condStackLevel==0) {
860 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): unmatched 'else'" << endl ;
861 }
862
863 if (parser.atEOL()) {
864 // simple else: process if nothing else was true
865 condStack[condStackLevel] = !anyCondTrue[condStackLevel] ;
866 parser.zapToEnd(kFALSE) ;
867 continue ;
868 } else {
869 // if anything follows it should be 'if'
870 token = parser.readToken() ;
871 if (token.CompareTo("if")) {
872 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): syntax error: 'else " << token << "'" << endl ;
873 return kTRUE ;
874 } else {
875 if (anyCondTrue[condStackLevel]) {
876 // No need for further checking, true conditional already processed
877 condStack[condStackLevel] = kFALSE ;
878 parser.zapToEnd(kFALSE) ;
879 continue ;
880 } else {
881 // Process as normal 'if' no true conditional was encountered
882 reprocessToken = kTRUE ;
883 lastLineWasElse=kTRUE ;
884 continue ;
885 }
886 }
887 }
888 }
889
890 if (!token.CompareTo("endif")) {
891 // Must have seen an if statement before
892 if (condStackLevel==0) {
893 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): unmatched 'endif'" << endl ;
894 return kTRUE ;
895 }
896
897 // Decrease stack by one
898 condStackLevel-- ;
899 continue ;
900 }
901
902 // If current conditional is true
903 if (condStack[condStackLevel]) {
904
905 // Process echo statements
906 if (!token.CompareTo("echo")) {
907 TString message = parser.readLine() ;
908 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): >> " << message << endl ;
909 continue ;
910 }
911
912 // Process abort statements
913 if (!token.CompareTo("abort")) {
914 TString message = parser.readLine() ;
915 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): USER ABORT" << endl ;
916 return kTRUE ;
917 }
918
919 // Interpret the rest as <arg> = <value_expr>
920 RooAbsArg *arg ;
921
922 if ((arg = find(token)) && !arg->getAttribute("Dynamic")) {
923 if (parser.expectToken("=",kTRUE)) {
924 parser.zapToEnd(kTRUE) ;
925 retVal=kTRUE ;
926 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName()
927 << "): missing '=' sign: " << arg << endl ;
928 continue ;
929 }
930 Bool_t argRet = arg->readFromStream(is,kFALSE,verbose) ;
931 if (!argRet && flagReadAtt) arg->setAttribute(flagReadAtt,kTRUE) ;
932 retVal |= argRet ;
933 } else {
934 if (verbose) {
935 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): argument "
936 << token << " not in list, ignored" << endl ;
937 }
938 parser.zapToEnd(kTRUE) ;
939 }
940 } else {
941 parser.readLine() ;
942 }
943 }
944
945 // Did we fully unwind the conditional stack?
946 if (condStackLevel!=0) {
947 coutE(InputArguments) << "RooArgSet::readFromStream(" << GetName() << "): missing 'endif'" << endl ;
948 return kTRUE ;
949 }
950
951 return retVal ;
952}
953
954
955Bool_t RooArgSet::isInRange(const char* rangeSpec)
956{
957 char buf[1024] ;
958 strlcpy(buf,rangeSpec,1024) ;
959 char* token = strtok(buf,",") ;
960
961 TIterator* iter = createIterator() ;
962
963 while(token) {
964
965 Bool_t accept=kTRUE ;
966 iter->Reset() ;
967 RooAbsArg* arg ;
968 while((arg=(RooAbsArg*)iter->Next())) {
969 RooAbsRealLValue* lvarg = dynamic_cast<RooAbsRealLValue*>(arg) ;
970 if (lvarg) {
971 if (!lvarg->inRange(token)) {
972 accept=kFALSE ;
973 break ;
974 }
975 }
976 // WVE MUST HANDLE RooAbsCategoryLValue ranges as well
977 }
978 if (accept) {
979 delete iter ;
980 return kTRUE ;
981 }
982
983 token = strtok(0,",") ;
984 }
985
986 delete iter ;
987 return kFALSE ;
988}
#define coutI(a)
Definition: RooMsgService.h:31
#define cxcoutD(a)
Definition: RooMsgService.h:79
#define coutW(a)
Definition: RooMsgService.h:33
#define coutE(a)
Definition: RooMsgService.h:34
#define TRACE_DESTROY
Definition: RooTrace.h:23
#define TRACE_CREATE
Definition: RooTrace.h:22
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
char name[80]
Definition: TGX11.cxx:109
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
Definition: TString.cxx:1474
Memory pool for RooArgSet and RooDataSet.
void teardown()
Set pool to teardown mode (at program end).
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:70
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)=0
void setAttribute(const Text_t *name, Bool_t value=kTRUE)
Set (default) or clear a named boolean attribute of this object.
Definition: RooAbsArg.cxx:256
Bool_t getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
Definition: RooAbsArg.cxx:279
RooAbsCategoryLValue is the common abstract base class for objects that represent a discrete value th...
virtual Bool_t setLabel(const char *label, Bool_t printError=kTRUE)=0
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)=0
RooAbsCategory is the common abstract base class for objects that represent a discrete value with a f...
virtual Int_t getIndex() const
Return index number of current state.
virtual const char * getLabel() const
Return label string of current state.
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Bool_t contains(const RooAbsArg &var) const
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
const char * GetName() const
Returns name of object.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
virtual void setVal(Double_t value)=0
virtual Bool_t inRange(const char *name) const
Check if current value is inside range with given name.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:81
RooAbsString is the common abstract base class for objects that represent a string value.
Definition: RooAbsString.h:25
virtual const char * getVal() const
Return value of object. Calculated if dirty, otherwise cached value is returned.
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooAbsArg & operator[](const char *name) const
Array operator.
Definition: RooArgSet.cxx:434
Int_t getCatIndex(const char *name, Int_t defVal=0, Bool_t verbose=kFALSE) const
Get index value of a RooAbsCategory stored in set with given name.
Definition: RooArgSet.cxx:558
RooArgSet()
Default constructor.
Definition: RooArgSet.cxx:144
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Shortcut for readFromStream(std::istream&, Bool_t, const char*, const char*, Bool_t),...
Definition: RooArgSet.h:110
const char * getCatLabel(const char *name, const char *defVal="", Bool_t verbose=kFALSE) const
Get state name of a RooAbsCategory stored in set with given name.
Definition: RooArgSet.cxx:515
virtual Bool_t addOwned(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
Definition: RooArgSet.h:92
virtual ~RooArgSet()
Destructor.
Definition: RooArgSet.cxx:380
Bool_t readFromFile(const char *fileName, const char *flagReadAtt=0, const char *section=0, Bool_t verbose=kFALSE)
Read contents of the argset from specified file.
Definition: RooArgSet.cxx:660
Bool_t isInRange(const char *rangeSpec)
Definition: RooArgSet.cxx:955
void writeToFile(const char *fileName) const
Write contents of the argset to specified file.
Definition: RooArgSet.cxx:644
Bool_t setCatIndex(const char *name, Int_t newVal=0, Bool_t verbose=kFALSE)
Set index value of a RooAbsCategoryLValue stored in set with given name to newVal.
Definition: RooArgSet.cxx:579
Double_t getRealValue(const char *name, Double_t defVal=0, Bool_t verbose=kFALSE) const
Get value of a RooAbsReal stored in set with given name.
Definition: RooArgSet.cxx:472
static MemPool * memPool()
virtual void writeToStream(std::ostream &os, Bool_t compact, const char *section=0) const
Write the contents of the argset in ASCII form to given stream.
Definition: RooArgSet.cxx:686
const char * getStringValue(const char *name, const char *defVal="", Bool_t verbose=kFALSE) const
Get string value of a RooAbsString stored in set with given name.
Definition: RooArgSet.cxx:601
Bool_t setCatLabel(const char *name, const char *newVal="", Bool_t verbose=kFALSE)
Set state name of a RooAbsCategoryLValue stored in set with given name to newVal.
Definition: RooArgSet.cxx:536
MemPoolForRooSets< RooArgSet, 10 *600 > MemPool
Definition: RooArgSet.h:148
Bool_t setRealValue(const char *name, Double_t newVal=0, Bool_t verbose=kFALSE)
Set value of a RooAbsRealLValye stored in set with given name to newVal No error messages are printed...
Definition: RooArgSet.cxx:493
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
static void cleanup()
Definition: RooArgSet.cxx:71
Bool_t checkForDup(const RooAbsArg &arg, Bool_t silent) const
Check if element with var's name is already in set.
Definition: RooArgSet.cxx:449
Bool_t setStringValue(const char *name, const char *newVal="", Bool_t verbose=kFALSE)
Set string value of a RooStringVar stored in set with given name to newVal.
Definition: RooArgSet.cxx:622
virtual void addClone(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling addOwned() for each element in the source...
Definition: RooArgSet.h:96
static void softAbort()
RooFormula an implementation of ROOT::v5::TFormula that interfaces it to RooAbsArg value objects.
Definition: RooFormula.h:27
Bool_t ok()
Definition: RooFormula.h:50
Double_t eval(const RooArgSet *nset=0)
Evaluate ROOT::v5::TFormula using given normalization set to be used as observables definition passed...
Definition: RooFormula.cxx:234
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
Definition: RooSentinel.cxx:73
Bool_t atEOL()
If true, parser is at end of line in stream.
void setPunctuation(const TString &punct)
Change list of characters interpreted as punctuation.
void zapToEnd(Bool_t inclContLines=kFALSE)
Eat all characters up to and including then end of the current line.
Bool_t expectToken(const TString &expected, Bool_t zapOnError=kFALSE)
Read the next token and return kTRUE if it is identical to the given 'expected' token.
TString readLine()
Read an entire line from the stream and return as TString This method recognizes the use of '\' in th...
TString readToken()
Read one token separated by any of the know punctuation characters This function recognizes and handl...
RooStringVar implements a string values RooAbsArg.
Definition: RooStringVar.h:23
virtual void setVal(const char *newVal)
Set value to given TString.
Collection abstract base class.
Definition: TCollection.h:63
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const =0
Iterator abstract base class.
Definition: TIterator.h:30
virtual void Reset()=0
virtual TObject * Next()=0
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Definition: TString.cxx:418
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402
TString & Append(const char *cs)
Definition: TString.h:559
std::string GetName(const std::string &scope_name)
Definition: Cppyy.cxx:146
@ InputArguments
Definition: RooGlobalFunc.h:58