]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGJE/EMCALJetTasks/UserTasks/AliEMCalHistoContainer.h
d0557ab6eea9f620da7d85b17d4319273a9dd945
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliEMCalHistoContainer.h
1 #ifndef ALIEMCALHISTOCONTAINER_H
2 #define ALIEMCALHISTOCONTAINER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice                               */
5
6 // Author: Markus Fasel
7
8 #include <cstring>
9 #include <exception>
10 #include <string>
11 #include <sstream>
12 #include <TNamed.h>
13
14 class TArrayD;
15 class TAxis;
16 class TList;
17 class THashList;
18
19 namespace EMCalTriggerPtAnalysis {
20
21 class HistoContainerContentException : public std::exception {
22   /*
23    * Error handling class for the histogram container
24    */
25 public:
26   enum ExceptionType_t {
27     kHistNotFoundException = 0,
28     kTypeException = 1,
29     kHistDuplicationException = 2,
30     kGroupException = 3
31   };
32
33   HistoContainerContentException(const char *histname, const char *hgroup, ExceptionType_t etype):
34     fHistname(),
35     fGroup(),
36     fErrorMessage(),
37     fExceptionType(etype)
38   {
39     if(histname) fHistname = histname;
40     if(hgroup) fGroup = hgroup;
41
42     CreateErrorMessage();
43   }
44   virtual ~HistoContainerContentException() throw() {}
45
46   virtual const char *what() const throw() {
47     return fErrorMessage.c_str();
48   }
49
50   const char * GetErrorHistogramName() const { return fHistname.c_str(); }
51   ExceptionType_t GetExceptionType() const { return fExceptionType; }
52
53 private:
54   void CreateErrorMessage(){
55     /*
56      * Create error message with the histogram name, the histogram group, and the error type
57      */
58     std::stringstream msgbuilder;
59     switch(fExceptionType) {
60     case kHistNotFoundException:
61       msgbuilder << "Histogram " << fHistname << " not found in";
62       if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup;
63       else msgbuilder << " the list of histograms.";
64       break;
65     case kTypeException:
66       msgbuilder << "Object " << fHistname << " is of wrong type.";
67       break;
68     case kHistDuplicationException:
69       msgbuilder << "Histogram " << fHistname << " already exists in";
70       if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup;
71       else msgbuilder << " the list of histograms.";
72       break;
73     case kGroupException:
74       msgbuilder << "Group " << fGroup << " not found.";
75       break;
76     };
77     fErrorMessage = msgbuilder.str();
78   }
79
80   std::string           fHistname;            // Name of the histogram producing the exception
81   std::string           fGroup;               // Group of objects producing the exception
82   std::string                     fErrorMessage;                // container for the error message produced in the what function
83   ExceptionType_t       fExceptionType;       // type of the exception
84
85 };
86
87 class AliEMCalHistoContainer : public TNamed {
88 public:
89   AliEMCalHistoContainer();
90   AliEMCalHistoContainer(const char *name);
91   ~AliEMCalHistoContainer();
92   void ReleaseOwner() { fIsOwner = kFALSE; };
93
94   void CreateHistoGroup(const char *groupname, const char *parent = "/") throw(HistoContainerContentException);
95
96   void CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt = "") throw(HistoContainerContentException);
97   void CreateTH1(const char *name, const char *title, int nbins, const double *xbins, Option_t *opt = "") throw(HistoContainerContentException);
98   void CreateTH1(const char *name, const char *title, const TArrayD &xbins, Option_t *opt = "") throw(HistoContainerContentException);
99   void CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt = "") throw(HistoContainerContentException);
100   void CreateTH2(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, Option_t *opt = "") throw(HistoContainerContentException);
101   void CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, Option_t *opt = "") throw(HistoContainerContentException);
102   void CreateTH3(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt = "") throw (HistoContainerContentException);
103   void CreateTH3(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, int nbinsz, const double *zbins, Option_t *opt = "") throw (HistoContainerContentException);
104   void CreateTH3(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, const TArrayD &zbins, Option_t *opt = "") throw(HistoContainerContentException);
105   void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt = "") throw(HistoContainerContentException);
106   void CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes, Option_t *opt = "") throw(HistoContainerContentException);
107   void SetObject(TObject * const o, const char *group = "/") throw(HistoContainerContentException);
108   void FillTH1(const char *hname, double x, double weight = 1.) throw(HistoContainerContentException);
109   void FillTH2(const char *hname, double x, double y, double weight = 1.) throw(HistoContainerContentException);
110   void FillTH2(const char *hname, double *point, double weight = 1.) throw(HistoContainerContentException);
111   void FillTH3(const char *hname, double x, double y, double z, double weight = 1.) throw(HistoContainerContentException);
112   void FillTH3(const char *hname, const double *point, double weight = 1.) throw(HistoContainerContentException);
113   void FillTHnSparse(const char *name, const double *x, double weight = 1.) throw(HistoContainerContentException);
114
115   THashList *GetListOfHistograms() { return fHistos; }
116   virtual TObject *FindObject(const char *name) const;
117   virtual TObject *FindObject(const TObject *obj) const;
118
119 private:
120   AliEMCalHistoContainer(const AliEMCalHistoContainer &);
121   AliEMCalHistoContainer &operator=(const AliEMCalHistoContainer &);
122   THashList *FindGroup(const char *dirname) const;
123   void TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const;
124   const char *basename(const char *path) const;
125   const char *histname(const char *path) const;
126
127   THashList *fHistos;                   // List of histograms
128   bool fIsOwner;                        // Set the ownership
129
130   ClassDef(AliEMCalHistoContainer, 1);  // Container for histograms
131 };
132
133 }
134 #endif