CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DPGAnalysis/SiStripTools/src/RunHistogramManager.cc

Go to the documentation of this file.
00001 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
00002 #include "FWCore/Framework/interface/Run.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "FWCore/ServiceRegistry/interface/Service.h"
00005 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00006 #include "TH1F.h"
00007 #include "TH2F.h"
00008 #include "TProfile.h"
00009 #include "TProfile2D.h"
00010 
00011 BaseHistoParams::BaseHistoParams() { }
00012 
00013 BaseHistoParams::~BaseHistoParams() { }
00014 
00015 void BaseHistoParams::beginRun(const edm::Run& iRun, TFileDirectory& subrun) {
00016   
00017   beginRun(iRun.run(),subrun);
00018 
00019 }
00020 
00021 
00022 
00023 
00024 RunHistogramManager::RunHistogramManager():
00025   _histograms() { }
00026 
00027 TH1F** RunHistogramManager::makeTH1F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
00028 
00029   TH1F** pointer =new TH1F*(0);
00030 
00031   BaseHistoParams* hp = new HistoParams<TH1F>(pointer,"TH1F",name,title,nbinx,xmin,xmax);
00032   _histograms.push_back(hp);
00033 
00034   LogDebug("TH1Fmade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
00035 
00036   return pointer;
00037 
00038 }
00039 
00040 RunHistogramManager::~RunHistogramManager() {
00041 
00042   for(std::vector<BaseHistoParams*>::const_iterator hp=_histograms.begin();hp!=_histograms.end();++hp) {
00043 
00044     delete *hp;
00045 
00046   }
00047   LogDebug("Destructor") << "All BaseHistoParams destroyed ";
00048 
00049 }
00050 
00051 TProfile** RunHistogramManager::makeTProfile(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
00052 
00053   TProfile** pointer =new TProfile*(0);
00054 
00055   BaseHistoParams* hp = new HistoParams<TProfile>(pointer,"TProfile",name,title,nbinx,xmin,xmax);
00056   _histograms.push_back(hp);
00057 
00058   LogDebug("TProfilemade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
00059 
00060   return pointer;
00061 
00062 }
00063 
00064 TH2F** RunHistogramManager::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 ) {
00065 
00066   TH2F** pointer  = new TH2F*(0);
00067 
00068   BaseHistoParams* hp = new HistoParams<TH2F>(pointer,"TH2F",name,title,nbinx,xmin,xmax,nbiny,ymin,ymax);
00069   _histograms.push_back(hp);
00070 
00071   LogDebug("TH2Fmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
00072 
00073   return pointer;
00074 }
00075 
00076 TProfile2D** RunHistogramManager::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 ) {
00077 
00078   TProfile2D** pointer  = new TProfile2D*(0);
00079 
00080   BaseHistoParams* hp = new HistoParams<TProfile2D>(pointer,"TProfile2D",name,title,nbinx,xmin,xmax,nbiny,ymin,ymax);
00081   _histograms.push_back(hp);
00082 
00083   LogDebug("TProfile2Dmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
00084 
00085   return pointer;
00086 }
00087 
00088 void  RunHistogramManager::beginRun(const edm::Run& iRun) {
00089 
00090   beginRun(iRun.run());
00091 
00092 }
00093 
00094 void  RunHistogramManager::beginRun(const unsigned int irun) {
00095 
00096   edm::Service<TFileService> tfserv;
00097   beginRun(irun,*tfserv);
00098 
00099 }
00100 
00101 void  RunHistogramManager::beginRun(const unsigned int irun, TFileDirectory& subdir) {
00102   
00103   // create/go to the run subdirectory
00104   
00105   char dirname[300];
00106   sprintf(dirname,"run_%d",irun);
00107   TFileDirectory subrun = subdir.mkdir(dirname);
00108   
00109   // loop on the histograms and update the pointer references
00110   
00111   for(unsigned int ih=0;ih<_histograms.size();++ih) {
00112     
00113     _histograms[ih]->beginRun(irun,subrun);
00114     
00115   }
00116 }
00117