ROOT logo
#ifndef ALICOUNTERCOLLECTION_H
#define ALICOUNTERCOLLECTION_H
/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

/* $Id$ */ 

/// \ingroup PWG3muon
/// \class AliCounterCollection
/// \brief generic class to handle a collection of counters
// Author: Philippe Pillot

#include <TNamed.h>

class TString;
class TObjArray;
class THnSparse;
class THashList;
class TArrayI;
class TH1D;
class TH2D;
class TCollection;

class AliCounterCollection : public TNamed {
public:
  
  AliCounterCollection(const char* name = "counters");
  virtual ~AliCounterCollection();
  
  virtual void Clear(Option_t* = "");
  
  // Add a new rubric with the complete list of related key words separated by "/"
  void AddRubric(TString name, TString listOfKeyWords);
  // Add a new rubric containing at maximum maxNKeyWords key words
  void AddRubric(TString name, Int_t maxNKeyWords);
  // Initialize the internal counters from the added rubrics
  void Init(Bool_t weightedCounters = kFALSE);
  
  // return the list of key words for the given rubric
  TString GetKeyWords(TString rubric) const;
  
  // Add "value" to the counter referenced by "externalKey"
  void Count(TString externalKey, Int_t value = 1);
  void Count(TString externalKey, Double_t value);
  
  // Get the overall statistics for the given selection (result is integrated over not specified rubrics)
  Double_t GetSum(TString selections = "", Bool_t* longCounters = 0x0);
  // Get counters of the rubric "rubric1" for the given "selection"
  TH1D* Get(TString rubric1, TString selections);
  // Get counters of the "rubric1" vs "rubric2" for the given "selection"
  TH2D* Get(TString rubric1, TString rubric2, TString selections);
  
  // Print every individual counters if opt=="" or call "Print(opt, "")".
  virtual void Print(const Option_t* opt = "") const;
  // Print the full list of key words
  void PrintKeyWords() const;
  // Print value of selected counter
  void PrintValue(TString selections);
  // Print desired rubrics for the given selection
  void Print(TString rubrics, TString selections, Bool_t removeEmpty = kFALSE);
  // Print the overall statistics for the given selection (result is integrated over not specified rubrics)
  void PrintSum(TString selections = "");
  
  /// Overload TObject::Draw(Option_t*): Call "Draw(TString rubric1=opt, TString selections="")"
  virtual void Draw(Option_t* opt = "") {Draw(opt, "");}
  // Draw counters of the rubric "rubric1" for the given "selection"
  TH1D* Draw(TString rubric1, TString selections);
  // Draw counters of the "rubric1" vs "rubric2" for the given "selection"
  TH2D* Draw(TString rubric1, TString rubric2, TString selections);
  
  // Add the given AliCounterCollections to this
  void Add(const AliCounterCollection* counter);
  
  // Merge this with a list of AliCounterCollections
  Long64_t Merge(TCollection* list);
  
  // Sort rubrics defined without a list of authorized key words or all rubrics if opt=="all"
  void Sort(Option_t* opt = "", Bool_t asInt = kFALSE);
  /// Sort only that rubric. If asInt=kTRUE, key words are ordered as interger instead of alphabetically
  void SortRubric(TString rubric, Bool_t asInt = kFALSE);
  
private:
  
  /// Not implemented
  AliCounterCollection(const AliCounterCollection& rhs);
  /// Not implemented
  AliCounterCollection& operator = (const AliCounterCollection& rhs);
  
  // return the number of labels in that rubric
  Int_t GetNActiveBins(Int_t dim);
  // return kTRUE if that rubric contains the keyWord "ANY"
  Bool_t ContainsAny(Int_t dim);
    
  // Return the corresponding bins ordered by rubric or 0x0 if externalKey is not valid
  const Int_t* FindBins(const TString& externalKey, Bool_t allocate, Int_t& nEmptySlots);
  // Return the dimension corresponding to that rubric (or -1)
  Int_t FindDim(const TString& rubricName) const;
  // Return the bin number corresponding to that key word (or -1)
  Int_t FindBin(Int_t dim, const TString& keyWord, Bool_t allocate);
  
