Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsCollection.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooAbsCollection.h,v 1.26 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_ABS_COLLECTION
17#define ROO_ABS_COLLECTION
18
19#include "TObject.h"
20#include "TString.h"
21#include "RooAbsArg.h"
22#include "RooPrintable.h"
23#include "RooCmdArg.h"
24#include "RooLinkedListIter.h"
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29class RooCmdArg;
30
31class RooAbsCollection : public TObject, public RooPrintable {
32public:
33 using Storage_t = std::vector<RooAbsArg*>;
34 using const_iterator = Storage_t::const_iterator;
35
36
37 // Constructors, assignment etc.
39 RooAbsCollection(const char *name);
40 virtual TObject* clone(const char* newname) const = 0 ;
41 virtual TObject* create(const char* newname) const = 0 ;
42 virtual TObject* Clone(const char* newname=0) const {
43 return clone(newname?newname:GetName()) ;
44 }
45 virtual ~RooAbsCollection();
46
47 // Create a copy of an existing list. New variables cannot be added
48 // to a copied list. The variables in the copied list are independent
49 // of the original variables.
50 RooAbsCollection(const RooAbsCollection& other, const char *name="");
53 void assignFast(const RooAbsCollection& other, Bool_t setValDirty=kTRUE) ;
54
55 // Copy list and contents (and optionally 'deep' servers)
56 RooAbsCollection *snapshot(Bool_t deepCopy=kTRUE) const ;
58
59 /// Set the size at which the collection will automatically start using an extra
60 /// lookup table instead of performing a linear search.
61 void setHashTableSize(Int_t number) {
63 }
64 /// Query the size at which the collection will automatically start using an extra
65 /// lookup table instead of performing a linear search.
68 }
69
70 // List content management
71 virtual Bool_t add(const RooAbsArg& var, Bool_t silent=kFALSE) ;
72 virtual Bool_t addOwned(RooAbsArg& var, Bool_t silent=kFALSE);
73 virtual RooAbsArg *addClone(const RooAbsArg& var, Bool_t silent=kFALSE) ;
74 virtual Bool_t replace(const RooAbsArg& var1, const RooAbsArg& var2) ;
75 virtual Bool_t remove(const RooAbsArg& var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
76 virtual void removeAll() ;
77
78 virtual Bool_t add(const RooAbsCollection& list, Bool_t silent=kFALSE) ;
79 virtual Bool_t addOwned(const RooAbsCollection& list, Bool_t silent=kFALSE);
80 virtual void addClone(const RooAbsCollection& list, Bool_t silent=kFALSE);
81 Bool_t replace(const RooAbsCollection &other);
82 Bool_t remove(const RooAbsCollection& list, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
83 template<class forwardIt>
84 void remove(forwardIt rangeBegin, forwardIt rangeEnd, Bool_t silent = kFALSE, Bool_t matchByNameOnly = kFALSE) {
85 for (forwardIt it = rangeBegin; it != rangeEnd; ++it) {
86 static_assert(std::is_same<
87 typename std::iterator_traits<forwardIt>::value_type,
88 RooAbsArg*>::value, "Can only remove lists of RooAbsArg*.");
89 auto castedElm = static_cast<RooAbsArg*>(*it);
90 remove(*castedElm, silent, matchByNameOnly);
91 }
92 }
93
94 // Utilities functions when used as configuration object
95 Double_t getRealValue(const char* name, Double_t defVal=0, Bool_t verbose=kFALSE) const ;
96 const char* getCatLabel(const char* name, const char* defVal="", Bool_t verbose=kFALSE) const ;
97 Int_t getCatIndex(const char* name, Int_t defVal=0, Bool_t verbose=kFALSE) const ;
98 const char* getStringValue(const char* name, const char* defVal="", Bool_t verbose=kFALSE) const ;
99 Bool_t setRealValue(const char* name, Double_t newVal=0, Bool_t verbose=kFALSE) ;
100 Bool_t setCatLabel(const char* name, const char* newVal="", Bool_t verbose=kFALSE) ;
101 Bool_t setCatIndex(const char* name, Int_t newVal=0, Bool_t verbose=kFALSE) ;
102 Bool_t setStringValue(const char* name, const char* newVal="", Bool_t verbose=kFALSE) ;
103
104 // Group operations on AbsArgs
105 void setAttribAll(const Text_t* name, Bool_t value=kTRUE) ;
106
107 // List search methods
108 RooAbsArg *find(const char *name) const ;
109 RooAbsArg *find(const RooAbsArg&) const ;
110
111 /// Check if collection contains an argument with the same name as var.
112 /// To check for a specific instance, use containsInstance().
113 Bool_t contains(const RooAbsArg& var) const {
114 return find(var) != nullptr;
115 }
116 /// Check if this exact instance is in this collection.
117 Bool_t containsInstance(const RooAbsArg& var) const {
118 return std::find(_list.begin(), _list.end(), &var) != _list.end();
119 }
120 RooAbsCollection* selectByAttrib(const char* name, Bool_t value) const ;
121 RooAbsCollection* selectCommon(const RooAbsCollection& refColl) const ;
122 RooAbsCollection* selectByName(const char* nameList, Bool_t verbose=kFALSE) const ;
123 Bool_t equals(const RooAbsCollection& otherColl) const ;
124 Bool_t overlaps(const RooAbsCollection& otherColl) const ;
125
126 /// TIterator-style iteration over contained elements.
127 /// \note These iterators are slow. Use begin() and end() or
128 /// range-based for loop instead.
130 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
131 // Create and return an iterator over the elements in this collection
132 return new RooLinkedListIter(makeLegacyIterator(dir));
133 }
134
135 /// TIterator-style iteration over contained elements.
136 /// \note This iterator is slow. Use begin() and end() or range-based for loop instead.
138 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
140 }
141
142 /// One-time forward iterator.
143 /// \note Use begin() and end() or range-based for loop instead.
145 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
147 }
148
150 return _list.begin();
151 }
152
154 return _list.end();
155 }
156
157 Storage_t::const_reverse_iterator rbegin() const {
158 return _list.rbegin();
159 }
160
161 Storage_t::const_reverse_iterator rend() const {
162 return _list.rend();
163 }
164
165 Storage_t::size_type size() const {
166 return _list.size();
167 }
168
169 bool empty() const {
170 return _list.empty();
171 }
172
173 void reserve(Storage_t::size_type count) {
174 _list.reserve(count);
175 }
176
177 /// Clear contents. If the collection is owning, it will also delete the contents.
178 void clear() {
179 removeAll();
180 }
181
182 inline Int_t getSize() const {
183 // Return the number of elements in the collection
184 return _list.size();
185 }
186
187 inline RooAbsArg *first() const {
188 // Return the first element in this collection
189 return _list.front();
190 }
191
192 RooAbsArg * operator[](Storage_t::size_type i) const {
193 return _list[i];
194 }
195
196
197 /// Returns index of given arg, or -1 if arg is not in the collection.
198 inline Int_t index(const RooAbsArg* arg) const {
199 auto item = std::find(_list.begin(), _list.end(), arg);
200 return item != _list.end() ? item - _list.begin() : -1;
201 }
202
203 /// Returns index of given arg, or -1 if arg is not in the collection.
204 inline Int_t index(const RooAbsArg& arg) const {
205 return index(&arg);
206 }
207
208 Int_t index(const char* name) const;
209
210 inline virtual void Print(Option_t *options= 0) const {
211 // Printing interface (human readable)
213 }
214 std::string contentsString() const ;
215
216
217 virtual void printName(std::ostream& os) const ;
218 virtual void printTitle(std::ostream& os) const ;
219 virtual void printClassName(std::ostream& os) const ;
220 virtual void printValue(std::ostream& os) const ;
221 virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
222
223 virtual Int_t defaultPrintContents(Option_t* opt) const ;
224
225 // Latex printing methods
226 void printLatex(const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(),
227 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
228 const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
229 const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) const ;
230 void printLatex(std::ostream& ofs, Int_t ncol, const char* option="NEYU", Int_t sigDigit=1,
231 const RooLinkedList& siblingLists=RooLinkedList(), const RooCmdArg* formatCmd=0) const ;
232
233 void setName(const char *name) {
234 // Set name of collection
235 _name= name;
236 }
237 const char* GetName() const {
238 // Return namer of collection
239 return _name.Data() ;
240 }
241 Bool_t isOwning() const {
242 // Does collection own contents?
243 return _ownCont ;
244 }
245
246 Bool_t allInRange(const char* rangeSpec) const ;
247
248 void dump() const ;
249
252
253 void sort(Bool_t reverse = false);
254
255 virtual void RecursiveRemove(TObject *obj);
256
257 void useHashMapForFind(bool flag) const;
258
259protected:
260 Storage_t _list; // Actual object storage
262
263 Bool_t _ownCont; // Flag to identify a list that owns its contents.
264 TString _name; // Our name.
265 Bool_t _allRRV ; // All contents are RRV
266
267 void safeDeleteList() ;
268
269 // Support for snapshot method
271
274
275 mutable TNamed* _structureTag{nullptr}; //! Structure tag
276 mutable TNamed* _typedStructureTag{nullptr}; //! Typed structure tag
277
279
280 void makeStructureTag() ;
281 void makeTypedStructureTag() ;
282
283private:
284 std::unique_ptr<LegacyIterator_t> makeLegacyIterator (bool forward = true) const;
285 mutable std::unique_ptr<std::unordered_map<const TNamed*, Storage_t::value_type>> _nameToItemMap; //!
287 void insert(RooAbsArg*);
288 RooAbsArg* tryFastFind(const TNamed* namePtr) const;
289
290 ClassDef(RooAbsCollection,3) // Collection of RooAbsArg objects
291};
292
293#endif
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition RConfig.hxx:534
char Text_t
Definition RtypesCore.h:62
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassDef(name, id)
Definition Rtypes.h:325
static void indent(ostringstream &buf, int indent_level)
const Bool_t kIterForward
Definition TCollection.h:40
char name[80]
Definition TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition RooAbsArg.h:72
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
void clearStructureTags()
Typed structure tag.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
void remove(forwardIt rangeBegin, forwardIt rangeEnd, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Bool_t containsInstance(const RooAbsArg &var) const
Check if this exact instance is in this collection.
std::vector< RooAbsArg * > Storage_t
TNamed * _typedStructureTag
Structure tag.
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
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.
virtual TObject * create(const char *newname) const =0
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.
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.
TNamed * typedStructureTag()
RooAbsCollection()
Default constructor.
RooAbsCollection & assignValueOnly(const RooAbsCollection &other, Bool_t oneSafe=kFALSE)
The assignment operator sets the value of any argument in our set that also appears in the other set.
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
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.
Int_t getSize() const
Storage_t::const_reverse_iterator rend() const
RooAbsArg * tryFastFind(const TNamed *namePtr) const
Perform a search in a hash map.
void printLatex(const RooCmdArg &arg1=RooCmdArg(), 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
Output content of collection as LaTex table.
void sort(Bool_t reverse=false)
Sort collection using std::sort and name comparison.
Bool_t contains(const RooAbsArg &var) const
Check if collection contains an argument with the same name as var.
Bool_t addServerClonesToList(const RooAbsArg &var)
Add clones of servers of given argument to end of list.
virtual void printName(std::ostream &os) const
Return collection name.
Storage_t::const_reverse_iterator rbegin() const
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
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.
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
RooFIter fwdIterator() const
One-time forward iterator.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
const_iterator end() const
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.
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.
virtual ~RooAbsCollection()
Destructor.
Storage_t::size_type size() const
RooAbsArg * operator[](Storage_t::size_type i) const
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...
RooAbsArg * first() const
void assignFast(const RooAbsCollection &other, Bool_t setValDirty=kTRUE)
Functional equivalent of operator=() but assumes this and other collection have same layout.
void reserve(Storage_t::size_type count)
RooAbsCollection * selectByName(const char *nameList, Bool_t verbose=kFALSE) const
Create a subset of the current collection, consisting only of those elements with names matching the ...
void clear()
Clear contents. If the collection is owning, it will also delete the contents.
Bool_t overlaps(const RooAbsCollection &otherColl) const
Check if this and other collection have common entries.
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range.
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multiline printing of collection, one line for each contained object showing the requested ...
Int_t index(const RooAbsArg &arg) const
Returns index of given arg, or -1 if arg is not in the collection.
const_iterator begin() const
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
std::unique_ptr< LegacyIterator_t > makeLegacyIterator(bool forward=true) const
Factory for legacy iterators.
std::size_t _sizeThresholdForMapSearch
void setAttribAll(const Text_t *name, Bool_t value=kTRUE)
Set given attribute in each element of the collection by calling each elements setAttribute() functio...
std::unique_ptr< std::unordered_map< const TNamed *, Storage_t::value_type > > _nameToItemMap
void dump() const
Base contents dumper for debugging purposes.
Bool_t isOwning() const
virtual void printTitle(std::ostream &os) const
Return collection title.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically-named contents.
RooAbsCollection * selectByAttrib(const char *name, Bool_t value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
void useHashMapForFind(bool flag) const
Install an internal hash map for fast finding of elements by name.
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.
const char * GetName() const
Returns name of object.
virtual void printClassName(std::ostream &os) const
Return collection class name.
void setHashTableSize(Int_t number)
Set the size at which the collection will automatically start using an extra lookup table instead of ...
std::string contentsString() const
Return comma separated list of contained object names as STL string.
void setName(const char *name)
RooAbsCollection & operator=(const RooAbsCollection &other)
The assignment operator sets the value of any argument in our set that also appears in the other set.
void safeDeleteList()
Examine client server dependencies in list and delete contents in safe order: any client is deleted b...
Int_t getHashTableSize() const
Query the size at which the collection will automatically start using an extra lookup table instead o...
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
virtual void RecursiveRemove(TObject *obj)
If one of the TObject we have a referenced to is deleted, remove the reference.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
virtual TObject * clone(const char *newname) const =0
void insert(RooAbsArg *)
Insert an element into the owned collections.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
RooAbsArg * find(const char *name) const
Find object with given name in list.
Storage_t::const_iterator const_iterator
virtual void printValue(std::ostream &os) const
Print value of collection, i.e.
virtual Int_t defaultPrintContents(Option_t *opt) const
Define default RooPrinable print options for given Print() flag string For inline printing only show ...
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition RooCmdArg.h:27
A one-time forward iterator working on RooLinkedList or RooAbsCollection.
A wrapper around TIterator derivatives.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
virtual StyleOption defaultPrintStyle(Option_t *opt) const
static std::ostream & defaultPrintStream(std::ostream *os=0)
Return a reference to the current default stream to use in Print().
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
TIterator and GenericRooFIter front end with STL back end.
Iterator abstract base class.
Definition TIterator.h:30
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:37
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
for(Int_t i=0;i< n;i++)
Definition legend1.C:18
static void output(int code)
Definition gifencode.c:226