Line data Source code
1 : #ifndef ALICOUNTERCOLLECTION_H
2 : #define ALICOUNTERCOLLECTION_H
3 : /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 : * See cxx source for full Copyright notice */
5 :
6 : /* $Id$ */
7 :
8 : /// \ingroup PWG3muon
9 : /// \class AliCounterCollection
10 : /// \brief generic class to handle a collection of counters
11 : // Author: Philippe Pillot
12 :
13 : #include <TNamed.h>
14 :
15 : class TString;
16 : class TObjArray;
17 : class THnSparse;
18 : class THashList;
19 : class TArrayI;
20 : class TH1D;
21 : class TH2D;
22 : class TCollection;
23 :
24 : class AliCounterCollection : public TNamed {
25 : public:
26 :
27 : AliCounterCollection(const char* name = "counters");
28 : virtual ~AliCounterCollection();
29 :
30 : virtual void Clear(Option_t* = "");
31 :
32 : // Add a new rubric with the complete list of related key words separated by "/"
33 : void AddRubric(TString name, TString listOfKeyWords);
34 : // Add a new rubric containing at maximum maxNKeyWords key words
35 : void AddRubric(TString name, Int_t maxNKeyWords);
36 : // Initialize the internal counters from the added rubrics
37 : void Init(Bool_t weightedCounters = kFALSE);
38 :
39 : // return the list of key words for the given rubric
40 : TString GetKeyWords(TString rubric) const;
41 :
42 : // Add "value" to the counter referenced by "externalKey"
43 : void Count(TString externalKey, Int_t value = 1);
44 : void Count(TString externalKey, Double_t value);
45 :
46 : // Get the overall statistics for the given selection (result is integrated over not specified rubrics)
47 : Double_t GetSum(TString selections = "", Bool_t* longCounters = 0x0);
48 : // Get counters of the rubric "rubric1" for the given "selection"
49 : TH1D* Get(TString rubric1, TString selections);
50 : // Get counters of the "rubric1" vs "rubric2" for the given "selection"
51 : TH2D* Get(TString rubric1, TString rubric2, TString selections);
52 :
53 : // Print every individual counters if opt=="" or call "Print(opt, "")".
54 : virtual void Print(const Option_t* opt = "") const;
55 : // Print the full list of key words
56 : void PrintKeyWords() const;
57 : // Print value of selected counter
58 : void PrintValue(TString selections);
59 : // Print desired rubrics for the given selection
60 : void Print(TString rubrics, TString selections, Bool_t removeEmpty = kFALSE);
61 : // Print the overall statistics for the given selection (result is integrated over not specified rubrics)
62 : void PrintSum(TString selections = "");
63 :
64 : /// Overload TObject::Draw(Option_t*): Call "Draw(TString rubric1=opt, TString selections="")"
65 0 : virtual void Draw(Option_t* opt = "") {Draw(opt, "");}
66 : // Draw counters of the rubric "rubric1" for the given "selection"
67 : TH1D* Draw(TString rubric1, TString selections);
68 : // Draw counters of the "rubric1" vs "rubric2" for the given "selection"
69 : TH2D* Draw(TString rubric1, TString rubric2, TString selections);
70 :
71 : // Add the given AliCounterCollections to this
72 : void Add(const AliCounterCollection* counter);
73 :
74 : // Merge this with a list of AliCounterCollections
75 : Long64_t Merge(TCollection* list);
76 :
77 : // Sort rubrics defined without a list of authorized key words or all rubrics if opt=="all"
78 : void Sort(Option_t* opt = "", Bool_t asInt = kFALSE);
79 : /// Sort only that rubric. If asInt=kTRUE, key words are ordered as interger instead of alphabetically
80 : void SortRubric(TString rubric, Bool_t asInt = kFALSE);
81 :
82 : private:
83 :
84 : /// Not implemented
85 : AliCounterCollection(const AliCounterCollection& rhs);
86 : /// Not implemented
87 : AliCounterCollection& operator = (const AliCounterCollection& rhs);
88 :
89 : // return the number of labels in that rubric
90 : Int_t GetNActiveBins(Int_t dim);
91 : // return kTRUE if that rubric contains the keyWord "ANY"
92 : Bool_t ContainsAny(Int_t dim);
93 :
94 : // Return the corresponding bins ordered by rubric or 0x0 if externalKey is not valid
95 : const Int_t* FindBins(const TString& externalKey, Bool_t allocate, Int_t& nEmptySlots);
96 : // Return the dimension corresponding to that rubric (or -1)
97 : Int_t FindDim(const TString& rubricName) const;
98 : // Return the bin number corresponding to that key word (or -1)
99 : Int_t FindBin(Int_t dim, const TString& keyWord, Bool_t allocate);
100 :
101 : // Tag the selected keywords in each rubric (-1=subtract; 0=discard; 1=add)
102 : Short_t** DecodeSelection(const TString& selections, const TObjArray& displayedRubrics);
103 : // Tag the selected keywords (separated by ',') in that rubric (-1=subtract; 0=discard; 1=add)
104 : Bool_t Select(Bool_t include, const TString& rubric, const TString& keywords, Bool_t displayed, Short_t* selectBins[]);
105 :
106 : // Make sure all strings appear only once in this list
107 : void CleanListOfStrings(TObjArray* list);
108 :
109 : // Add "value" to the counter referenced by "externalKey"
110 : void CountAsDouble(TString externalKey, Double_t value);
111 :
112 : // Print the content of 1D histogram as a list
113 : void PrintList(const TH1D* hist, Bool_t removeEmpty, Bool_t longCounters) const;
114 : // Print the content of 2D histogram as an array
115 : void PrintArray(const TH2D* hist, Bool_t removeEmpty, Bool_t longCounters) const;
116 : // Print the content of nD histogram as a list of arrays
117 : void PrintListOfArrays(const THnSparse* hist, Bool_t removeEmpty, Bool_t longCounters) const;
118 :
119 : // Return the number of characters of the longest label
120 : Int_t GetMaxLabelSize(THashList* labels) const;
121 :
122 : // Return desired "data" for the given "selection" stored in a new histogram or 0x0
123 : TObject* Projection(const TObjArray& data, const TString& selections, Bool_t& longCounters);
124 :
125 : // Consistency check of the two counter collections
126 : Int_t* CheckConsistency(const AliCounterCollection* c);
127 :
128 : // Sort labels (alphabetically or as integer) in each rubric flagged in "rubricsToSort"
129 : void Sort(const Bool_t* rubricsToSort, Bool_t asInt);
130 : // Return a list (not owner) of labels sorted assuming they are integers
131 : THashList* SortAsInt(const THashList* labels);
132 :
133 : // Convert the given THnSparse to a THnSparseL (able to handle numbers >= 2^31)
134 : void ConvertToTHnSparseL(THnSparse* &h);
135 :
136 : private:
137 :
138 : THashList* fRubrics; ///< list of rubrics with associated key words
139 : TArrayI* fRubricsSize; ///< maximum number of key words in the corresponding rubric
140 : THnSparse* fCounters; ///< histogram of nRubrics dimensions used as n-dimensional counter
141 : Bool_t fWeightedCounters; ///< use THnSparseF instead of THnSparseI
142 : Bool_t fLongCounters; ///< use THnSparseL instead of THnSparseI
143 :
144 176 : ClassDef(AliCounterCollection, 3); // collection of mergeable counters
145 : };
146 :
147 : #endif
148 :
|