1 #ifndef ALIMERGEABLECOLLECTION_H
2 #define ALIMERGEABLECOLLECTION_H
4 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * See cxx source for full Copyright notice */
7 // $Id: AliMergeableCollection.h 50593 2011-07-14 17:42:28Z martinez $
9 ///////////////////////////////////////////////////////////////////////////////
11 /// AliMergeableCollection
13 /// Collection of mergeable objects, indexed by key-tuples
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
19 /// \author Diego Stocco
27 #ifndef ROOT_TCollection
28 # include "TCollection.h"
33 #include "Riostream.h"
38 class AliMergeableCollectionIterator;
43 class AliMergeableCollection : public TFolder
45 friend class AliMergeableCollectionIterator; // our iterator class
49 AliMergeableCollection(const char* name="", const char* title="");
50 virtual ~AliMergeableCollection();
52 virtual AliMergeableCollection* Clone(const char* name="") const;
54 Bool_t Attach(AliMergeableCollection* mc, const char* identifier, Bool_t pruneFirstIfAlreadyExists=kFALSE);
56 Bool_t Adopt(TObject* obj);
57 Bool_t Adopt(const char* identifier, TObject* obj);
59 virtual void Browse(TBrowser* b);
61 virtual void Clear(Option_t *option="") { Delete(option); }
63 virtual TObject* FindObject(const char* fullIdentifier) const;
65 virtual TObject* FindObject(const TObject* object) const;
67 virtual void Delete(Option_t *option="");
69 virtual Int_t NumberOfObjects() const;
71 virtual Int_t NumberOfKeys() const;
73 TObject* GetObject(const char* fullIdentifier) const;
74 TObject* GetObject(const char* identifier, const char* objectName) const;
76 TH1* Histo(const char* fullIdentifier) const;
77 TH1* Histo(const char* identifier, const char* objectName) const;
79 TH1* H1(const char* fullIdentifier) const { return Histo(fullIdentifier); }
80 TH1* H1(const char* identifier, const char* objectName) const { return Histo(identifier,objectName); }
82 TH2* H2(const char* fullIdentifier) const;
83 TH2* H2(const char* identifier, const char* objectName) const;
85 TProfile* Prof(const char* fullIdentifier) const;
86 TProfile* Prof(const char* identifier, const char* objectName) const;
88 virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const;
90 virtual TList* CreateListOfKeys(Int_t index) const;
92 virtual TList* CreateListOfObjectNames(const char* identifier) const;
94 using TFolder::Remove;
96 virtual TObject* Remove(const char* fullIdentifier);
98 Int_t RemoveByType(const char* typeName);
100 TString GetKey(const char* identifier, Int_t index, Bool_t idContainsObjName = kFALSE) const;
101 TString GetIdentifier(const char* fullIdentifier) const;
102 TString GetObjectName(const char* fullIdentifier) const;
104 void Print(Option_t *option="") const;
106 void ClearMessages();
107 void PrintMessages(const char* prefix="") const;
109 Long64_t Merge(TCollection* list);
111 AliMergeableCollection* Project(const char* identifier) const;
113 UInt_t EstimateSize(Bool_t show=kFALSE) const;
115 /// Turn on the display of empty objects for the Print method
116 void ShowEmptyObjects(Bool_t show=kTRUE) {
117 fMustShowEmptyObject = show;
120 void PruneEmptyObjects();
122 Int_t Prune(const char* identifier);
124 static Bool_t MergeObject(TObject* baseObject, TObject* objToAdd);
126 TObject* GetSum(const char* idPattern) const;
128 Bool_t IsEmptyObject(TObject* obj) const;
132 AliMergeableCollection(const AliMergeableCollection& rhs);
133 AliMergeableCollection& operator=(const AliMergeableCollection& rhs);
135 TH1* HistoWithAction(const char* identifier, TObject* o, const TString& action) const;
137 Bool_t InternalAdopt(const char* identifier, TObject* obj);
139 TString InternalDecode(const char* fullIdentifier, Int_t index) const;
141 TObject* InternalObject(const char* identifier, const char* objectName) const;
144 TObjArray* SortAllIdentifiers() const;
146 TString NormalizeName(const char* identifier, const char* action) const;
152 mutable TMap* fMap; /// map of TMap of THashList* of TObject*...
153 Bool_t fMustShowEmptyObject; /// Whether or not to show empty objects with the Print method
154 mutable Int_t fMapVersion; /// internal version of map (to avoid custom streamer...)
155 mutable std::map<std::string,int> fMessages; //! log messages
157 ClassDef(AliMergeableCollection,4) /// A collection of mergeable objects
160 class AliMergeableCollectionIterator : public TIterator
163 virtual ~AliMergeableCollectionIterator();
165 AliMergeableCollectionIterator(const AliMergeableCollection* hcol, Bool_t direction=kIterForward);
166 AliMergeableCollectionIterator& operator=(const TIterator &rhs);
168 const TCollection *GetCollection() const { return 0x0; }
175 const AliMergeableCollection* fkMergeableCollection; // Mergeable objects collection being iterated
176 TIterator* fMapIterator; // Iterator for the internal map
177 TIterator* fHashListIterator; // Iterator for the current hash list
178 Bool_t fDirection; // forward or reverse
180 AliMergeableCollectionIterator() : fkMergeableCollection(0x0), fMapIterator(0x0), fHashListIterator(0x0), fDirection(kIterForward) {}
183 AliMergeableCollectionIterator& operator=(const AliMergeableCollectionIterator &rhs);
185 AliMergeableCollectionIterator(const AliMergeableCollectionIterator &iter);
187 ClassDef(AliMergeableCollectionIterator,0) // Mergeable object collection iterator