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

// Author: Markus Fasel

#include <cstring>
#include <exception>
#include <string>
#include <sstream>
#include <TNamed.h>

class TArrayD;
class TAxis;
class TList;
class THashList;

namespace EMCalTriggerPtAnalysis {

class HistoContainerContentException : public std::exception {
  /*
   * Error handling class for the histogram container
   */
public:
  enum ExceptionType_t {
    kHistNotFoundException = 0,
    kTypeException = 1,
    kHistDuplicationException = 2,
    kGroupException = 3
  };

  HistoContainerContentException(const char *histname, const char *hgroup, ExceptionType_t etype):
    fHistname(),
    fGroup(),
    fErrorMessage(),
    fExceptionType(etype)
  {
    if(histname) fHistname = histname;
    if(hgroup) fGroup = hgroup;

    CreateErrorMessage();
  }
  virtual ~HistoContainerContentException() throw() {}

  virtual const char *what() const throw() {
    return fErrorMessage.c_str();
  }

  const char * GetErrorHistogramName() const { return fHistname.c_str(); }
  ExceptionType_t GetExceptionType() const { return fExceptionType; }

private:
  void CreateErrorMessage(){
    /*
     * Create error message with the histogram name, the histogram group, and the error type
     */
    std::stringstream msgbuilder;
    switch(fExceptionType) {
    case kHistNotFoundException:
      msgbuilder << "Histogram " << fHistname << " not found in";
      if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup;
      else msgbuilder << " the list of histograms.";
      break;
    case kTypeException:
      msgbuilder << "Object " << fHistname << " is of wrong type.";
      break;
    case kHistDuplicationException:
      msgbuilder << "Histogram " << fHistname << " already exists in";
      if(strlen(fGroup.c_str())) msgbuilder << " group " << fGroup;
      else msgbuilder << " the list of histograms.";
      break;
    case kGroupException:
      msgbuilder << "Group " << fGroup << " not found.";
      break;
    };
    fErrorMessage = msgbuilder.str();
  }

  std::string           fHistname;            // Name of the histogram producing the exception
  std::string           fGroup;               // Group of objects producing the exception
  std::string			  fErrorMessage;		// container for the error message produced in the what function
  ExceptionType_t       fExceptionType;       // type of the exception

};

class AliEMCalHistoContainer : public TNamed {
public:
  AliEMCalHistoContainer();
  AliEMCalHistoContainer(const char *name);
  ~AliEMCalHistoContainer();
  void ReleaseOwner() { fIsOwner = kFALSE; };

  void CreateHistoGroup(const char *groupname, const char *parent = "/") throw(HistoContainerContentException);

  void CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt = "") throw(HistoContainerContentException);
  void CreateTH1(const char *name, const char *title, int nbins, const double *xbins, Option_t *opt = "") throw(HistoContainerContentException);
  void CreateTH1(const char *name, const char *title, const TArrayD &xbins, Option_t *opt = "") throw(HistoContainerContentException);
  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);
  void CreateTH2(const char *name, const char *title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, Option_t *opt = "") throw(HistoContainerContentException);
  void CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, Option_t *opt = "") throw(HistoContainerContentException);
  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);
  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);
  void CreateTH3(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, const TArrayD &zbins, Option_t *opt = "") throw(HistoContainerContentException);
  void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt = "") throw(HistoContainerContentException);
  void CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes, Option_t *opt = "") throw(HistoContainerContentException);
  void SetObject(TObject * const o, const char *group = "/") throw(HistoContainerContentException);
  void FillTH1(const char *hname, double x, double weight = 1.) throw(HistoContainerContentException);
  void FillTH2(const char *hname, double x, double y, double weight = 1.) throw(HistoContainerContentException);
  void FillTH2(const char *hname, double *point, double weight = 1.) throw(HistoContainerContentException);
  void FillTH3(const char *hname, double x, double y, double z, double weight = 1.) throw(HistoContainerContentException);
  void FillTH3(const char *hname, const double *point, double weight = 1.) throw(HistoContainerContentException);
  void FillTHnSparse(const char *name, const double *x, double weight = 1.) throw(HistoContainerContentException);

  THashList *GetListOfHistograms() { return fHistos; }
  virtual TObject *FindObject(const char *name) const;
  virtual TObject *FindObject(const TObject *obj) const;

private:
  AliEMCalHistoContainer(const AliEMCalHistoContainer &);
  AliEMCalHistoContainer &operator=(const AliEMCalHistoContainer &);
  THashList *FindGroup(const char *dirname) const;
  void TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const;
  const char *basename(const char *path) const;
  const char *histname(const char *path) const;

  THashList *fHistos;                   // List of histograms
  bool fIsOwner;                        // Set the ownership

  ClassDef(AliEMCalHistoContainer, 1);  // Container for histograms
};

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