  // Tag the selected keywords in each rubric (-1=subtract; 0=discard; 1=add)
  Short_t** DecodeSelection(const TString& selections, const TObjArray& displayedRubrics);
  // Tag the selected keywords (separated by ',') in that rubric (-1=subtract; 0=discard; 1=add)
  Bool_t Select(Bool_t include, const TString& rubric, const TString& keywords, Bool_t displayed, Short_t* selectBins[]);
    
  // Make sure all strings appear only once in this list
  void CleanListOfStrings(TObjArray* list);
  
  // Add "value" to the counter referenced by "externalKey"
  void CountAsDouble(TString externalKey, Double_t value);
  
  // Print the content of 1D histogram as a list
  void PrintList(const TH1D* hist, Bool_t removeEmpty, Bool_t longCounters) const;
  // Print the content of 2D histogram as an array
  void PrintArray(const TH2D* hist, Bool_t removeEmpty, Bool_t longCounters) const;
  // Print the content of nD histogram as a list of arrays
  void PrintListOfArrays(const THnSparse* hist, Bool_t removeEmpty, Bool_t longCounters) const;
  
  // Return the number of characters of the longest label
  Int_t GetMaxLabelSize(THashList* labels) const;
  
  // Return desired "data" for the given "selection" stored in a new histogram or 0x0
  TObject* Projection(const TObjArray& data, const TString& selections, Bool_t& longCounters);
  
  // Consistency check of the two counter collections
  Int_t* CheckConsistency(const AliCounterCollection* c);
  
  // Sort labels (alphabetically or as integer) in each rubric flagged in "rubricsToSort"
  void Sort(const Bool_t* rubricsToSort, Bool_t asInt);
  // Return a list (not owner) of labels sorted assuming they are integers
  THashList* SortAsInt(const THashList* labels);
  
  // Convert the given THnSparse to a THnSparseL (able to handle numbers >= 2^31)
  void ConvertToTHnSparseL(THnSparse* &h);
  
private:
  
  THashList* fRubrics;        ///< list of rubrics with associated key words
  TArrayI*   fRubricsSize;    ///< maximum number of key words in the corresponding rubric
  THnSparse* fCounters;       ///< histogram of nRubrics dimensions used as n-dimensional counter
  Bool_t fWeightedCounters;   ///< use THnSparseF instead of THnSparseI
  Bool_t fLongCounters;       ///< use THnSparseL instead of THnSparseI
  
  ClassDef(AliCounterCollection, 3); // collection of mergeable counters
};

