]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/muon/AliHistogramCollection.h
Coverity fixes (Diego)
[u/mrichter/AliRoot.git] / PWG / muon / AliHistogramCollection.h
1 #ifndef ALIHISTOGRAMCOLLECTION_H
2 #define ALIHISTOGRAMCOLLECTION_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$
8
9 ///////////////////////////////////////////////////////////////////////////////
10 ///
11 /// AliHistogramCollection
12 ///
13 /// Collection of histograms, indexed by key-tuples
14 ///
15 /// Important point is that AliHistogramCollection is *always* the
16 /// owner of the histograms it holds. This is why you should not
17 /// use the (inherited from TCollection) Add() method but the Adopt() methods
18 ///
19 /// \author Laurent Aphecetche
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 <map>
31 #include <string>
32
33 class TH1;
34 class TMap;
35 class AliHistogramCollectionIterator;
36
37 class AliHistogramCollection : public TNamed
38 {
39   friend class AliHistogramCollectionIterator; // our iterator class
40
41 public:
42
43   AliHistogramCollection(const char* name="", const char* title="");
44   virtual ~AliHistogramCollection();
45
46   virtual AliHistogramCollection* Clone(const char* name="") const;
47   
48   Bool_t Adopt(TH1* histo);
49   Bool_t Adopt(const char* keyA, TH1* histo);
50   Bool_t Adopt(const char* keyA, const char* keyB, TH1* histo);
51   Bool_t Adopt(const char* keyA, const char* keyB, const char* keyC, TH1* histo);
52   Bool_t Adopt(const char* keyA, const char* keyB, const char* keyC, const char* keyD, TH1* histo);
53     
54   virtual void Clear(Option_t *option="") { Delete(option); }
55   
56   virtual TObject* FindObject(const char* identifier) const;
57
58   virtual TObject* FindObject(const TObject* key) const;
59
60   virtual void Delete(Option_t *option="");
61   
62   virtual Int_t NumberOfHistograms() const;
63
64   virtual Int_t NumberOfKeys() const;
65
66   TH1* Histo(const char* identifier) const;
67   TH1* Histo(const char* keyA, const char* histoname) const;
68   TH1* Histo(const char* keyA, const char* keyB, const char* histoname) const;
69   TH1* Histo(const char* keyA, const char* keyB, const char* keyC, const char* histoname) const;
70   TH1* Histo(const char* keyA, const char* keyB, const char* keyC, const char* keyD, const char* histoname) const;
71   
72   virtual TIterator* CreateIterator(Bool_t dir = kIterForward) const;
73   
74   virtual TObject* Remove(TObject *obj);
75
76   TString KeyA(const char* identifier) const;
77   TString KeyB(const char* identifier) const;
78   TString KeyC(const char* identifier) const;
79   TString KeyD(const char* identifier) const;
80   TString HistoName(const char* identifier) const;
81   
82   void Print(Option_t *option="") const;
83   
84   void ClearMessages();
85   void PrintMessages(const char* prefix="") const;
86   
87   Long64_t Merge(TCollection* list);
88   
89   AliHistogramCollection* Project(const char* keyA, const char* keyB="", const char* keyC="", const char* keyD="") const;
90   
91   UInt_t EstimateSize(Bool_t show=kFALSE) const;
92   
93   /// Turn on the display of empty histograms for the Print method
94   void ShowEmptyHistograms(Bool_t show=kTRUE) {
95     fMustShowEmptyHistogram = show;
96   }
97   
98   void PruneEmptyHistograms();
99   
100 private:
101   
102   AliHistogramCollection(const AliHistogramCollection& rhs);
103   AliHistogramCollection& operator=(const AliHistogramCollection& rhs);
104
105   Bool_t InternalAdopt(const char* identifier, TH1* histo);
106   
107   Bool_t HistoSameAxis(TH1 *h0, TH1 *h1) const;
108
109   TString InternalDecode(const char* identifier, Int_t index) const;
110   
111   TH1* InternalHisto(const char* identifier, const char* histoname) 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 TH1*...
121   Bool_t fMustShowEmptyHistogram; /// Whether or not to show empty histograms 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(AliHistogramCollection,7) /// A collection of histograms
126 };
127
128 class AliHistogramCollectionIterator : public TIterator
129 {  
130 public:
131   virtual ~AliHistogramCollectionIterator();
132   
133   AliHistogramCollectionIterator(const AliHistogramCollection* hcol, Bool_t direction=kIterForward);
134   AliHistogramCollectionIterator& 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 AliHistogramCollection* fkHistogramCollection; // histogram 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   AliHistogramCollectionIterator() : fkHistogramCollection(0x0), fMapIterator(0x0), fHashListIterator(0x0), fDirection(kIterForward) {}
149   
150   /// not implemented
151   AliHistogramCollectionIterator& operator=(const AliHistogramCollectionIterator &rhs);
152   /// not implemented
153   AliHistogramCollectionIterator(const AliHistogramCollectionIterator &iter);
154     
155   ClassDef(AliHistogramCollectionIterator,0)  // Histogram collection iterator
156 };
157
158 #endif