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 */
9 /// \class AliCounterCollection
10 /// \brief generic class to handle a collection of counters
11 // Author: Philippe Pillot
24 class AliCounterCollection : public TNamed {
27 AliCounterCollection(const char* name = "counters");
28 virtual ~AliCounterCollection();
30 virtual void Clear(Option_t* = "");
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);
39 // return the list of key words for the given rubric
40 TString GetKeyWords(TString rubric) const;
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);
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);
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 = "");
64 /// Overload TObject::Draw(Option_t*): Call "Draw(TString rubric1=opt, TString selections="")"
65 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);
71 // Add the given AliCounterCollections to this
72 void Add(const AliCounterCollection* counter);
74 // Merge this with a list of AliCounterCollections
75 Long64_t Merge(TCollection* list);
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);
85 AliCounterCollection(const AliCounterCollection& rhs);
87 AliCounterCollection& operator = (const AliCounterCollection& rhs);
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);
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);
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[]);
106 // Make sure all strings appear only once in this list
107 void CleanListOfStrings(TObjArray* list);
109 // Add "value" to the counter referenced by "externalKey"
110 void CountAsDouble(TString externalKey, Double_t value);
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;
119 // Return the number of characters of the longest label
120 Int_t GetMaxLabelSize(THashList* labels) const;
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);
125 // Consistency check of the two counter collections
126 Int_t* CheckConsistency(const AliCounterCollection* c);
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);
133 // Convert the given THnSparse to a THnSparseL (able to handle numbers >= 2^31)
134 void ConvertToTHnSparseL(THnSparse* &h);
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
144 ClassDef(AliCounterCollection, 3); // collection of mergeable counters