Logo ROOT  
Reference Guide
RooArgSet.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooArgSet.h,v 1.45 2007/08/09 19:55:47 wouter Exp $
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 #ifndef ROO_ARG_SET
17 #define ROO_ARG_SET
18 
19 #include "RooAbsCollection.h"
20 #include "RooAbsArg.h"
21 
22 class RooArgList ;
23 
24 
25 #define USEMEMPOOLFORARGSET
26 template <class RooSet_t, size_t>
27 class MemPoolForRooSets;
28 
29 class RooArgSet : public RooAbsCollection {
30 public:
31 
32 #ifdef USEMEMPOOLFORARGSET
33  void* operator new (size_t bytes);
34  void* operator new (size_t bytes, void* ptr) noexcept;
35  void operator delete (void *ptr);
36 #endif
37 
38  // Constructors, assignment etc.
39  RooArgSet();
40 
41  /// Construct a (non-owning) RooArgSet from one or more
42  /// RooFit objects. The set will not own its contents.
43  /// \tparam Ts Parameter pack of objects that derive from RooAbsArg or RooFit collections; or a name.
44  /// \param arg A RooFit object.
45  /// \param moreArgsOrName Arbitrary number of
46  /// - Further RooFit objects that derive from RooAbsArg
47  /// - RooFit collections of such objects
48  /// - A name for the set. Given multiple names, the last-given name prevails.
49  template<typename... Ts>
50  RooArgSet(const RooAbsArg& arg, const Ts&... moreArgsOrName) {
51  add(arg);
52  // Expand parameter pack in C++ 11 way:
53  int dummy[] = { 0, (processArg(moreArgsOrName), 0) ... };
54  (void)dummy;
55  };
56 
57  /// Construct from iterators.
58  /// \tparam Iterator_t An iterator pointing to RooFit objects or references thereof.
59  /// \param beginIt Iterator to first element to add.
60  /// \param end Iterator to end of range to be added.
61  /// \param name Optional name of the collection.
62  template<typename Iterator_t,
63  typename value_type = typename std::iterator_traits<Iterator_t>::value_type,
64  typename = std::enable_if<std::is_convertible<const value_type*, const RooAbsArg*>::value> >
65  RooArgSet(Iterator_t beginIt, Iterator_t endIt, const char* name="") :
66  RooArgSet(name) {
67  for (auto it = beginIt; it != endIt; ++it) {
68  add(*it);
69  }
70  }
71 
72  RooArgSet(const RooArgSet& other, const char *name="");
73 
74  RooArgSet(const RooArgSet& set1, const RooArgSet& set2,
75  const char *name="");
76 
77  RooArgSet(const RooArgList& list) ;
78  RooArgSet(const RooAbsCollection& collection, const RooAbsArg* var1);
79  explicit RooArgSet(const TCollection& tcoll, const char* name="") ;
80  explicit RooArgSet(const char *name);
81 
82  ~RooArgSet() override;
83  TObject* clone(const char* newname) const override { return new RooArgSet(*this,newname); }
84  TObject* create(const char* newname) const override { return new RooArgSet(newname); }
85  RooArgSet& operator=(const RooArgSet& other) { RooAbsCollection::operator=(other) ; return *this ;}
86 
88  Bool_t add(const RooAbsArg& var, Bool_t silent=kFALSE) override;
89 
91  Bool_t addOwned(RooAbsArg& var, Bool_t silent=kFALSE) override;
92 
94  RooAbsArg *addClone(const RooAbsArg& var, Bool_t silent=kFALSE) override;
95 
96  using RooAbsCollection::operator[];
97  RooAbsArg& operator[](const TString& str) const;
98 
99 
100  /// Shortcut for readFromStream(std::istream&, Bool_t, const char*, const char*, Bool_t), setting
101  /// `flagReadAtt` and `section` to 0.
102  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) {
103  // I/O streaming interface (machine readable)
104  return readFromStream(is, compact, 0, 0, verbose) ;
105  }
106  Bool_t readFromStream(std::istream& is, Bool_t compact, const char* flagReadAtt, const char* section, Bool_t verbose=kFALSE) ;
107  virtual void writeToStream(std::ostream& os, Bool_t compact, const char* section=0) const;
108  void writeToFile(const char* fileName) const ;
109  Bool_t readFromFile(const char* fileName, const char* flagReadAtt=0, const char* section=0, Bool_t verbose=kFALSE) ;
110 
111  // Utilities functions when used as configuration object
112  Double_t getRealValue(const char* name, Double_t defVal=0, Bool_t verbose=kFALSE) const ;
113  const char* getCatLabel(const char* name, const char* defVal="", Bool_t verbose=kFALSE) const ;
114  Int_t getCatIndex(const char* name, Int_t defVal=0, Bool_t verbose=kFALSE) const ;
115  const char* getStringValue(const char* name, const char* defVal="", Bool_t verbose=kFALSE) const ;
116  Bool_t setRealValue(const char* name, Double_t newVal=0, Bool_t verbose=kFALSE) ;
117  Bool_t setCatLabel(const char* name, const char* newVal="", Bool_t verbose=kFALSE) ;
118  Bool_t setCatIndex(const char* name, Int_t newVal=0, Bool_t verbose=kFALSE) ;
119  Bool_t setStringValue(const char* name, const char* newVal="", Bool_t verbose=kFALSE) ;
120 
121  static void cleanup() ;
122 
123  Bool_t isInRange(const char* rangeSpec) ;
124 
125  /// Use RooAbsCollection::snapshot(), but return as RooArgSet.
126  RooArgSet * snapshot(bool deepCopy = true) const {
127  return static_cast<RooArgSet*>(RooAbsCollection::snapshot(deepCopy));
128  }
129 
130  /// \copydoc RooAbsCollection::snapshot()
132  return RooAbsCollection::snapshot(output, deepCopy);
133  }
134 
135 protected:
136  Bool_t checkForDup(const RooAbsArg& arg, Bool_t silent) const ;
137 
138 private:
139  void processArg(const RooAbsArg& var) { add(var); }
140  void processArg(const RooArgSet& set) { add(set); if (_name.Length() == 0) _name = set.GetName(); }
141  void processArg(const RooArgList& list);
142  void processArg(const char* name) { _name = name; }
143 
144 #ifdef USEMEMPOOLFORARGSET
145 private:
146  typedef MemPoolForRooSets<RooArgSet, 10*600> MemPool; //600 = about 100 kb
147  //Initialise a static mem pool. It has to happen inside a function to solve the
148  //static initialisation order fiasco. At the end of the program, this might have
149  //to leak depending if RooArgSets are still alive. This depends on the order of destructions.
150  static MemPool* memPool();
151 #endif
152 
153  ClassDefOverride(RooArgSet,1) // Set of RooAbsArg objects
154 };
155 
156 #endif
RooArgSet::MemPool
MemPoolForRooSets< RooArgSet, 10 *600 > MemPool
Definition: RooArgSet.h:146
RooArgSet::setRealValue
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:364
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooArgSet::writeToFile
void writeToFile(const char *fileName) const
Write contents of the argset to specified file.
Definition: RooArgSet.cxx:517
RooArgSet::getRealValue
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:343
RooArgSet::checkForDup
Bool_t checkForDup(const RooAbsArg &arg, Bool_t silent) const
Check if element with var's name is already in set.
Definition: RooArgSet.cxx:320
RooArgSet::isInRange
Bool_t isInRange(const char *rangeSpec)
Definition: RooArgSet.cxx:831
RooArgSet::clone
TObject * clone(const char *newname) const override
Definition: RooArgSet.h:83
RooArgSet::RooArgSet
RooArgSet()
Default constructor.
Definition: RooArgSet.cxx:146
output
static void output(int code)
Definition: gifencode.c:226
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet::setStringValue
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:494
RooAbsArg.h
RooArgSet::operator=
RooArgSet & operator=(const RooArgSet &other)
Definition: RooArgSet.h:85
RooArgSet::setCatLabel
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:407
RooArgSet::processArg
void processArg(const RooAbsArg &var)
Definition: RooArgSet.h:139
TString::Length
Ssiz_t Length() const
Definition: TString.h:410
RooArgSet::~RooArgSet
~RooArgSet() override
Destructor.
Definition: RooArgSet.cxx:241
RooAbsCollection::_name
TString _name
Definition: RooAbsCollection.h:254
TString
Basic string class.
Definition: TString.h:136
ClassDefOverride
#define ClassDefOverride(name, id)
Definition: Rtypes.h:329
RooAbsCollection::GetName
const char * GetName() const
Returns name of object.
Definition: RooAbsCollection.h:227
RooArgSet::getCatLabel
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:386
RooAbsCollection::operator=
RooAbsCollection & operator=(const RooAbsCollection &other)
The assignment operator sets the value of any argument in our set that also appears in the other set.
Definition: RooAbsCollection.cxx:310
bool
RooArgSet::getCatIndex
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:429
RooAbsCollection.h
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:126
RooAbsCollection::addClone
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
Definition: RooAbsCollection.cxx:412
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooArgSet::memPool
static MemPool * memPool()
RooAbsCollection
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Definition: RooAbsCollection.h:31
RooArgSet::addClone
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
Definition: RooAbsCollection.cxx:412
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:437
RooArgSet::addOwned
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:389
RooArgSet::operator[]
RooAbsArg & operator[](const TString &str) const
Get reference to an element using its name.
Definition: RooArgSet.cxx:305
void
typedef void((*Func_t)())
RooArgSet::writeToStream
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:559
RooAbsCollection::addOwned
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:389
MemPoolForRooSets
Memory pool for RooArgSet and RooDataSet.
Definition: MemPoolForRooSets.h:34
RooArgSet::readFromStream
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:102
RooArgSet::cleanup
static void cleanup()
Definition: RooArgSet.cxx:73
RooArgSet::RooArgSet
RooArgSet(const RooAbsArg &arg, const Ts &... moreArgsOrName)
Construct a (non-owning) RooArgSet from one or more RooFit objects.
Definition: RooArgSet.h:50
Double_t
double Double_t
Definition: RtypesCore.h:59
RooArgSet::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:437
RooArgSet::snapshot
Bool_t snapshot(RooAbsCollection &output, Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
Definition: RooArgSet.h:131
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
RooArgSet::readFromFile
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:533
RooArgSet::RooArgSet
RooArgSet(Iterator_t beginIt, Iterator_t endIt, const char *name="")
Construct from iterators.
Definition: RooArgSet.h:65
name
char name[80]
Definition: TGX11.cxx:110
genreflex::verbose
bool verbose
Definition: rootcling_impl.cxx:133
RooAbsArg
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
TCollection
Collection abstract base class.
Definition: TCollection.h:63
RooArgSet::processArg
void processArg(const char *name)
Definition: RooArgSet.h:142
RooArgSet::processArg
void processArg(const RooArgSet &set)
Definition: RooArgSet.h:140
RooArgSet::getStringValue
const char * getStringValue(const char *name, const char *defVal="", Bool_t verbose=kFALSE) const
Get string value of a RooStringVar stored in set with given name.
Definition: RooArgSet.cxx:472
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
RooAbsCollection::snapshot
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
Definition: RooAbsCollection.cxx:201
int
RooArgSet::setCatIndex
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:450
RooArgSet::create
TObject * create(const char *newname) const override
Definition: RooArgSet.h:84