]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/muon/AliMergeableCollection.h
o small fix
[u/mrichter/AliRoot.git] / PWG / muon / AliMergeableCollection.h
CommitLineData
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
34class TMap;
35class AliMergeableCollectionIterator;
d440e2c5 36class TH1;
ac4edd2e 37
38class AliMergeableCollection : public TNamed
39{
40 friend class AliMergeableCollectionIterator; // our iterator class
41
42public:
43
44 AliMergeableCollection(const char* name="", const char* title="");
45 virtual ~AliMergeableCollection();
46
47 virtual AliMergeableCollection* Clone(const char* name="") const;
48
1b331634 49 Bool_t Attach(AliMergeableCollection* mc, const char* identifier, Bool_t pruneFirstIfAlreadyExists=kFALSE);
50
ac4edd2e 51 Bool_t Adopt(TObject* obj);
52 Bool_t Adopt(const char* identifier, TObject* obj);
53
54 virtual void Clear(Option_t *option="") { Delete(option); }
55
56 virtual TObject* FindObject(const char* fullIdentifier) const;
57
58 virtual TObject* FindObject(const TObject* object) const;
59
60 virtual void Delete(Option_t *option="");
61
62 virtual Int_t NumberOfObjects() const;
63
64 virtual Int_t NumberOfKeys() const;
65
66 TObject* GetObject(const char* fullIdentifier) const;
67 TObject* GetObject(const char* identifier, const char* objectName) const;
d440e2c5 68
69 TH1* Histo(const char* fullIdentifier) const;
70 TH1* Histo(const char* identifier, const char* objectName) const;
71
ac4edd2e 72 virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const;
73
74 virtual TList* CreateListOfKeys(Int_t index) const;
75
76 virtual TList* CreateListOfObjectNames(const char* identifier) const;
77
78 virtual TObject* Remove(const char* fullIdentifier);
79
d440e2c5 80 Int_t RemoveByType(const char* typeName);
81
ac4edd2e 82 TString GetKey(const char* identifier, Int_t index, Bool_t idContainsObjName = kFALSE) const;
83 TString GetIdentifier(const char* fullIdentifier) const;
84 TString GetObjectName(const char* fullIdentifier) const;
85
86 void Print(Option_t *option="") const;
87
88 void ClearMessages();
89 void PrintMessages(const char* prefix="") const;
90
91 Long64_t Merge(TCollection* list);
92
93 AliMergeableCollection* Project(const char* identifier) const;
94
95 UInt_t EstimateSize(Bool_t show=kFALSE) const;
96
97 /// Turn on the display of empty objects for the Print method
98 void ShowEmptyObjects(Bool_t show=kTRUE) {
99 fMustShowEmptyObject = show;
100 }
101
102 void PruneEmptyObjects();
103
1b331634 104 Int_t Prune(const char* identifier);
105
ac4edd2e 106 static Bool_t MergeObject(TObject* baseObject, TObject* objToAdd);
107
d5a197f5 108 TObject* GetSum(const char* idPattern) const;
ac4edd2e 109
110 Bool_t IsEmptyObject(TObject* obj) const;
111
112private:
113
114 AliMergeableCollection(const AliMergeableCollection& rhs);
115 AliMergeableCollection& operator=(const AliMergeableCollection& rhs);
116
d440e2c5 117 TH1* HistoWithAction(const char* identifier, TObject* o, const TString& action) const;
118
ac4edd2e 119 Bool_t InternalAdopt(const char* identifier, TObject* obj);
120
121 TString InternalDecode(const char* fullIdentifier, Int_t index) const;
122
d440e2c5 123 TObject* InternalObject(const char* identifier, const char* objectName) const;
ac4edd2e 124
d440e2c5 125public:
126 TObjArray* SortAllIdentifiers() const;
127
ac4edd2e 128 TString NormalizeName(const char* identifier, const char* action) const;
129
130 TMap* Map() const;
131
132private:
133
134 mutable TMap* fMap; /// map of TMap of THashList* of TObject*...
135 Bool_t fMustShowEmptyObject; /// Whether or not to show empty objects with the Print method
136 mutable Int_t fMapVersion; /// internal version of map (to avoid custom streamer...)
137 mutable std::map<std::string,int> fMessages; //! log messages
138
139 ClassDef(AliMergeableCollection,1) /// A collection of mergeable objects
140};
141
142class AliMergeableCollectionIterator : public TIterator
143{
144public:
145 virtual ~AliMergeableCollectionIterator();
146
147 AliMergeableCollectionIterator(const AliMergeableCollection* hcol, Bool_t direction=kIterForward);
148 AliMergeableCollectionIterator& operator=(const TIterator &rhs);
149
150 const TCollection *GetCollection() const { return 0x0; }
151
152 TObject* Next();
153
154 void Reset();
155
156private:
157 const AliMergeableCollection* fkMergeableCollection; // Mergeable objects collection being iterated
158 TIterator* fMapIterator; // Iterator for the internal map
159 TIterator* fHashListIterator; // Iterator for the current hash list
160 Bool_t fDirection; // forward or reverse
161
162 AliMergeableCollectionIterator() : fkMergeableCollection(0x0), fMapIterator(0x0), fHashListIterator(0x0), fDirection(kIterForward) {}
163
164 /// not implemented
165 AliMergeableCollectionIterator& operator=(const AliMergeableCollectionIterator &rhs);
166 /// not implemented
167 AliMergeableCollectionIterator(const AliMergeableCollectionIterator &iter);
168
169 ClassDef(AliMergeableCollectionIterator,0) // Mergeable object collection iterator
170};
171
172#endif