#endif

 AliCounterCollection.h:1
 AliCounterCollection.h:2
 AliCounterCollection.h:3
 AliCounterCollection.h:4
 AliCounterCollection.h:5
 AliCounterCollection.h:6
 AliCounterCollection.h:7
 AliCounterCollection.h:8
 AliCounterCollection.h:9
 AliCounterCollection.h:10
 AliCounterCollection.h:11
 AliCounterCollection.h:12
 AliCounterCollection.h:13
 AliCounterCollection.h:14
 AliCounterCollection.h:15
 AliCounterCollection.h:16
 AliCounterCollection.h:17
 AliCounterCollection.h:18
 AliCounterCollection.h:19
 AliCounterCollection.h:20
 AliCounterCollection.h:21
 AliCounterCollection.h:22
 AliCounterCollection.h:23
 AliCounterCollection.h:24
 AliCounterCollection.h:25
 AliCounterCollection.h:26
 AliCounterCollection.h:27
 AliCounterCollection.h:28
 AliCounterCollection.h:29
 AliCounterCollection.h:30
 AliCounterCollection.h:31
 AliCounterCollection.h:32
 AliCounterCollection.h:33
 AliCounterCollection.h:34
 AliCounterCollection.h:35
 AliCounterCollection.h:36
 AliCounterCollection.h:37
 AliCounterCollection.h:38
 AliCounterCollection.h:39
 AliCounterCollection.h:40
 AliCounterCollection.h:41
 AliCounterCollection.h:42
 AliCounterCollection.h:43
 AliCounterCollection.h:44
 AliCounterCollection.h:45
 AliCounterCollection.h:46
 AliCounterCollection.h:47
 AliCounterCollection.h:48
 AliCounterCollection.h:49
 AliCounterCollection.h:50
 AliCounterCollection.h:51
 AliCounterCollection.h:52
 AliCounterCollection.h:53
 AliCounterCollection.h:54
 AliCounterCollection.h:55
 AliCounterCollection.h:56
 AliCounterCollection.h:57
 AliCounterCollection.h:58
 AliCounterCollection.h:59
 AliCounterCollection.h:60
 AliCounterCollection.h:61
 AliCounterCollection.h:62
 AliCounterCollection.h:63
 AliCounterCollection.h:64
 AliCounterCollection.h:65
 AliCounterCollection.h:66
 AliCounterCollection.h:67
 AliCounterCollection.h:68
 AliCounterCollection.h:69
 AliCounterCollection.h:70
 AliCounterCollection.h:71
 AliCounterCollection.h:72
 AliCounterCollection.h:73
 AliCounterCollection.h:74
 AliCounterCollection.h:75
 AliCounterCollection.h:76
 AliCounterCollection.h:77
 AliCounterCollection.h:78
 AliCounterCollection.h:79
 AliCounterCollection.h:80
 AliCounterCollection.h:81
 AliCounterCollection.h:82
 AliCounterCollection.h:83
 AliCounterCollection.h:84
 AliCounterCollection.h:85
 AliCounterCollection.h:86
 AliCounterCollection.h:87
 AliCounterCollection.h:88
 AliCounterCollection.h:89
 AliCounterCollection.h:90
 AliCounterCollection.h:91
 AliCounterCollection.h:92
 AliCounterCollection.h:93
 AliCounterCollection.h:94
 AliCounterCollection.h:95
 AliCounterCollection.h:96
 AliCounterCollection.h:97
 AliCounterCollection.h:98
 AliCounterCollection.h:99
 AliCounterCollection.h:100
 AliCounterCollection.h:101
 AliCounterCollection.h:102
 AliCounterCollection.h:103
 AliCounterCollection.h:104
 AliCounterCollection.h:105
 AliCounterCollection.h:106
 AliCounterCollection.h:107
 AliCounterCollection.h:108
 AliCounterCollection.h:109
 AliCounterCollection.h:110
 AliCounterCollection.h:111
 AliCounterCollection.h:112
 AliCounterCollection.h:113
 AliCounterCollection.h:114
 AliCounterCollection.h:115
 AliCounterCollection.h:116
 AliCounterCollection.h:117
 AliCounterCollection.h:118
 AliCounterCollection.h:119
 AliCounterCollection.h:120
 AliCounterCollection.h:121
 AliCounterCollection.h:122
 AliCounterCollection.h:123
 AliCounterCollection.h:124
 AliCounterCollection.h:125
 AliCounterCollection.h:126
 AliCounterCollection.h:127
 AliCounterCollection.h:128
 AliCounterCollection.h:129
 AliCounterCollection.h:130
 AliCounterCollection.h:131
 AliCounterCollection.h:132
 AliCounterCollection.h:133
 AliCounterCollection.h:134
 AliCounterCollection.h:135
 AliCounterCollection.h:136
 AliCounterCollection.h:137
 AliCounterCollection.h:138
 AliCounterCollection.h:139
 AliCounterCollection.h:140
 AliCounterCollection.h:141
 AliCounterCollection.h:142
 AliCounterCollection.h:143
 AliCounterCollection.h:144
 AliCounterCollection.h:145
 AliCounterCollection.h:146
 AliCounterCollection.h:147
 AliCounterCollection.h:148