AliRoot Core  3dc7879 (3dc7879)
AliMergeableCollection.h
Go to the documentation of this file.
1 #ifndef ALIMERGEABLECOLLECTION_H
2 #define ALIMERGEABLECOLLECTION_H
3 
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
6 
7 // $Id: AliMergeableCollection.h 50593 2011-07-14 17:42:28Z martinez $
8 
20 
21 #include "TString.h"
22 #include "TFolder.h"
23 #include "TIterator.h"
24 #include "TCollection.h"
25 #include <map>
26 #include <string>
27 
28 class TMap;
31 class TH1;
32 class TH2;
33 class TProfile;
34 class THashList;
35 class TCollection;
36 
37 class AliMergeableCollection : public TFolder
38 {
39  friend class AliMergeableCollectionIterator; // our iterator class
40  friend class AliMergeableCollectionProxy; // out proxy class
41 
42 public:
43 
44  AliMergeableCollection(const char* name="", const char* title="");
45  virtual ~AliMergeableCollection();
46 
47  virtual AliMergeableCollection* Clone(const char* name="") const;
48 
49  Bool_t Attach(AliMergeableCollection* mc, const char* identifier, Bool_t pruneFirstIfAlreadyExists=kFALSE);
50 
51  Bool_t Adopt(TObject* obj);
52  Bool_t Adopt(const char* identifier, TObject* obj);
53 
54  virtual void Browse(TBrowser* b);
55 
56  virtual void Clear(Option_t *option="") { Delete(option); }
57 
58  virtual TObject* FindObject(const char* fullIdentifier) const;
59 
60  virtual TObject* FindObject(const TObject* object) const;
61 
62  virtual void Delete(Option_t *option="");
63 
64  virtual Int_t NumberOfObjects() const;
65 
66  virtual Int_t NumberOfKeys() const;
67 
68  TObject* GetObject(const char* fullIdentifier) const;
69  TObject* GetObject(const char* identifier, const char* objectName) const;
70 
71  TH1* Histo(const char* fullIdentifier) const;
72  TH1* Histo(const char* identifier, const char* objectName) const;
73 
74  TH1* H1(const char* fullIdentifier) const { return Histo(fullIdentifier); }
75  TH1* H1(const char* identifier, const char* objectName) const { return Histo(identifier,objectName); }
76 
77  TH2* H2(const char* fullIdentifier) const;
78  TH2* H2(const char* identifier, const char* objectName) const;
79 
80  TProfile* Prof(const char* fullIdentifier) const;
81  TProfile* Prof(const char* identifier, const char* objectName) const;
82 
83  virtual AliMergeableCollectionProxy* CreateProxy(const char* identifier, Bool_t createIfNeeded=kFALSE);
84 
85  virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const;
86 
87  virtual TList* CreateListOfKeys(Int_t index) const;
88 
89  virtual TList* CreateListOfObjectNames(const char* identifier) const;
90 
91  using TFolder::Remove;
92 
93  virtual TObject* Remove(const char* fullIdentifier);
94 
95  Int_t RemoveByType(const char* typeName);
96 
97  TString GetKey(const char* identifier, Int_t index, Bool_t idContainsObjName = kFALSE) const;
98  TString GetIdentifier(const char* fullIdentifier) const;
99  TString GetObjectName(const char* fullIdentifier) const;
100 
101  void Print(Option_t *option="") const;
102 
103  void ClearMessages();
104  void PrintMessages(const char* prefix="") const;
105 
106  Long64_t Merge(TCollection* list);
107 
108  AliMergeableCollection* Project(const char* identifier) const;
109 
110  UInt_t EstimateSize(Bool_t show=kFALSE) const;
111 
113  void ShowEmptyObjects(Bool_t show=kTRUE) {
114  fMustShowEmptyObject = show;
115  }
116 
117  void PruneEmptyObjects();
118 
119  Int_t Prune(const char* identifier);
120 
121  static Bool_t MergeObject(TObject* baseObject, TObject* objToAdd);
122 
123  TObject* GetSum(const char* idPattern) const;
124 
125  Bool_t IsEmptyObject(TObject* obj) const;
126 
127  static void CorrectIdentifier(TString& sidentifier);
128 
129 private:
130 
133 
134  TH1* HistoWithAction(const char* identifier, TObject* o, const TString& action) const;
135 
136  Bool_t InternalAdopt(const char* identifier, TObject* obj);
137 
138  TString InternalDecode(const char* fullIdentifier, Int_t index) const;
139 
140  TObject* InternalObject(const char* identifier, const char* objectName) const;
141 
142 public:
143  TObjArray* SortAllIdentifiers() const;
144 
145  TString NormalizeName(const char* identifier, const char* action) const;
146 
147  TMap* Map() const;
148 
149 private:
150 
151  mutable TMap* fMap;
153  mutable Int_t fMapVersion;
154  mutable std::map<std::string,int> fMessages;
155 
156  ClassDef(AliMergeableCollection,4)
157 };
158 
159 class AliMergeableCollectionIterator : public TIterator
160 {
161 public:
163 
164  AliMergeableCollectionIterator(const AliMergeableCollection* hcol, Bool_t direction=kIterForward);
165  AliMergeableCollectionIterator& operator=(const TIterator &rhs);
166 
167  const TCollection *GetCollection() const { return 0x0; }
168 
169  TObject* Next();
170 
171  void Reset();
172 
173 private:
174  const AliMergeableCollection* fkMergeableCollection; // Mergeable objects collection being iterated
175  TIterator* fMapIterator; // Iterator for the internal map
176  TIterator* fHashListIterator; // Iterator for the current hash list
177  Bool_t fDirection; // forward or reverse
178 
179  AliMergeableCollectionIterator() : fkMergeableCollection(0x0), fMapIterator(0x0), fHashListIterator(0x0), fDirection(kIterForward) {}
180 
185 
186  ClassDef(AliMergeableCollectionIterator,0) // Mergeable object collection iterator
187 };
188 
189 class AliMergeableCollectionProxy : public TFolder
190 {
192 
193 protected:
195 
196 public:
197 
198  TObject* GetObject(const char* objectName) const;
199 
200  TH1* Histo(const char* objectName) const;
201 
202  TH1* H1(const char* objectName) const { return Histo(objectName); }
203 
204  TH2* H2(const char* objectName) const;
205 
206  TProfile* Prof(const char* objectName) const;
207 
208  void Print(Option_t* opt="") const;
209 
210  Bool_t Adopt(TObject* obj);
211 
212  Bool_t Adopt(const char* identifier, TObject* obj);
213 
214  virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const;
215 
216 private:
218  THashList& fList;
219 
220  ClassDef(AliMergeableCollectionProxy,0) // Mergeable object collection proxy
221 
222 };
223 
224 #endif
TBrowser b
Definition: RunAnaESD.C:12
TH1 * H1(const char *fullIdentifier) const
Int_t RemoveByType(const char *typeName)
AliMergeableCollection(const char *name="", const char *title="")
Long64_t Merge(TCollection *list)
TString InternalDecode(const char *fullIdentifier, Int_t index) const
virtual TList * CreateListOfKeys(Int_t index) const
TObjArray * SortAllIdentifiers() const
#define TObjArray
TString GetObjectName(const char *fullIdentifier) const
TH1 * H1(const char *objectName) const
void ShowEmptyObjects(Bool_t show=kTRUE)
Turn on the display of empty objects for the Print method.
TObject * InternalObject(const char *identifier, const char *objectName) const
static Bool_t MergeObject(TObject *baseObject, TObject *objToAdd)
TH1 * Histo(const char *fullIdentifier) const
TH2 * H2(const char *fullIdentifier) const
virtual void Delete(Option_t *option="")
void PrintMessages(const char *prefix="") const
virtual AliMergeableCollection * Clone(const char *name="") const
friend class AliMergeableCollectionIterator
virtual TObject * Remove(const char *fullIdentifier)
virtual AliMergeableCollectionProxy * CreateProxy(const char *identifier, Bool_t createIfNeeded=kFALSE)
void Print(Option_t *option="") const
std::map< std::string, int > fMessages
internal version of map (to avoid custom streamer...)
TString GetKey(const char *identifier, Int_t index, Bool_t idContainsObjName=kFALSE) const
TObject * GetObject(const char *fullIdentifier) const
char * prefix
Int_t fMapVersion
Whether or not to show empty objects with the Print method.
static void CorrectIdentifier(TString &sidentifier)
TH1 * H1(const char *identifier, const char *objectName) const
TString NormalizeName(const char *identifier, const char *action) const
virtual TList * CreateListOfObjectNames(const char *identifier) const
virtual Int_t NumberOfObjects() const
virtual void Browse(TBrowser *b)
Int_t Prune(const char *identifier)
UInt_t EstimateSize(Bool_t show=kFALSE) const
AliMergeableCollection & fOC
TProfile * Prof(const char *fullIdentifier) const
virtual void Clear(Option_t *option="")
virtual Int_t NumberOfKeys() const
AliMergeableCollection & operator=(const AliMergeableCollection &rhs)
TString GetIdentifier(const char *fullIdentifier) const
Bool_t InternalAdopt(const char *identifier, TObject *obj)
friend class AliMergeableCollectionProxy
virtual TIterator * CreateIterator(Bool_t dir=kIterForward) const
const TCollection * GetCollection() const
TH1 * HistoWithAction(const char *identifier, TObject *o, const TString &action) const
AliMergeableCollection * Project(const char *identifier) const
Bool_t Attach(AliMergeableCollection *mc, const char *identifier, Bool_t pruneFirstIfAlreadyExists=kFALSE)
Bool_t fMustShowEmptyObject
map of TMap of THashList* of TObject*...
virtual TObject * FindObject(const char *fullIdentifier) const
TObject * GetSum(const char *idPattern) const
const AliMergeableCollection * fkMergeableCollection
Bool_t IsEmptyObject(TObject *obj) const