Logo ROOT  
Reference Guide
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 "TString.h"
20#include "RooAbsArg.h"
21#include "RooPrintable.h"
22#include "RooCmdArg.h"
23#include "RooLinkedListIter.h"
24#include <string>
25#include <unordered_map>
26
27class RooCmdArg;
28
29class RooAbsCollection : public TObject, public RooPrintable {
30public:
31 using Storage_t = std::vector<RooAbsArg*>;
32 using const_iterator = Storage_t::const_iterator;
33
34
35 // Constructors, assignment etc.
37 RooAbsCollection(const char *name);
38 virtual TObject* clone(const char* newname) const = 0 ;
39 virtual TObject* create(const char* newname) const = 0 ;
40 virtual TObject* Clone(const char* newname=0) const {
41 return clone(newname?newname:GetName()) ;
42 }
43 virtual ~RooAbsCollection();
44
45 // Create a copy of an existing list. New variables cannot be added
46 // to a copied list. The variables in the copied list are independent
47 // of the original variables.
48 RooAbsCollection(const RooAbsCollection& other, const char *name="");
51 void assignFast(const RooAbsCollection& other, Bool_t setValDirty=kTRUE) ;
52
53 // Copy list and contents (and optionally 'deep' servers)
54 RooAbsCollection *snapshot(Bool_t deepCopy=kTRUE) const ;
56
57 /// Set the size at which the collection will automatically start using an extra
58 /// lookup table instead of performing a linear search.
59 void setHashTableSize(Int_t number) {
61 }
62 /// Query the size at which the collection will automatically start using an extra
63 /// lookup table instead of performing a linear search.
66 }
67
68 // List content management
69 virtual Bool_t add(const RooAbsArg& var, Bool_t silent=kFALSE) ;
70 virtual Bool_t addOwned(RooAbsArg& var, Bool_t silent=kFALSE);
71 virtual RooAbsArg *addClone(const RooAbsArg& var, Bool_t silent=kFALSE) ;
72 virtual Bool_t replace(const RooAbsArg& var1, const RooAbsArg& var2) ;
73 virtual Bool_t remove(const RooAbsArg& var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
74 virtual void removeAll() ;
75
76 virtual Bool_t add(const RooAbsCollection& list, Bool_t silent=kFALSE) ;
77 virtual Bool_t addOwned(const RooAbsCollection& list, Bool_t silent=kFALSE);
78 virtual void addClone(const RooAbsCollection& list, Bool_t silent=kFALSE);
79 Bool_t replace(const RooAbsCollection &other);
80 Bool_t remove(const RooAbsCollection& list, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
81 template<class forwardIt>
82 void remove(forwardIt rangeBegin, forwardIt rangeEnd, Bool_t silent = kFALSE, Bool_t matchByNameOnly = kFALSE) {
83 for (forwardIt it = rangeBegin; it != rangeEnd; ++it) {
84 static_assert(std::is_same<
85 typename std::iterator_traits<forwardIt>::value_type,
86 RooAbsArg*>::value, "Can only remove lists of RooAbsArg*.");
87 auto castedElm = static_cast<RooAbsArg*>(*it);
88 remove(*castedElm, silent, matchByNameOnly);
89 }
90 }
91
92 // Utilities functions when used as configuration object
93 Double_t getRealValue(const char* name, Double_t defVal=0, Bool_t verbose=kFALSE) const ;
94 const char* getCatLabel(const char* name, const char* defVal="", Bool_t verbose=kFALSE) const ;
95 Int_t getCatIndex(const char* name, Int_t defVal=0, Bool_t verbose=kFALSE) const ;
96 const char* getStringValue(const char* name, const char* defVal="", Bool_t verbose=kFALSE) const ;
97 Bool_t setRealValue(const char* name, Double_t newVal=0, Bool_t verbose=kFALSE) ;
98 Bool_t setCatLabel(const char* name, const char* newVal="", Bool_t verbose=kFALSE) ;
99 Bool_t setCatIndex(const char* name, Int_t newVal=0, Bool_t verbose=kFALSE) ;
100 Bool_t setStringValue(const char* name, const char* newVal="", Bool_t verbose=kFALSE) ;
101
102 // Group operations on AbsArgs
103 void setAttribAll(const Text_t* name, Bool_t value=kTRUE) ;
104
105 // List search methods
106 RooAbsArg *find(const char *name) const ;
107 RooAbsArg *find(const RooAbsArg&) const ;
108
109 /// Check if collection contains an argument with the same name as var.
110 /// To check for a specific instance, use containsInstance().
111 Bool_t contains(const RooAbsArg& var) const {
112 return find(var) != nullptr;
113 }
114 /// Check if this exact instance is in this collection.
115 Bool_t containsInstance(const RooAbsArg& var) const {
116 return std::find(_list.begin(), _list.end(), &var) != _list.end();
117 }
118 RooAbsCollection* selectByAttrib(const char* name, Bool_t value) const ;
119 RooAbsCollection* selectCommon(const RooAbsCollection& refColl) const ;
120 RooAbsCollection* selectByName(const char* nameList, Bool_t verbose=kFALSE) const ;
121 Bool_t equals(const RooAbsCollection& otherColl) const ;
122 Bool_t overlaps(const RooAbsCollection& otherColl) const ;
123
124 /// TIterator-style iteration over contained elements.
125 /// \note These iterators are slow. Use begin() and end() or
126 /// range-based for loop instead.
128 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
129 // Create and return an iterator over the elements in this collection
130 return new RooLinkedListIter(makeLegacyIterator(dir));
131 }
132
133 /// TIterator-style iteration over contained elements.
134 /// \note This iterator is slow. Use begin() and end() or range-based for loop instead.
136 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
138 }
139
140 /// One-time forward iterator.
141 /// \note Use begin() and end() or range-based for loop instead.
143 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
145 }
146
148 return _list.begin();
149 }
150
152 return _list.end();
153 }
154
155 Storage_t::const_reverse_iterator rbegin() const {
156 return _list.rbegin();
157 }
158
159 Storage_t::const_reverse_iterator rend() const {
160 return _list.rend();
161 }
162
163 Storage_t::size_type size() const {
164 return _list.size();
165 }
166
167 bool empty() const {
168 return _list.empty();
169 }
170
171 void reserve(Storage_t::size_type count) {
172 _list.reserve(count);
173 }
174
175 /// Clear contents. If the collection is owning, it will also delete the contents.
176 void clear() {
177 removeAll();
178 }
179
180 inline Int_t getSize() const {
181 // Return the number of elements in the collection
182 return _list.size();
183 }
184
185 inline RooAbsArg *first() const {
186 // Return the first element in this collection
187 return _list.front();
188 }
189
190 RooAbsArg * operator[](Storage_t::size_type i) const {
191 return _list[i];
192 }
193
194
195 /// Returns index of given arg, or -1 if arg is not in the collection.
196 inline Int_t index(const RooAbsArg* arg) const {
197 auto item = std::find(_list.begin(), _list.end(), arg);
198 return item != _list.end() ? item - _list.begin() : -1;
199 }
200
201 /// Returns index of given arg, or -1 if arg is not in the collection.
202 inline Int_t index(const RooAbsArg& arg) const {
203 return index(&arg);
204 }
205
206 Int_t index(const char* name) const;
207
208 inline virtual void Print(Option_t *options= 0) const {
209 // Printing interface (human readable)
211 }
212 std::string contentsString() const ;
213
214
215 virtual void printName(std::ostream& os) const ;
216 virtual void printTitle(std::ostream& os) const ;
217 virtual void printClassName(std::ostream& os) const ;
218 virtual void printValue(std::ostream& os) const ;
219 virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
220
221 virtual Int_t defaultPrintContents(Option_t* opt) const ;
222
223 // Latex printing methods
224 void printLatex(const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(),
225 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
226 const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
227 const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) const ;
228 void printLatex(std::ostream& ofs, Int_t ncol, const char* option="NEYU", Int_t sigDigit=1,
229 const RooLinkedList& siblingLists=RooLinkedList(), const RooCmdArg* formatCmd=0) const ;
230
231 void setName(const char *name) {
232 // Set name of collection
233 _name= name;
234 }
235 const char* GetName() const {
236 // Return namer of collection
237 return _name.Data() ;
238 }
239 Bool_t isOwning() const {
240 // Does collection own contents?
241 return _ownCont ;
242 }
243
244 Bool_t allInRange(const char* rangeSpec) const ;
245
246 void dump() const ;
247
250
251 void sort(Bool_t reverse = false);
252
253 virtual void RecursiveRemove(TObject *obj);
254
255 void useHashMapForFind(bool flag) const;
256
257protected:
258 Storage_t _list; // Actual object storage
260
261 Bool_t _ownCont; // Flag to identify a list that owns its contents.
262 TString _name; // Our name.
263 Bool_t _allRRV ; // All contents are RRV
264
265 void safeDeleteList() ;
266
267 // Support for snapshot method
269
272
273 mutable TNamed* _structureTag{nullptr}; //! Structure tag
274 mutable TNamed* _typedStructureTag{nullptr}; //! Typed structure tag
275
277
278 void makeStructureTag() ;
279 void makeTypedStructureTag() ;
280
281private:
282 std::unique_ptr<LegacyIterator_t> makeLegacyIterator (bool forward = true) const;
283 mutable std::unique_ptr<std::unordered_map<const TNamed*, Storage_t::value_type>> _nameToItemMap; //!
285 void insert(RooAbsArg*);
286 RooAbsArg* tryFastFind(const TNamed* namePtr) const;
287
288 ClassDef(RooAbsCollection,3) // Collection of RooAbsArg objects
289};
290
291#endif
int Int_t
Definition: CPyCppyy.h:43
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition: RConfig.hxx:530
char Text_t
Definition: RtypesCore.h:60
const Bool_t kFALSE
Definition: RtypesCore.h:90
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
const Bool_t kTRUE
Definition: RtypesCore.h:89
const char Option_t
Definition: RtypesCore.h:64
#define ClassDef(name, id)
Definition: Rtypes.h:322
static void indent(ostringstream &buf, int indent_level)
const Bool_t kIterForward
Definition: TCollection.h:40
char name[80]
Definition: TGX11.cxx:109
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:73
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.
RooAbsArg * first() const
TNamed * typedStructureTag()
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.
bool empty() const
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.
TIterator * createIterator(Bool_t dir=kIterForward) const
TIterator-style iteration over contained elements.
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 TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
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) const =0
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
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...
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)
TNamed * structureTag()
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.
const char * GetName() const
Returns name of object.
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.
RooAbsArg * operator[](Storage_t::size_type i) const
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.
void insert(RooAbsArg *)
Insert an element into the owned collections.
virtual TObject * create(const char *newname) const =0
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:28
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 ...
Definition: RooLinkedList.h:35
RooPlotable is a 'mix-in' base class that define the standard RooFit plotting and printing methods.
Definition: RooPrintable.h:25
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:131
const char * Data() const
Definition: TString.h:364
for(Int_t i=0;i< n;i++)
Definition: legend1.C:18
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
Definition: NeuralNet.icc:546
static void output(int code)
Definition: gifencode.c:226