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 */
7 /// \class AliCounterCollection
8 /// \brief generic class to handle a collection of counters
9 // Author: Philippe Pillot
22 class AliCounterCollection : public TNamed {
25 AliCounterCollection(const char* name = "counters");
26 virtual ~AliCounterCollection();
28 virtual void Clear(Option_t* = "");
30 // Add a new rubric with the complete list of related key words separated by "/"
31 void AddRubric(TString name, TString listOfKeyWords);
32 // Add a new rubric containing at maximum maxNKeyWords key words
33 void AddRubric(TString name, Int_t maxNKeyWords);
34 // Initialize the internal counters from the added rubrics
35 void Init(Bool_t weightedCounters = kFALSE);
37 // return the list of key words for the given rubric
38 TString GetKeyWords(TString rubric) const;
40 // Add "value" to the counter referenced by "externalKey"
41 void Count(TString externalKey, Int_t value = 1);
42 void Count(TString externalKey, Double_t value);
44 // Get the overall statistics for the given selection (result is integrated over not specified rubrics)
45 Double_t GetSum(TString selections = "");
46 // Get counters of the rubric "rubric1" for the given "selection"
47 TH1D* Get(TString rubric1, TString selections);
48 // Get counters of the "rubric1" vs "rubric2" for the given "selection"
49 TH2D* Get(TString rubric1, TString rubric2, TString selections);
51 // Print every individual counters if opt=="", else call "Print(TString rubrics=opt, TString selections="")"
52 virtual void Print(const Option_t* opt = "") const;
53 // Print the full list of key words
54 void PrintKeyWords() const;
55 // Print value of selected counter
56 void PrintValue(TString selections);
57 // Print desired rubrics for the given selection
58 void Print(TString rubrics, TString selections);
59 // Print the overall statistics for the given selection (result is integrated over not specified rubrics)
60 void PrintSum(TString selections = "");
62 /// Overload TObject::Draw(Option_t*): Call "Draw(TString rubric1=opt, TString selections="")"
63 virtual void Draw(Option_t* opt = "") {Draw(opt, "");}
64 // Draw counters of the rubric "rubric1" for the given "selection"
65 TH1D* Draw(TString rubric1, TString selections);
66 // Draw counters of the "rubric1" vs "rubric2" for the given "selection"
67 TH2D* Draw(TString rubric1, TString rubric2, TString selections);
69 // Add the given AliCounterCollections to this
70 void Add(const AliCounterCollection* counter);
72 // Merge this with a list of AliCounterCollections
73 Long64_t Merge(TCollection* list);
75 // Sort rubrics defined without a list of authorized key words or all rubrics if opt=="all"
76 void Sort(Option_t* opt = "", Bool_t asInt = kFALSE);
77 /// Sort only that rubric. If asInt=kTRUE, key words are ordered as interger instead of alphabetically
78 void SortRubric(TString rubric, Bool_t asInt = kFALSE);
83 AliCounterCollection(const AliCounterCollection& rhs);
85 AliCounterCollection& operator = (const AliCounterCollection& rhs);
87 // return the number of labels in that rubric
88 Int_t GetNActiveBins(Int_t dim);
89 // return kTRUE if that rubric contains the keyWord "ANY"
90 Bool_t ContainsAny(Int_t dim);
92 // Return the corresponding bins ordered by rubric or 0x0 if externalKey is not valid
93 const Int_t* FindBins(const TString& externalKey, Bool_t allocate, Int_t& nEmptySlots);
94 // Return the dimension corresponding to that rubric (or -1)
95 Int_t FindDim(const TString& rubricName) const;
96 // Return the bin number corresponding to that key word (or -1)
97 Int_t FindBin(Int_t dim, const TString& keyWord, Bool_t allocate);
99 // Tag the selected keywords in each rubric (-1=subtract; 0=discard; 1=add)
100 Short_t** DecodeSelection(const TString& selections, const TObjArray& displayedRubrics);
101 // Tag the selected keywords (separated by ',') in that rubric (-1=subtract; 0=discard; 1=add)
102 Bool_t Select(Bool_t include, const TString& rubric, const TString& keywords, Bool_t displayed, Short_t* selectBins[]);
104 // Make sure all strings appear only once in this list
105 void CleanListOfStrings(TObjArray* list);
107 // Add "value" to the counter referenced by "externalKey"
108 void CountAsDouble(TString externalKey, Double_t value);
110 // Print the content of 1D histogram as a list
111 void PrintList(const TH1D* hist) const;
112 // Print the content of 2D histogram as an array
113 void PrintArray(const TH2D* hist) const;
114 // Print the content of nD histogram as a list of arrays
115 void PrintListOfArrays(const THnSparse* hist) const;
117 // Return the number of characters of the longest label
118 Int_t GetMaxLabelSize(THashList* labels) const;
120 // Return desired "data" for the given "selection" stored in a new histogram or 0x0
121 TObject* Projection(const TObjArray& data, const TString& selections);
123 // Consistency check of the two counter collections
124 Int_t* CheckConsistency(const AliCounterCollection* c);
126 // Sort labels (alphabetically or as integer) in each rubric flagged in "rubricsToSort"
127 void Sort(const Bool_t* rubricsToSort, Bool_t asInt);
128 /// Return a list (not owner) of labels sorted assuming they are integers
129 THashList* SortAsInt(const THashList* labels);
133 THashList* fRubrics; ///< list of rubrics with associated key words
134 TArrayI* fRubricsSize; ///< maximum number of key words in the corresponding rubric
135 THnSparse* fCounters; ///< histogram of nRubrics dimensions used as n-dimensional counter
136 Bool_t fWeightedCounters; ///< use THnSparseF instead of THnSparseI
138 ClassDef(AliCounterCollection, 2); // collection of mergeable counters