]>
Commit | Line | Data |
---|---|---|
ac4edd2e | 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 | #ifndef ROOT_TNamed | |
22 | # include "TNamed.h" | |
23 | #endif | |
24 | #ifndef ROOT_TString | |
25 | # include "TString.h" | |
26 | #endif | |
27 | #ifndef ROOT_TCollection | |
28 | # include "TCollection.h" | |
29 | #endif | |
30 | #include "Riostream.h" | |
31 | #include <map> | |
32 | #include <string> | |
33 | ||
34 | class TMap; | |
35 | class AliMergeableCollectionIterator; | |
36 | ||
37 | class AliMergeableCollection : public TNamed | |
38 | { | |
39 | friend class AliMergeableCollectionIterator; // our iterator class | |
40 | ||
41 | public: | |
42 | ||
43 | AliMergeableCollection(const char* name="", const char* title=""); | |
44 | virtual ~AliMergeableCollection(); | |
45 | ||
46 | virtual AliMergeableCollection* Clone(const char* name="") const; | |
47 | ||
48 | Bool_t Adopt(TObject* obj); | |
49 | Bool_t Adopt(const char* identifier, TObject* obj); | |
50 | ||
51 | virtual void Clear(Option_t *option="") { Delete(option); } | |
52 | ||
53 | virtual TObject* FindObject(const char* fullIdentifier) const; | |
54 | ||
55 | virtual TObject* FindObject(const TObject* object) const; | |
56 | ||
57 | virtual void Delete(Option_t *option=""); | |
58 | ||
59 | virtual Int_t NumberOfObjects() const; | |
60 | ||
61 | virtual Int_t NumberOfKeys() const; | |
62 | ||
63 | TObject* GetObject(const char* fullIdentifier) const; | |
64 | TObject* GetObject(const char* identifier, const char* objectName) const; | |
65 | ||
66 | virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const; | |
67 | ||
68 | virtual TList* CreateListOfKeys(Int_t index) const; | |
69 | ||
70 | virtual TList* CreateListOfObjectNames(const char* identifier) const; | |
71 | ||
72 | virtual TObject* Remove(const char* fullIdentifier); | |
73 | ||
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; | |
77 | ||
78 | void Print(Option_t *option="") const; | |
79 | ||
80 | void ClearMessages(); | |
81 | void PrintMessages(const char* prefix="") const; | |
82 | ||
83 | Long64_t Merge(TCollection* list); | |
84 | ||
85 | AliMergeableCollection* Project(const char* identifier) const; | |
86 | ||
87 | UInt_t EstimateSize(Bool_t show=kFALSE) const; | |
88 | ||
89 | /// Turn on the display of empty objects for the Print method | |
90 | void ShowEmptyObjects(Bool_t show=kTRUE) { | |
91 | fMustShowEmptyObject = show; | |
92 | } | |
93 | ||
94 | void PruneEmptyObjects(); | |
95 | ||
96 | static Bool_t MergeObject(TObject* baseObject, TObject* objToAdd); | |
97 | ||
98 | TObject* GetSum(const char* idPattern); | |
99 | ||
100 | Bool_t IsEmptyObject(TObject* obj) const; | |
101 | ||
102 | private: | |
103 | ||
104 | AliMergeableCollection(const AliMergeableCollection& rhs); | |
105 | AliMergeableCollection& operator=(const AliMergeableCollection& rhs); | |
106 | ||
107 | Bool_t InternalAdopt(const char* identifier, TObject* obj); | |
108 | ||
109 | TString InternalDecode(const char* fullIdentifier, Int_t index) const; | |
110 | ||
111 | TObject* InternalObject(const char* identifier, const char* objectName) const; | |
112 | TObjArray* SortAllIdentifiers() const; | |
113 | ||
114 | TString NormalizeName(const char* identifier, const char* action) const; | |
115 | ||
116 | TMap* Map() const; | |
117 | ||
118 | private: | |
119 | ||
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 | |
124 | ||
125 | ClassDef(AliMergeableCollection,1) /// A collection of mergeable objects | |
126 | }; | |
127 | ||
128 | class AliMergeableCollectionIterator : public TIterator | |
129 | { | |
130 | public: | |
131 | virtual ~AliMergeableCollectionIterator(); | |
132 | ||
133 | AliMergeableCollectionIterator(const AliMergeableCollection* hcol, Bool_t direction=kIterForward); | |
134 | AliMergeableCollectionIterator& operator=(const TIterator &rhs); | |
135 | ||
136 | const TCollection *GetCollection() const { return 0x0; } | |
137 | ||
138 | TObject* Next(); | |
139 | ||
140 | void Reset(); | |
141 | ||
142 | private: | |
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 | |
147 | ||
148 | AliMergeableCollectionIterator() : fkMergeableCollection(0x0), fMapIterator(0x0), fHashListIterator(0x0), fDirection(kIterForward) {} | |
149 | ||
150 | /// not implemented | |
151 | AliMergeableCollectionIterator& operator=(const AliMergeableCollectionIterator &rhs); | |
152 | /// not implemented | |
153 | AliMergeableCollectionIterator(const AliMergeableCollectionIterator &iter); | |
154 | ||
155 | ClassDef(AliMergeableCollectionIterator,0) // Mergeable object collection iterator | |
156 | }; | |
157 | ||
158 | #endif |