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"
30 #include "Riostream.h"
35 class AliMergeableCollectionIterator;
37 class AliMergeableCollection : public TNamed
39 friend class AliMergeableCollectionIterator; // our iterator class
43 AliMergeableCollection(const char* name="", const char* title="");
44 virtual ~AliMergeableCollection();
46 virtual AliMergeableCollection* Clone(const char* name="") const;
48 Bool_t Adopt(TObject* obj);
49 Bool_t Adopt(const char* identifier, TObject* obj);
51 virtual void Clear(Option_t *option="") { Delete(option); }
53 virtual TObject* FindObject(const char* fullIdentifier) const;
55 virtual TObject* FindObject(const TObject* object) const;
57 virtual void Delete(Option_t *option="");
59 virtual Int_t NumberOfObjects() const;
61 virtual Int_t NumberOfKeys() const;
63 TObject* GetObject(const char* fullIdentifier) const;
64 TObject* GetObject(const char* identifier, const char* objectName) const;
66 virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const;
68 virtual TList* CreateListOfKeys(Int_t index) const;
70 virtual TList* CreateListOfObjectNames(const char* identifier) const;
72 virtual TObject* Remove(const char* fullIdentifier);
74 TString GetKey(const char* identifier, Int_t index, Bool_t idContainsObjName = kFALSE) const;
75 TString GetIdentifier(const char* fullIdentifier) const;
76 TString GetObjectName(const char* fullIdentifier) const;
78 void Print(Option_t *option="") const;
81 void PrintMessages(const char* prefix="") const;
83 Long64_t Merge(TCollection* list);
85 AliMergeableCollection* Project(const char* identifier) const;
87 UInt_t EstimateSize(Bool_t show=kFALSE) const;
89 /// Turn on the display of empty objects for the Print method
90 void ShowEmptyObjects(Bool_t show=kTRUE) {
91 fMustShowEmptyObject = show;
94 void PruneEmptyObjects();
96 static Bool_t MergeObject(TObject* baseObject, TObject* objToAdd);
98 TObject* GetSum(const char* idPattern);
100 Bool_t IsEmptyObject(TObject* obj) const;
104 AliMergeableCollection(const AliMergeableCollection& rhs);
105 AliMergeableCollection& operator=(const AliMergeableCollection& rhs);
107 Bool_t InternalAdopt(const char* identifier, TObject* obj);
109 TString InternalDecode(const char* fullIdentifier, Int_t index) const;
111 TObject* InternalObject(const char* identifier, const char* objectName) const;
112 TObjArray* SortAllIdentifiers() const;
114 TString NormalizeName(const char* identifier, const char* action) const;
120 mutable TMap* fMap; /// map of TMap of THashList* of TObject*...
121 Bool_t fMustShowEmptyObject; /// Whether or not to show empty objects with the Print method
122 mutable Int_t fMapVersion; /// internal version of map (to avoid custom streamer...)
123 mutable std::map<std::string,int> fMessages; //! log messages
125 ClassDef(AliMergeableCollection,1) /// A collection of mergeable objects
128 class AliMergeableCollectionIterator : public TIterator
131 virtual ~AliMergeableCollectionIterator();
133 AliMergeableCollectionIterator(const AliMergeableCollection* hcol, Bool_t direction=kIterForward);
134 AliMergeableCollectionIterator& operator=(const TIterator &rhs);
136 const TCollection *GetCollection() const { return 0x0; }
143 const AliMergeableCollection* fkMergeableCollection; // Mergeable objects collection being iterated
144 TIterator* fMapIterator; // Iterator for the internal map
145 TIterator* fHashListIterator; // Iterator for the current hash list
146 Bool_t fDirection; // forward or reverse
148 AliMergeableCollectionIterator() : fkMergeableCollection(0x0), fMapIterator(0x0), fHashListIterator(0x0), fDirection(kIterForward) {}
151 AliMergeableCollectionIterator& operator=(const AliMergeableCollectionIterator &rhs);
153 AliMergeableCollectionIterator(const AliMergeableCollectionIterator &iter);
155 ClassDef(AliMergeableCollectionIterator,0) // Mergeable object collection iterator