Logo ROOT   6.18/05
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
26class RooCmdArg;
27
28class RooAbsCollection : public TObject, public RooPrintable {
29public:
30 using Storage_t = std::vector<RooAbsArg*>;
31 using const_iterator = Storage_t::const_iterator;
32
33
34 // Constructors, assignment etc.
36 RooAbsCollection(const char *name);
37 virtual TObject* clone(const char* newname) const = 0 ;
38 virtual TObject* create(const char* newname) const = 0 ;
39 virtual TObject* Clone(const char* newname=0) const {
40 return clone(newname?newname:GetName()) ;
41 }
42 virtual ~RooAbsCollection();
43
44 // Create a copy of an existing list. New variables cannot be added
45 // to a copied list. The variables in the copied list are independent
46 // of the original variables.
47 RooAbsCollection(const RooAbsCollection& other, const char *name="");
50 void assignFast(const RooAbsCollection& other, Bool_t setValDirty=kTRUE) ;
51
52 // Copy list and contents (and optionally 'deep' servers)
53 RooAbsCollection *snapshot(Bool_t deepCopy=kTRUE) const ;
55
56 /// \deprecated Without effect.
58 // Set size of internal hash table to i (should be a prime number)
59 }
60 /// \deprecated Without effect.
62 return 0;
63 }
64
65 // List content management
66 virtual Bool_t add(const RooAbsArg& var, Bool_t silent=kFALSE) ;
67 virtual Bool_t addOwned(RooAbsArg& var, Bool_t silent=kFALSE);
68 virtual RooAbsArg *addClone(const RooAbsArg& var, Bool_t silent=kFALSE) ;
69 virtual Bool_t replace(const RooAbsArg& var1, const RooAbsArg& var2) ;
70 virtual Bool_t remove(const RooAbsArg& var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
71 virtual void removeAll() ;
72
73 virtual Bool_t add(const RooAbsCollection& list, Bool_t silent=kFALSE) ;
74 virtual Bool_t addOwned(const RooAbsCollection& list, Bool_t silent=kFALSE);
75 virtual void addClone(const RooAbsCollection& list, Bool_t silent=kFALSE);
76 Bool_t replace(const RooAbsCollection &other);
77 Bool_t remove(const RooAbsCollection& list, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
78 template<class forwardIt>
79 void remove(forwardIt rangeBegin, forwardIt rangeEnd, Bool_t silent = kFALSE, Bool_t matchByNameOnly = kFALSE) {
80 for (forwardIt it = rangeBegin; it != rangeEnd; ++it) {
81 static_assert(std::is_same<
82 typename std::iterator_traits<forwardIt>::value_type,
83 RooAbsArg*>::value, "Can only remove lists of RooAbsArg*.");
84 auto castedElm = static_cast<RooAbsArg*>(*it);
85 remove(*castedElm, silent, matchByNameOnly);
86 }
87 }
88
89 // Group operations on AbsArgs
90 void setAttribAll(const Text_t* name, Bool_t value=kTRUE) ;
91
92 // List search methods
93 RooAbsArg *find(const char *name) const ;
94 RooAbsArg *find(const RooAbsArg&) const ;
95
96 Bool_t contains(const RooAbsArg& var) const {
97 // Returns true if object with same name as var is contained in this collection
98 return (0 == find(var)) ? kFALSE:kTRUE;
99 }
100 Bool_t containsInstance(const RooAbsArg& var) const {
101 // Returns true if var is contained in this collection
102 return std::find(_list.begin(), _list.end(), &var) != _list.end();
103 }
104 RooAbsCollection* selectByAttrib(const char* name, Bool_t value) const ;
105 RooAbsCollection* selectCommon(const RooAbsCollection& refColl) const ;
106 RooAbsCollection* selectByName(const char* nameList, Bool_t verbose=kFALSE) const ;
107 Bool_t equals(const RooAbsCollection& otherColl) const ;
108 Bool_t overlaps(const RooAbsCollection& otherColl) const ;
109
110 /// TIterator-style iteration over contained elements.
111 /// \note These iterators are slow. Use begin() and end() or
112 /// range-based for loop instead.
114 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
115 // Create and return an iterator over the elements in this collection
116 return new RooLinkedListIter(makeLegacyIterator(dir));
117 }
118
119 /// TIterator-style iteration over contained elements.
120 /// \note This iterator is slow. Use begin() and end() or range-based for loop instead.
122 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
124 }
125
126 /// One-time forward iterator.
127 /// \note Use begin() and end() or range-based for loop instead.
129 R__SUGGEST_ALTERNATIVE("begin(), end() and range-based for loops.") {
131 }
132
134 return _list.begin();
135 }
136
138 return _list.end();
139 }
140
141 Storage_t::size_type size() const {
142 return _list.size();
143 }
144
145 bool empty() const {
146 return _list.empty();
147 }
148
149 void reserve(Storage_t::size_type count) {
150 _list.reserve(count);
151 }
152
153 inline Int_t getSize() const {
154 // Return the number of elements in the collection
155 return _list.size();
156 }
157
158 inline RooAbsArg *first() const {
159 // Return the first element in this collection
160 return _list.front();
161 }
162
163 RooAbsArg * operator[](Storage_t::size_type i) const {
164 return _list[i];
165 }
166
167 inline virtual void Print(Option_t *options= 0) const {
168 // Printing interface (human readable)
170 }
171 std::string contentsString() const ;
172
173
174 virtual void printName(std::ostream& os) const ;
175 virtual void printTitle(std::ostream& os) const ;
176 virtual void printClassName(std::ostream& os) const ;
177 virtual void printValue(std::ostream& os) const ;
178 virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
179
180 virtual Int_t defaultPrintContents(Option_t* opt) const ;
181
182 // Latex printing methods
183 void printLatex(const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(),
184 const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
185 const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
186 const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) const ;
187 void printLatex(std::ostream& ofs, Int_t ncol, const char* option="NEYU", Int_t sigDigit=1,
188 const RooLinkedList& siblingLists=RooLinkedList(), const RooCmdArg* formatCmd=0) const ;
189
190 void setName(const char *name) {
191 // Set name of collection
192 _name= name;
193 }
194 const char* GetName() const {
195 // Return namer of collection
196 return _name.Data() ;
197 }
198 Bool_t isOwning() const {
199 // Does collection own contents?
200 return _ownCont ;
201 }
202
203 Bool_t allInRange(const char* rangeSpec) const ;
204
205 void dump() const ;
206
209
210 void sort(Bool_t reverse = false);
211
212 virtual void RecursiveRemove(TObject *obj);
213
214protected:
215
216 friend class RooMultiCatIter ;
217
218 Storage_t _list; // Actual object storage
220
221 Bool_t _ownCont; // Flag to identify a list that owns its contents.
222 TString _name; // Our name.
223 Bool_t _allRRV ; // All contents are RRV
224
225 void safeDeleteList() ;
226
227 // Support for snapshot method
229
232
233 mutable TNamed* _structureTag{nullptr}; //! Structure tag
234 mutable TNamed* _typedStructureTag{nullptr}; //! Typed structure tag
235
237
238 void makeStructureTag() ;
239 void makeTypedStructureTag() ;
240
241private:
242 std::unique_ptr<LegacyIterator_t> makeLegacyIterator (bool forward = true) const;
243
244 ClassDef(RooAbsCollection,3) // Collection of RooAbsArg objects
245};
246
247#endif
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition: RConfig.hxx:530
int Int_t
Definition: RtypesCore.h:41
char Text_t
Definition: RtypesCore.h:58
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:326
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:70
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects.
RooFIter fwdIterator() const R__SUGGEST_ALTERNATIVE("begin()
One-time forward iterator.
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
std::vector< RooAbsArg * > Storage_t
TNamed * _typedStructureTag
Structure tag.
void setHashTableSize(Int_t)
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
virtual TObject * create(const char *newname) const =0
TNamed * typedStructureTag()
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.
Int_t getSize() const
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
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.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
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 TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
TNamed * structureTag()
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
const_iterator end() const
virtual ~RooAbsCollection()
Destructor.
Storage_t::size_type size() const
RooAbsArg * operator[](Storage_t::size_type i) const
RooAbsArg * first() const
RooLinkedListIter iterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
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 ...
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 ...
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.
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...
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...
const char * GetName() const
Returns name of object.
virtual void printClassName(std::ostream &os) const
Return collection class name.
std::string contentsString() const
Return comma separated list of contained object names as STL string.
TIterator * createIterator(Bool_t dir=kIterForward) const R__SUGGEST_ALTERNATIVE("begin()
TIterator-style iteration over contained elements.
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
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
TIterator end() and range-based for loops.")
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 ...
Definition: RooLinkedList.h:36
RooMultiCatIter iterators over all state permutations of a list of categories.
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:544
static void output(int code)
Definition: gifencode.c:226