Line data Source code
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 :
9 : ///////////////////////////////////////////////////////////////////////////////
10 : ///
11 : /// AliMergeableCollection
12 : ///
13 : /// Collection of mergeable objects, indexed by key-tuples
14 : ///
15 : /// Important point is that AliMergeableCollection is *always* the
16 : /// owner of the objects it holds. This is why you should not
17 : /// use the (inherited from TCollection) Add() method but the Adopt() methods
18 : ///
19 : /// \author Diego Stocco
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;
29 : class AliMergeableCollectionIterator;
30 : class AliMergeableCollectionProxy;
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 0 : 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 0 : TH1* H1(const char* fullIdentifier) const { return Histo(fullIdentifier); }
75 0 : 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 :
112 : /// Turn on the display of empty objects for the Print method
113 : void ShowEmptyObjects(Bool_t show=kTRUE) {
114 0 : fMustShowEmptyObject = show;
115 0 : }
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 :
131 : AliMergeableCollection(const AliMergeableCollection& rhs);
132 : AliMergeableCollection& operator=(const AliMergeableCollection& rhs);
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; /// map of TMap of THashList* of TObject*...
152 : Bool_t fMustShowEmptyObject; /// Whether or not to show empty objects with the Print method
153 : mutable Int_t fMapVersion; /// internal version of map (to avoid custom streamer...)
154 : mutable std::map<std::string,int> fMessages; //! log messages
155 :
156 176 : ClassDef(AliMergeableCollection,4) /// A collection of mergeable objects
157 : };
158 :
159 : class AliMergeableCollectionIterator : public TIterator
160 : {
161 : public:
162 : virtual ~AliMergeableCollectionIterator();
163 :
164 : AliMergeableCollectionIterator(const AliMergeableCollection* hcol, Bool_t direction=kIterForward);
165 : AliMergeableCollectionIterator& operator=(const TIterator &rhs);
166 :
167 0 : 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 :
181 : /// not implemented
182 : AliMergeableCollectionIterator& operator=(const AliMergeableCollectionIterator &rhs);
183 : /// not implemented
184 : AliMergeableCollectionIterator(const AliMergeableCollectionIterator &iter);
185 :
186 176 : ClassDef(AliMergeableCollectionIterator,0) // Mergeable object collection iterator
187 : };
188 :
189 0 : class AliMergeableCollectionProxy : public TFolder
190 : {
191 : friend class AliMergeableCollection;
192 :
193 : protected:
194 : AliMergeableCollectionProxy(AliMergeableCollection& oc, THashList& list);
195 :
196 : public:
197 :
198 : TObject* GetObject(const char* objectName) const;
199 :
200 : TH1* Histo(const char* objectName) const;
201 :
202 0 : 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:
217 : AliMergeableCollection& fOC;
218 : THashList& fList;
219 :
220 176 : ClassDef(AliMergeableCollectionProxy,0) // Mergeable object collection proxy
221 :
222 : };
223 :
224 : #endif
|