Logo ROOT   6.10/09
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 "RooLinkedList.h"
23 #include "RooCmdArg.h"
24 #include "RooLinkedListIter.h"
25 #include <string>
26 
27 class RooAbsCollection : public TObject, public RooPrintable {
28 public:
29 
30  // Constructors, assignment etc.
32  RooAbsCollection(const char *name);
33  virtual TObject* clone(const char* newname) const = 0 ;
34  virtual TObject* create(const char* newname) const = 0 ;
35  virtual TObject* Clone(const char* newname=0) const {
36  return clone(newname?newname:GetName()) ;
37  }
38  virtual ~RooAbsCollection();
39 
40  // Create a copy of an existing list. New variables cannot be added
41  // to a copied list. The variables in the copied list are independent
42  // of the original variables.
43  RooAbsCollection(const RooAbsCollection& other, const char *name="");
46  void assignFast(const RooAbsCollection& other, Bool_t setValDirty=kTRUE) ;
47 
48  // Copy list and contents (and optionally 'deep' servers)
49  RooAbsCollection *snapshot(Bool_t deepCopy=kTRUE) const ;
51 
52  // Hash table control
54  // Set size of internal hash table to i (should be a prime number)
56  }
58  // Return size of internal hash table
59  return _list.getHashTableSize() ;
60  }
61 
62  // List content management
63  virtual Bool_t add(const RooAbsArg& var, Bool_t silent=kFALSE) ;
64  virtual Bool_t addOwned(RooAbsArg& var, Bool_t silent=kFALSE);
65  virtual RooAbsArg *addClone(const RooAbsArg& var, Bool_t silent=kFALSE) ;
66  virtual Bool_t replace(const RooAbsArg& var1, const RooAbsArg& var2) ;
67  virtual Bool_t remove(const RooAbsArg& var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
68  virtual void removeAll() ;
69 
70  virtual Bool_t add(const RooAbsCollection& list, Bool_t silent=kFALSE) ;
71  virtual Bool_t addOwned(const RooAbsCollection& list, Bool_t silent=kFALSE);
72  virtual void addClone(const RooAbsCollection& list, Bool_t silent=kFALSE);
73  Bool_t replace(const RooAbsCollection &other);
74  Bool_t remove(const RooAbsCollection& list, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE) ;
75 
76  // Group operations on AbsArgs
77  void setAttribAll(const Text_t* name, Bool_t value=kTRUE) ;
78 
79  // List search methods
80  RooAbsArg *find(const char *name) const ;
81  RooAbsArg *find(const RooAbsArg&) const ;
82 
83  Bool_t contains(const RooAbsArg& var) const {
84  // Returns true if object with same name as var is contained in this collection
85  return (0 == find(var)) ? kFALSE:kTRUE;
86  }
87  Bool_t containsInstance(const RooAbsArg& var) const {
88  // Returns true if var is contained in this collection
89  return (0 == _list.FindObject(&var)) ? kFALSE:kTRUE;
90  }
91  RooAbsCollection* selectByAttrib(const char* name, Bool_t value) const ;
92  RooAbsCollection* selectCommon(const RooAbsCollection& refColl) const ;
93  RooAbsCollection* selectByName(const char* nameList, Bool_t verbose=kFALSE) const ;
94  Bool_t equals(const RooAbsCollection& otherColl) const ;
95  Bool_t overlaps(const RooAbsCollection& otherColl) const ;
96 
97  // export subset of THashList interface
98  inline TIterator* createIterator(Bool_t dir = kIterForward) const {
99  // Create and return an iterator over the elements in this collection
100  return _list.MakeIterator(dir);
101  }
102 
104  RooFIter fwdIterator() const { return RooFIter(&_list); }
105 
106  inline Int_t getSize() const {
107  // Return the number of elements in the collection
108  return _list.GetSize();
109  }
110  inline RooAbsArg *first() const {
111  // Return the first element in this collection
112  return (RooAbsArg*)_list.First();
113  }
114 
115  inline virtual void Print(Option_t *options= 0) const {
116  // Printing interface (human readable)
118  }
119  std::string contentsString() const ;
120 
121 
122  virtual void printName(std::ostream& os) const ;
123  virtual void printTitle(std::ostream& os) const ;
124  virtual void printClassName(std::ostream& os) const ;
125  virtual void printValue(std::ostream& os) const ;
126  virtual void printMultiline(std::ostream& os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const ;
127 
128  virtual Int_t defaultPrintContents(Option_t* opt) const ;
129 
130  // Latex printing methods
131  void printLatex(const RooCmdArg& arg1=RooCmdArg(), const RooCmdArg& arg2=RooCmdArg(),
132  const RooCmdArg& arg3=RooCmdArg(), const RooCmdArg& arg4=RooCmdArg(),
133  const RooCmdArg& arg5=RooCmdArg(), const RooCmdArg& arg6=RooCmdArg(),
134  const RooCmdArg& arg7=RooCmdArg(), const RooCmdArg& arg8=RooCmdArg()) const ;
135  void printLatex(std::ostream& ofs, Int_t ncol, const char* option="NEYU", Int_t sigDigit=1,
136  const RooLinkedList& siblingLists=RooLinkedList(), const RooCmdArg* formatCmd=0) const ;
137 
138  void setName(const char *name) {
139  // Set name of collection
140  _name= name;
141  }
142  const char* GetName() const {
143  // Return namer of collection
144  return _name.Data() ;
145  }
146  Bool_t isOwning() const {
147  // Does collection own contents?
148  return _ownCont ;
149  }
150 
151  Bool_t allInRange(const char* rangeSpec) const ;
152 
153  void dump() const ;
154 
156  void takeOwnership() { _ownCont = kTRUE ; }
157 
158  void sort(Bool_t ascend=kTRUE) { _list.Sort(ascend) ; }
159 
160 protected:
161 
162  friend class RooMultiCatIter ;
163 
164  RooLinkedList _list ; // Actual object store
165 
166  Bool_t _ownCont; // Flag to identify a list that owns its contents.
167  TString _name; // Our name.
168  Bool_t _allRRV ; // All contents are RRV
169 
170  void safeDeleteList() ;
171 
172  // Support for snapshot method
174 
177 
178  mutable TNamed* _structureTag ; //! Structure tag
179  mutable TNamed* _typedStructureTag ; //! Typed structure tag
180 
181  inline void clearStructureTags() { _structureTag=0 ; _typedStructureTag = 0 ; }
182 
183  void makeStructureTag() ;
184  void makeTypedStructureTag() ;
185 
186 private:
187 
188  ClassDef(RooAbsCollection,2) // Collection of RooAbsArg objects
189 };
190 
191 #endif
TIterator * createIterator(Bool_t dir=kIterForward) const
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, which is interpreted as an OR of &#39;enum ContentsOptions&#39; values and in the style given by &#39;enum StyleOption&#39;.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
TObject * FindObject(const char *name) const
Return pointer to obejct with given name.
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.
RooAbsCollection()
Default constructor.
void sort(Bool_t ascend=kTRUE)
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
TNamed * typedStructureTag()
void setHashTableSize(Int_t size)
Change the threshold for hash-table use to given size.
const char Option_t
Definition: RtypesCore.h:62
RooAbsCollection * selectCommon(const RooAbsCollection &refColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Bool_t isOwning() const
virtual Bool_t replace(const RooAbsArg &var1, const RooAbsArg &var2)
Replace var1 with var2 and return kTRUE for success.
virtual void printValue(std::ostream &os) const
Print value of collection, i.e.
TNamed * structureTag()
Basic string class.
Definition: TString.h:129
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual ~RooAbsCollection()
Destructor.
Bool_t equals(const RooAbsCollection &otherColl) const
Check if this and other collection have identically named contents.
Int_t getHashTableSize() const
Definition: RooLinkedList.h:50
TObject * First() const
Definition: RooLinkedList.h:78
Int_t GetSize() const
Definition: RooLinkedList.h:60
Iterator abstract base class.
Definition: TIterator.h:30
void Sort(Bool_t ascend=kTRUE)
void safeDeleteList()
Examine client server dependencies in list and delete contents in safe order: any client is deleted b...
#define ClassDef(name, id)
Definition: Rtypes.h:297
RooPlotable is a &#39;mix-in&#39; base class that define the standard RooFit plotting and printing methods...
Definition: RooPrintable.h:25
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Bool_t allInRange(const char *rangeSpec) const
Return true if all contained object report to have their value inside the specified range...
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 Bool_t kIterForward
Definition: TCollection.h:37
void assignFast(const RooAbsCollection &other, Bool_t setValDirty=kTRUE)
Functional equivalent of operator=() but assumes this and other collection have same layout...
virtual TObject * clone(const char *newname) const =0
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
void clearStructureTags()
Typed structure tag.
Bool_t overlaps(const RooAbsCollection &otherColl) const
Check if this and other collection have common entries.
virtual void printName(std::ostream &os) const
Return collection name.
Int_t getSize() const
virtual Int_t defaultPrintContents(Option_t *opt) const
Define default RooPrinable print options for given Print() flag string For inline printing only show ...
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...
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
std::string contentsString() const
Return comma separated list of contained object names as STL string.
TNamed * _typedStructureTag
Structure tag.
RooAbsArg * first() const
bool verbose
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
static std::ostream & defaultPrintStream(std::ostream *os=0)
Return a reference to the current default stream to use in Print().
virtual void printClassName(std::ostream &os) const
Return collection class name.
RooAbsArg * find(const char *name) const
Find object with given name in list.
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...
RooFIter fwdIterator() const
virtual void printMultiline(std::ostream &os, Int_t contents, Bool_t verbose=kFALSE, TString indent="") const
Implement multiline printin of collection, one line for each ontained object showing the requested co...
virtual StyleOption defaultPrintStyle(Option_t *opt) const
RooLinkedList _list
const char * GetName() const
Returns name of object.
Mother of all ROOT objects.
Definition: TObject.h:37
RooAbsCollection is an abstract container object that can hold multiple RooAbsArg objects...
Bool_t containsInstance(const RooAbsArg &var) const
virtual void printTitle(std::ostream &os) const
Return collection title.
TIterator * MakeIterator(Bool_t dir=kTRUE) const
Return an iterator over this list.
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
void setName(const char *name)
Bool_t addServerClonesToList(const RooAbsArg &var)
Add clones of servers of given argument to list.
char Text_t
Definition: RtypesCore.h:58
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 contains(const RooAbsArg &var) const
RooAbsCollection & operator=(const RooAbsCollection &other)
The assignment operator sets the value of any argument in our set that also appears in the other set...
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
void setHashTableSize(Int_t i)
const Bool_t kTRUE
Definition: RtypesCore.h:91
Int_t getHashTableSize() const
RooLinkedListIter is the TIterator implementation for RooLinkedList.
RooMultiCatIter iterators over all state permutations of a list of categories.
virtual TObject * create(const char *newname) const =0
void dump() const
Base contents dumper for debugging purposes.
RooCmdArg is a named container for two doubles, two integers two object points and three string point...
Definition: RooCmdArg.h:27
const char * Data() const
Definition: TString.h:347