CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DPGAnalysis/SiStripTools/interface/RunHistogramManager.h

Go to the documentation of this file.
00001 #ifndef DPGAnalysis_SiStripTools_RunHistogramManager_H
00002 #define DPGAnalysis_SiStripTools_RunHistogramManager_H
00003 
00004 #include <vector>
00005 #include <map>
00006 #include <string>
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/Framework/interface/Run.h"
00009 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00010 #include "TH2F.h"
00011 #include "TProfile2D.h"
00012 
00013 class TH1F;
00014 class TProfile;
00015 
00016  class BaseHistoParams{
00017 
00018  public:
00019    BaseHistoParams();
00020    virtual ~BaseHistoParams();
00021 
00022    virtual void beginRun(const edm::Run& iRun, TFileDirectory& subrun);
00023    virtual void beginRun(const unsigned int irun, TFileDirectory& subrun) = 0;
00024 
00025  };
00026 
00027 template <class T>
00028   class HistoParams: public BaseHistoParams
00029 {
00030   
00031  public:
00032   HistoParams(T** pointer, const std::string type, const std::string name, const std::string title, 
00033               const unsigned int nbinx=-1, const double xmin = -1., const double xmax = -1.,
00034               const unsigned int nbiny=-1, const double ymin = -1., const double ymax = -1.):
00035     BaseHistoParams(),
00036     _pointer(pointer),
00037     _type(type), _name(name), _title(title), _nbinx(nbinx), _xmin(xmin), _xmax(xmax),
00038     _nbiny(nbiny), _ymin(ymin), _ymax(ymax), _runpointers() { }
00039     
00040     ~HistoParams() {
00041 
00042       delete _pointer;
00043       LogDebug("Destructor") << "Destroy " << _name;
00044 
00045     }
00046 
00047     virtual void beginRun(const unsigned int irun, TFileDirectory& subrun) {
00048       
00049       if(_runpointers.find(irun)!=_runpointers.end()) {
00050         *_pointer = _runpointers[irun];
00051         LogDebug("TH1Fbooked") << "Histogram " << _name.c_str() << " already exists " << _runpointers[irun];
00052         
00053       }
00054       else {
00055 
00056         char title[400];
00057         sprintf(title,"%s run %d",_title.c_str(),irun);
00058         
00059         _runpointers[irun] = subrun.make<T>(_name.c_str(),
00060                                                   title,
00061                                                   _nbinx,
00062                                                   _xmin,
00063                                                   _xmax);
00064         
00065         *_pointer = _runpointers[irun];
00066         LogDebug("TH1Fbooked") << "Histogram " << _name.c_str() << " booked " << _runpointers[irun];
00067       }
00068       
00069     }
00070     
00071  private:
00072     T** _pointer;
00073     std::string _type;
00074     std::string _name;
00075     std::string _title;
00076     unsigned int _nbinx;
00077     double _xmin;
00078     double _xmax;
00079     unsigned int _nbiny;
00080     double _ymin;
00081     double _ymax;
00082     std::map<unsigned int, T*> _runpointers;
00083     
00084  };
00085  
00086 template <>
00087   class HistoParams<TH2F>: public BaseHistoParams
00088 {
00089   
00090  public:
00091   HistoParams(TH2F** pointer, const std::string type, const std::string name, const std::string title, 
00092               const unsigned int nbinx=-1, const double xmin = -1., const double xmax = -1.,
00093               const unsigned int nbiny=-1, const double ymin = -1., const double ymax = -1.):
00094     BaseHistoParams(),
00095     _pointer(pointer),
00096     _type(type), _name(name), _title(title), _nbinx(nbinx), _xmin(xmin), _xmax(xmax),
00097     _nbiny(nbiny), _ymin(ymin), _ymax(ymax), _runpointers() { }
00098     
00099     
00100     ~HistoParams() {
00101 
00102       delete _pointer;
00103       LogDebug("TH2FDestructor") << "Destroy " << _name;
00104 
00105     }
00106 
00107     virtual void beginRun(const unsigned int irun, TFileDirectory& subrun) {
00108       
00109       if(_runpointers.find(irun)!=_runpointers.end()) {
00110         *_pointer = _runpointers[irun];
00111         LogDebug("TH2Fbooked") << "Histogram " << _name.c_str() << " already exists " << _runpointers[irun];
00112         
00113       }
00114       else {
00115         
00116         char title[400];
00117         sprintf(title,"%s run %d",_title.c_str(),irun);
00118         
00119         _runpointers[irun] = subrun.make<TH2F>(_name.c_str(),
00120                                                   title,
00121                                                   _nbinx,
00122                                                   _xmin,
00123                                                   _xmax,
00124                                                   _nbiny,
00125                                                   _ymin,
00126                                                   _ymax);
00127         
00128         *_pointer = _runpointers[irun];
00129         LogDebug("TH2Fbooked") << "Histogram " << _name.c_str() << " booked " << _runpointers[irun];
00130       }
00131       
00132       
00133     }
00134     
00135  private:
00136     TH2F** _pointer;
00137     std::string _type;
00138     std::string _name;
00139     std::string _title;
00140     unsigned int _nbinx;
00141     double _xmin;
00142     double _xmax;
00143     unsigned int _nbiny;
00144     double _ymin;
00145     double _ymax;
00146     std::map<unsigned int, TH2F*> _runpointers;
00147     
00148  };
00149  
00150 template <>
00151   class HistoParams<TProfile2D>: public BaseHistoParams
00152 {
00153   
00154  public:
00155   HistoParams(TProfile2D** pointer, const std::string type, const std::string name, const std::string title, 
00156               const unsigned int nbinx=-1, const double xmin = -1., const double xmax = -1.,
00157               const unsigned int nbiny=-1, const double ymin = -1., const double ymax = -1.):
00158     BaseHistoParams(),
00159     _pointer(pointer),
00160     _type(type), _name(name), _title(title), _nbinx(nbinx), _xmin(xmin), _xmax(xmax),
00161     _nbiny(nbiny), _ymin(ymin), _ymax(ymax), _runpointers() { }
00162     
00163     
00164     ~HistoParams() {
00165 
00166       delete _pointer;
00167       LogDebug("TProfile2DDestructor") << "Destroy " << _name;
00168 
00169     }
00170 
00171     virtual void beginRun(const unsigned int irun, TFileDirectory& subrun) {
00172       
00173       if(_runpointers.find(irun)!=_runpointers.end()) {
00174         *_pointer = _runpointers[irun];
00175         LogDebug("TProfile2Dbooked") << "Histogram " << _name.c_str() << " already exists " << _runpointers[irun];
00176         
00177       }
00178       else {
00179         
00180         char title[400];
00181         sprintf(title,"%s run %d",_title.c_str(),irun);
00182         
00183         _runpointers[irun] = subrun.make<TProfile2D>(_name.c_str(),
00184                                                   title,
00185                                                   _nbinx,
00186                                                   _xmin,
00187                                                   _xmax,
00188                                                   _nbiny,
00189                                                   _ymin,
00190                                                   _ymax);
00191         
00192         *_pointer = _runpointers[irun];
00193         LogDebug("TProfile2Dbooked") << "Histogram " << _name.c_str() << " booked " << _runpointers[irun];
00194       }
00195       
00196       
00197     }
00198     
00199  private:
00200     TProfile2D** _pointer;
00201     std::string _type;
00202     std::string _name;
00203     std::string _title;
00204     unsigned int _nbinx;
00205     double _xmin;
00206     double _xmax;
00207     unsigned int _nbiny;
00208     double _ymin;
00209     double _ymax;
00210     std::map<unsigned int, TProfile2D*> _runpointers;
00211     
00212  };
00213  
00214 
00215 class RunHistogramManager {
00216 
00217  public:
00218   
00219   RunHistogramManager();
00220   ~RunHistogramManager();
00221   
00222   TH1F**  makeTH1F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax);
00223   TProfile**  makeTProfile(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax);
00224   TH2F**  makeTH2F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax);
00225   TProfile2D**  makeTProfile2D(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax);
00226   
00227   void  beginRun(const edm::Run& iRun);
00228   void  beginRun(const unsigned int irun);
00229   void  beginRun(const unsigned int irun, TFileDirectory& subdir);
00230   
00231   
00232  private:
00233   
00234   std::vector<BaseHistoParams*> _histograms;
00235   
00236 };
00237 
00238 
00239 
00240 #endif // DPGAnalysis_SiStripTools_RunHistogramManager_H