AliPhysics  v5-06-11-01 (156c7f3)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEMCalHistoContainer.h
Go to the documentation of this file.
1 #ifndef ALIEMCALHISTOCONTAINER_H
2 #define ALIEMCALHISTOCONTAINER_H
3 /* Copyright(c) 1998-2014, 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 
26 namespace EMCalTriggerPtAnalysis {
27 
28 class HistoContainerContentException : public std::exception {
29  /*
30  * Error handling class for the histogram container
31  */
32 public:
38  };
39 
40  HistoContainerContentException(const char *histname, const char *hgroup, ExceptionType_t etype):
41  fHistname(),
42  fGroup(),
43  fErrorMessage(),
44  fExceptionType(etype)
45  {
46  if(histname) fHistname = histname;
47  if(hgroup) fGroup = hgroup;
48 
50  }
51  virtual ~HistoContainerContentException() throw() {}
52 
53  virtual const char *what() const throw() {
54  return fErrorMessage.c_str();
55  }
56 
57  const char * GetErrorHistogramName() const { return fHistname.c_str(); }
59 
60 private:
62  /*
63  * Create error message with the histogram name, the histogram group, and the error type
64  */
65  std::stringstream msgbuilder;
66  switch(fExceptionType) {
68  msgbuilder << "Histogram " << fHistname << " not found in";
69  if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup;
70  else msgbuilder << " the list of histograms.";
71  break;
72  case kTypeException:
73  msgbuilder << "Object " << fHistname << " is of wrong type.";
74  break;
76  msgbuilder << "Histogram " << fHistname << " already exists in";
77  if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup;
78  else msgbuilder << " the list of histograms.";
79  break;
80  case kGroupException:
81  msgbuilder << "Group " << fGroup << " not found.";
82  break;
83  };
84  fErrorMessage = msgbuilder.str();
85  }
86 
87  std::string fHistname; // Name of the histogram producing the exception
88  std::string fGroup; // Group of objects producing the exception
89  std::string fErrorMessage; // container for the error message produced in the what function
90  ExceptionType_t fExceptionType; // type of the exception
91 
92 };
93 
94 class AliEMCalHistoContainer : public TNamed {
95 public:
97  AliEMCalHistoContainer(const char *name);
99  void ReleaseOwner() { fIsOwner = kFALSE; };
100 
101  void CreateHistoGroup(const char *groupname, const char *parent = "/") throw(HistoContainerContentException);
102 
103  void CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt = "") throw(HistoContainerContentException);
104  void CreateTH1(const char *name, const char *title, int nbins, const double *xbins, Option_t *opt = "") throw(HistoContainerContentException);
105  void CreateTH1(const char *name, const char *title, const TArrayD &xbins, Option_t *opt = "") throw(HistoContainerContentException);
106  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);
107  void CreateTH2(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, Option_t *opt = "") throw(HistoContainerContentException);
108  void CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, Option_t *opt = "") throw(HistoContainerContentException);
109  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);
110  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);
111  void CreateTH3(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, const TArrayD &zbins, Option_t *opt = "") throw(HistoContainerContentException);
112  void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt = "") throw(HistoContainerContentException);
113  void CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes, Option_t *opt = "") throw(HistoContainerContentException);
114  void SetObject(TObject * const o, const char *group = "/") throw(HistoContainerContentException);
115  void FillTH1(const char *hname, double x, double weight = 1.) throw(HistoContainerContentException);
116  void FillTH2(const char *hname, double x, double y, double weight = 1.) throw(HistoContainerContentException);
117  void FillTH2(const char *hname, double *point, double weight = 1.) throw(HistoContainerContentException);
118  void FillTH3(const char *hname, double x, double y, double z, double weight = 1.) throw(HistoContainerContentException);
119  void FillTH3(const char *hname, const double *point, double weight = 1.) throw(HistoContainerContentException);
120  void FillTHnSparse(const char *name, const double *x, double weight = 1.) throw(HistoContainerContentException);
121 
122  THashList *GetListOfHistograms() { return fHistos; }
123  virtual TObject *FindObject(const char *name) const;
124  virtual TObject *FindObject(const TObject *obj) const;
125 
126 private:
129  THashList *FindGroup(const char *dirname) const;
130  void TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const;
131  const char *basename(const char *path) const;
132  const char *histname(const char *path) const;
133 
134  THashList *fHistos; // List of histograms
135  bool fIsOwner; // Set the ownership
136 
137  ClassDef(AliEMCalHistoContainer, 1); // Container for histograms
138 };
139 
140 }
141 #endif
THashList * FindGroup(const char *dirname) const
AliEMCalHistoContainer & operator=(const AliEMCalHistoContainer &)
void FillTH2(const char *hname, double x, double y, double weight=1.)
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="")
void SetObject(TObject *const o, const char *group="/")
void CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
void FillTHnSparse(const char *name, const double *x, double weight=1.)
void FillTH3(const char *hname, double x, double y, double z, double weight=1.)
void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
const char * histname(const char *path) const
virtual TObject * FindObject(const char *name) const
void CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
void TokenizeFilename(const char *name, const char *delim, std::vector< std::string > &listoftokens) const
const char * basename(const char *path) const
void FillTH1(const char *hname, double x, double weight=1.)
void CreateHistoGroup(const char *groupname, const char *parent="/")
HistoContainerContentException(const char *histname, const char *hgroup, ExceptionType_t etype)