]>
Commit | Line | Data |
---|---|---|
46f589c2 | 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 | fExceptionType(etype) | |
37 | { | |
38 | if(histname) fHistname = histname; | |
39 | if(hgroup) fGroup = hgroup; | |
40 | } | |
41 | virtual ~HistoContainerContentException() throw() {} | |
42 | ||
43 | virtual const char *what() const throw() { | |
44 | std::stringstream msgbuilder; | |
45 | switch(fExceptionType) { | |
46 | case kHistNotFoundException: | |
47 | msgbuilder << "Histogram " << fHistname << " not found in"; | |
48 | if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup; | |
49 | else msgbuilder << " the list of histograms."; | |
50 | break; | |
51 | case kTypeException: | |
52 | msgbuilder << "Object " << fHistname << " is of wrong type."; | |
53 | break; | |
54 | case kHistDuplicationException: | |
55 | msgbuilder << "Histogram " << fHistname << " already exists in"; | |
56 | if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup; | |
57 | else msgbuilder << " the list of histograms."; | |
58 | break; | |
59 | case kGroupException: | |
60 | msgbuilder << "Group " << fGroup << " not found."; | |
61 | break; | |
62 | }; | |
63 | return msgbuilder.str().c_str(); | |
64 | } | |
65 | ||
66 | const char * GetErrorHistogramName() const { return fHistname.c_str(); } | |
67 | ExceptionType_t GetExceptionType() const { return fExceptionType; } | |
68 | ||
69 | private: | |
70 | std::string fHistname; // Name of the histogram producing the exception | |
71 | std::string fGroup; // Group of objects producing the exception | |
72 | ExceptionType_t fExceptionType; // type of the exception | |
73 | ||
74 | }; | |
75 | ||
76 | class AliEMCalHistoContainer : public TNamed { | |
77 | public: | |
78 | AliEMCalHistoContainer(); | |
79 | AliEMCalHistoContainer(const char *name); | |
80 | ~AliEMCalHistoContainer(); | |
81 | void ReleaseOwner() { fIsOwner = kFALSE; }; | |
82 | ||
83 | void CreateHistoGroup(const char *groupname, const char *parent = "/") throw(HistoContainerContentException); | |
84 | ||
85 | void CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax) throw(HistoContainerContentException); | |
86 | void CreateTH1(const char *name, const char *title, int nbins, const double *xbins) throw(HistoContainerContentException); | |
87 | void CreateTH1(const char *name, const char *title, const TArrayD &xbins) throw(HistoContainerContentException); | |
88 | void CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax) throw(HistoContainerContentException); | |
89 | void CreateTH2(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins) throw(HistoContainerContentException); | |
90 | void CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins) throw(HistoContainerContentException); | |
91 | 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) throw (HistoContainerContentException); | |
92 | void CreateTH3(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, int nbinsz, const double *zbins) throw (HistoContainerContentException); | |
93 | void CreateTH3(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, const TArrayD &zbins) throw(HistoContainerContentException); | |
94 | void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max) throw(HistoContainerContentException); | |
95 | void CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes) throw(HistoContainerContentException); | |
96 | void SetObject(TObject * const o, const char *group = "/") throw(HistoContainerContentException); | |
97 | void FillTH1(const char *hname, double x, double weight = 1.) throw(HistoContainerContentException); | |
98 | void FillTH2(const char *hname, double x, double y, double weight = 1.) throw(HistoContainerContentException); | |
99 | void FillTH2(const char *hname, double *point, double weight = 1.) throw(HistoContainerContentException); | |
100 | void FillTH3(const char *hname, double x, double y, double z, double weight = 1.) throw(HistoContainerContentException); | |
101 | void FillTH3(const char *hname, const double *point, double weight = 1.) throw(HistoContainerContentException); | |
102 | void FillTHnSparse(const char *name, const double *x, double weight = 1.) throw(HistoContainerContentException); | |
103 | ||
104 | THashList *GetListOfHistograms() { return fHistos; } | |
105 | TObject *FindObject(const char *name) const; | |
106 | ||
107 | private: | |
108 | AliEMCalHistoContainer(const AliEMCalHistoContainer &); | |
109 | AliEMCalHistoContainer &operator=(const AliEMCalHistoContainer &); | |
110 | THashList *FindGroup(const char *dirname) const; | |
111 | void TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const; | |
112 | const char *basename(const char *path) const; | |
113 | const char *histname(const char *path) const; | |
114 | ||
115 | THashList *fHistos; // List of histograms | |
116 | bool fIsOwner; // Set the ownership | |
117 | ||
118 | ClassDef(AliEMCalHistoContainer, 1); // Container for histograms | |
119 | }; | |
120 | ||
121 | } | |
122 | #endif |