CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/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 "DataFormats/Common/interface/ConditionsInEdm.h"
00007 #include "TH1F.h"
00008 #include "TH2F.h"
00009 #include "TProfile.h"
00010 #include "TProfile2D.h"
00011 
00012 BaseHistoParams::BaseHistoParams() { }
00013 
00014 BaseHistoParams::~BaseHistoParams() { }
00015 
00016 /*
00017 void BaseHistoParams::beginRun(const edm::Run& iRun, TFileDirectory& subrun) {
00018   
00019   beginRun(iRun.run(),subrun);
00020 
00021 }
00022 */
00023 
00024 
00025 
00026 RunHistogramManager::RunHistogramManager(const bool fillHistograms):
00027   _fillHistograms(fillHistograms), _histograms() { }
00028 
00029 TH1F** RunHistogramManager::makeTH1F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
00030 
00031   TH1F** pointer =new TH1F*(0);
00032 
00033   BaseHistoParams* hp = new HistoParams<TH1F>(pointer,"TH1F",name,title,nbinx,xmin,xmax);
00034   _histograms.push_back(hp);
00035 
00036   LogDebug("TH1Fmade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
00037 
00038   return pointer;
00039 
00040 }
00041 
00042 RunHistogramManager::~RunHistogramManager() {
00043 
00044   for(std::vector<BaseHistoParams*>::const_iterator hp=_histograms.begin();hp!=_histograms.end();++hp) {
00045 
00046     delete *hp;
00047 
00048   }
00049   LogDebug("Destructor") << "All BaseHistoParams destroyed ";
00050 
00051 }
00052 
00053 TProfile** RunHistogramManager::makeTProfile(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
00054 
00055   TProfile** pointer =new TProfile*(0);
00056 
00057   BaseHistoParams* hp = new HistoParams<TProfile>(pointer,"TProfile",name,title,nbinx,xmin,xmax);
00058   _histograms.push_back(hp);
00059 
00060   LogDebug("TProfilemade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
00061 
00062   return pointer;
00063 
00064 }
00065 
00066 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 ) {
00067 
00068   TH2F** pointer  = new TH2F*(0);
00069 
00070   BaseHistoParams* hp = new HistoParams<TH2F>(pointer,"TH2F",name,title,nbinx,xmin,xmax,nbiny,ymin,ymax);
00071   _histograms.push_back(hp);
00072 
00073   LogDebug("TH2Fmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
00074 
00075   return pointer;
00076 }
00077 
00078 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 ) {
00079 
00080   TProfile2D** pointer  = new TProfile2D*(0);
00081 
00082   BaseHistoParams* hp = new HistoParams<TProfile2D>(pointer,"TProfile2D",name,title,nbinx,xmin,xmax,nbiny,ymin,ymax);
00083   _histograms.push_back(hp);
00084 
00085   LogDebug("TProfile2Dmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
00086 
00087   return pointer;
00088 }
00089 
00090 void  RunHistogramManager::beginRun(const edm::Run&  iRun) {
00091 
00092   edm::Service<TFileService> tfserv;
00093   beginRun(iRun,*tfserv);
00094 
00095 }
00096 
00097 void  RunHistogramManager::beginRun(const edm::Run& iRun, TFileDirectory& subdir) {
00098 
00099   if(!_fillHistograms) {
00100     beginRun(iRun.run(),subdir);
00101   }
00102   else {
00103     edm::Handle<edm::ConditionsInRunBlock> cirb;
00104     iRun.getByLabel("conditionsInEdm",cirb);
00105 
00106     beginRun(cirb->lhcFillNumber,subdir);
00107   }
00108 }
00109 
00110 void  RunHistogramManager::beginRun(const unsigned int irun) {
00111 
00112   edm::Service<TFileService> tfserv;
00113   beginRun(irun,*tfserv);
00114 
00115 }
00116 
00117 void  RunHistogramManager::beginRun(const unsigned int irun, TFileDirectory& subdir) {
00118   
00119   // create/go to the run subdirectory
00120   
00121   char fillrun[30];
00122 
00123   if(!_fillHistograms) {
00124     sprintf(fillrun,"%s","run");
00125   }
00126   else {
00127     sprintf(fillrun,"%s","fill");
00128   }
00129 
00130   char dirname[300];
00131   sprintf(dirname,"%s_%d",fillrun,irun);
00132   TFileDirectory subrun = subdir.mkdir(dirname);
00133   
00134   // loop on the histograms and update the pointer references
00135   
00136   for(unsigned int ih=0;ih<_histograms.size();++ih) {
00137     
00138     _histograms[ih]->beginRun(irun,subrun,fillrun);
00139     
00140   }
00141 }
00142