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 // Use a memory pool for RooArgSet.
25 // RooFit assumes (e.g. for caching results) that arg sets that have the same pointer have
26 // the same contents. Trying to remove that memory pool lead to wrong results, because the
27 // OS *occasionally* returns the same address, and the caching goes wrong.
28 // It's hard to track down, so disable this only when e.g. looking for memory leaks!
29 #define USEMEMPOOLFORARGSET
30 template <class RooSet_t, size_t>
31 class MemPoolForRooSets;
32 
33 class RooArgSet : public RooAbsCollection {
34 public:
35 
36 #ifdef USEMEMPOOLFORARGSET
37  void* operator new (size_t bytes);
38  void* operator new (size_t bytes, void* ptr) noexcept;
39  void operator delete (void *ptr);
40 #endif
41 
42  // Constructors, assignment etc.
43  RooArgSet();
44 
45  /// Construct a (non-owning) RooArgSet from one or more
46  /// RooFit objects. The set will not own its contents.
47  /// \tparam Ts Parameter pack of objects that derive from RooAbsArg or RooFit collections; or a name.
48  /// \param arg A RooFit object.
49  /// \param moreArgsOrName Arbitrary number of
50  /// - Further RooFit objects that derive from RooAbsArg
51  /// - RooFit collections of such objects
52  /// - A name for the set. Given multiple names, the last-given name prevails.
53  template<typename... Ts>
54  RooArgSet(const RooAbsArg& arg, const Ts&... moreArgsOrName) {
55  add(arg);
56  // Expand parameter pack in C++ 11 way:
57  int dummy[] = { 0, (processArg(moreArgsOrName), 0) ... };
58  (void)dummy;
59  }
60 
61  /// Construct a (non-owning) RooArgSet from iterators.
62  /// \tparam Iterator_t An iterator pointing to RooFit objects or to pointers/references of those.
63  /// \param beginIt Iterator to first element to add.
64  /// \param endIt Iterator to end of range to be added.
65  /// \param name Optional name of the collection.
66  template<typename Iterator_t,
67  typename value_type = typename std::remove_pointer<typename std::iterator_traits<Iterator_t>::value_type>::type,
68  typename = std::enable_if<std::is_convertible<const value_type*, const RooAbsArg*>::value> >
69  RooArgSet(Iterator_t beginIt, Iterator_t endIt, const char* name="") :
70  RooArgSet(name) {
71  for (auto it = beginIt; it != endIt; ++it) {
72  processArg(*it);
73  }
74  }
75 
76  RooArgSet(const RooArgSet& other, const char *name="");
77  /// Move constructor.
78  RooArgSet(RooArgSet && other) : RooAbsCollection(std::move(other)) {}
79 
80  RooArgSet(const RooArgSet& set1, const RooArgSet& set2,
81  const char *name="");
82 
83  RooArgSet(const RooArgList& list) ;
84  RooArgSet(const RooAbsCollection& collection, const RooAbsArg* var1);
85  explicit RooArgSet(const TCollection& tcoll, const char* name="") ;
86  explicit RooArgSet(const char *name);
87 
88  ~RooArgSet() override;
89  TObject* clone(const char* newname) const override { return new RooArgSet(*this,newname); }
90  TObject* create(const char* newname) const override { return new RooArgSet(newname); }
91  RooArgSet& operator=(const RooArgSet& other) { RooAbsCollection::operator=(other) ; return *this ;}
92 
93  using RooAbsCollection::operator[];
94  RooAbsArg& operator[](const TString& str) const;
95 
96 
97  /// Shortcut for readFromStream(std::istream&, Bool_t, const char*, const char*, Bool_t), setting
98  /// `flagReadAtt` and `section` to 0.
99  virtual bool readFromStream(std::istream& is, bool compact, bool verbose=false) {
100  // I/O streaming interface (machine readable)
101  return readFromStream(is, compact, 0, 0, verbose) ;
102  }
103  Bool_t readFromStream(std::istream& is, Bool_t compact, const char* flagReadAtt, const char* section, Bool_t verbose=kFALSE) ;
104  virtual void writeToStream(std::ostream& os, bool compact, const char* section=0) const;
105  void writeToFile(const char* fileName) const ;
106  Bool_t readFromFile(const char* fileName, const char* flagReadAtt=0, const char* section=0, Bool_t verbose=kFALSE) ;
107 
108 
109 
110  static void cleanup() ;
111 
112  Bool_t isInRange(const char* rangeSpec) ;
113 
114  /// Use RooAbsCollection::snapshot(), but return as RooArgSet.
115  RooArgSet * snapshot(bool deepCopy = true) const {
116  return static_cast<RooArgSet*>(RooAbsCollection::snapshot(deepCopy));
117  }
118 
119  /// \copydoc RooAbsCollection::snapshot()
121  return RooAbsCollection::snapshot(output, deepCopy);
122  }
123 
124 protected:
125  Bool_t checkForDup(const RooAbsArg& arg, Bool_t silent) const ;
126  virtual bool canBeAdded(const RooAbsArg& arg, bool silent) const override {
127  return !checkForDup(arg, silent);
128  }
129 
130 private:
131  void processArg(const RooAbsArg& var) { add(var); }
132  void processArg(const RooAbsArg* var) { add(*var); }
133  void processArg(const RooArgSet& set) { add(set); if (_name.Length() == 0) _name = set.GetName(); }
134  void processArg(const RooArgList& list);
135  void processArg(const char* name) { _name = name; }
136 
137 #ifdef USEMEMPOOLFORARGSET
138 private:
139  typedef MemPoolForRooSets<RooArgSet, 10*600> MemPool; //600 = about 100 kb
140  //Initialise a static mem pool. It has to happen inside a function to solve the
141  //static initialisation order fiasco. At the end of the program, this might have
142  //to leak depending if RooArgSets are still alive. This depends on the order of destructions.
143  static MemPool* memPool();
144 #endif
145 
146  ClassDefOverride(RooArgSet,1) // Set of RooAbsArg objects
147 };
148 
149 #endif
RooArgSet::MemPool
MemPoolForRooSets< RooArgSet, 10 *600 > MemPool
Definition: RooArgSet.h:139
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
RooArgSet::writeToFile
void writeToFile(const char *fileName) const
Write contents of the argset to specified file.
Definition: RooArgSet.cxx:308
RooArgSet::RooArgSet
RooArgSet(RooArgSet &&other)
Move constructor.
Definition: RooArgSet.h:78
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:281
RooArgSet::isInRange
Bool_t isInRange(const char *rangeSpec)
Definition: RooArgSet.cxx:622
RooArgSet::clone
TObject * clone(const char *newname) const override
Definition: RooArgSet.h:89
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
RooAbsArg.h
RooArgSet::operator=
RooArgSet & operator=(const RooArgSet &other)
Definition: RooArgSet.h:91
RooArgSet::processArg
void processArg(const RooAbsArg &var)
Definition: RooArgSet.h:131
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:313
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:286
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:324
bool
RooArgSet::processArg
void processArg(const RooAbsArg *var)
Definition: RooArgSet.h:132
RooAbsCollection.h
RooArgSet::snapshot
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition: RooArgSet.h:115
RooArgSet::canBeAdded
virtual bool canBeAdded(const RooAbsArg &arg, bool silent) const override
Determine whether it's possible to add a given RooAbsArg to the collection or not.
Definition: RooArgSet.h:126
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
RooArgSet::memPool
static MemPool * memPool()
RooArgSet::readFromStream
virtual bool readFromStream(std::istream &is, bool compact, bool verbose=false)
Shortcut for readFromStream(std::istream&, Bool_t, const char*, const char*, Bool_t),...
Definition: RooArgSet.h:99
RooAbsCollection
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
Definition: RooAbsCollection.h:33
RooAbsCollection::add
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Definition: RooAbsCollection.cxx:455
RooArgSet::operator[]
RooAbsArg & operator[](const TString &str) const
Get reference to an element using its name.
Definition: RooArgSet.cxx:266
void
typedef void((*Func_t)())
MemPoolForRooSets
Memory pool for RooArgSet and RooDataSet.
Definition: MemPoolForRooSets.h:60
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:54
RooArgSet::writeToStream
virtual void writeToStream(std::ostream &os, bool compact, const char *section=0) const
Write the contents of the argset in ASCII form to given stream.
Definition: RooArgSet.cxx:350
RooArgSet::snapshot
Bool_t snapshot(RooAbsCollection &output, Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
Definition: RooArgSet.h:120
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:324
RooArgSet::RooArgSet
RooArgSet(Iterator_t beginIt, Iterator_t endIt, const char *name="")
Construct a (non-owning) RooArgSet from iterators.
Definition: RooArgSet.h:69
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:135
type
int type
Definition: TGX11.cxx:121
RooArgSet::processArg
void processArg(const RooArgSet &set)
Definition: RooArgSet.h:133
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:33
RooAbsCollection::snapshot
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
Definition: RooAbsCollection.cxx:215
RooArgSet::create
TObject * create(const char *newname) const override
Definition: RooArgSet.h:90