CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/HLTrigger/Timer/plugins/FastTimerServiceClient.cc

Go to the documentation of this file.
00001 // C++ headers
00002 #include <string>
00003 #include <cstring>
00004 
00005 // boost headers
00006 #include <boost/foreach.hpp>
00007 
00008 // Root headers
00009 #include <TH1F.h>
00010 
00011 // CMSSW headers
00012 #include "FWCore/Framework/interface/Frameworkfwd.h"
00013 #include "FWCore/Framework/interface/EDAnalyzer.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/Run.h"
00016 #include "FWCore/Framework/interface/LuminosityBlock.h"
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00020 #include "FWCore/ParameterSet/interface/Registry.h"
00021 #include "FWCore/ServiceRegistry/interface/Service.h"
00022 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00023 #include "DQMServices/Core/interface/DQMStore.h"
00024 #include "DQMServices/Core/interface/MonitorElement.h"
00025 
00026 class FastTimerServiceClient : public edm::EDAnalyzer {
00027 public:
00028   explicit FastTimerServiceClient(edm::ParameterSet const &);
00029   ~FastTimerServiceClient();
00030 
00031   static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00032 
00033 private:
00034   std::string m_dqm_path;
00035 
00036   void analyze(const edm::Event & event, const edm::EventSetup & setup);
00037   void beginJob();
00038   void endJob();
00039   void beginRun(edm::Run const & run, edm::EventSetup const & setup);
00040   void endRun  (edm::Run const & run, edm::EventSetup const & setup);
00041   void beginLuminosityBlock(edm::LuminosityBlock const & lumi, edm::EventSetup const & setup);
00042   void endLuminosityBlock  (edm::LuminosityBlock const & lumi, edm::EventSetup const & setup);
00043 };
00044 
00045 FastTimerServiceClient::FastTimerServiceClient(edm::ParameterSet const & config) :
00046   m_dqm_path( config.getUntrackedParameter<std::string>( "dqmPath", "TimerService") )
00047 {
00048 }
00049 
00050 FastTimerServiceClient::~FastTimerServiceClient()
00051 {
00052 }
00053 
00054 void
00055 FastTimerServiceClient::analyze(edm::Event const & event, edm::EventSetup const & setup) 
00056 {
00057 }
00058 
00059 void
00060 FastTimerServiceClient::beginJob(void)
00061 {
00062 }
00063 
00064 void
00065 FastTimerServiceClient::endJob(void)
00066 {
00067 }
00068 
00069 void
00070 FastTimerServiceClient::beginRun(edm::Run const & run, edm::EventSetup const & setup)
00071 {
00072 }
00073 
00074 void
00075 FastTimerServiceClient::endRun(edm::Run const & run, edm::EventSetup const & setup)
00076 {
00077   DQMStore * dqm = edm::Service<DQMStore>().operator->();
00078   if (dqm == 0)
00079     // cannot access the DQM store
00080     return;
00081   
00082   MonitorElement * me;
00083   me = dqm->get(m_dqm_path + "/event");
00084   if (me == 0)
00085     // no FastTimerService DQM information
00086     return;
00087   double events = me->getTH1F()->GetEntries();
00088 
00089   // fill summary histograms with the average (total and active) time spent in each path
00090   dqm->setCurrentFolder(m_dqm_path);
00091   TH1F * path_active = dqm->get(m_dqm_path + "/path_active_time")->getTH1F();
00092   TH1F * path_total  = dqm->get(m_dqm_path + "/path_total_time")->getTH1F();
00093   size_t size = path_total->GetXaxis()->GetNbins();
00094   for (size_t i = 0; i < size; ++i) {
00095     // extract the list of Paths and EndPaths from the bin labels of "path_total_time"
00096     std::string label = path_total->GetXaxis()->GetBinLabel(i+1);   // bin count from 1 (bin 0 is underflow)
00097     if (( me = dqm->get(m_dqm_path + "/Paths/" + label + "_total") ))
00098       path_total ->Fill(i, me->getTH1F()->GetMean());
00099     if (( me = dqm->get(m_dqm_path + "/Paths/" + label + "_active") ))
00100       path_active->Fill(i, me->getTH1F()->GetMean());
00101   }
00102 
00103   // for each path, fill histograms with
00104   //  - the average time spent in each module (total time spent in that module, averaged over all events)
00105   //  - the running time spent in each module (total time spent in that module, averaged over the events where that module actually ran)
00106   //  - the "efficiency" of each module (number of time a module succeded divided by the number of times the has run)
00107   dqm->setCurrentFolder(m_dqm_path + "/Paths");
00108   for (size_t p = 1; p <= size; ++p) {
00109     // extract the list of Paths and EndPaths from the bin labels of "path_total_time"
00110     std::string label = path_total->GetXaxis()->GetBinLabel(p);
00111     TH1F * counter = dqm->get( m_dqm_path + "/Paths/" + label + "_module_counter" )->getTH1F();
00112     TH1F * total   = dqm->get( m_dqm_path + "/Paths/" + label + "_module_total"   )->getTH1F();
00113     if (counter == 0 or total == 0)
00114       continue;
00115     size_t bins = counter->GetXaxis()->GetNbins();
00116     double min  = counter->GetXaxis()->GetXmin();
00117     double max  = counter->GetXaxis()->GetXmax();
00118     TH1F * average    = dqm->book1D(label + "_module_average",    label + " module average",    bins, min, max)->getTH1F();
00119     TH1F * running    = dqm->book1D(label + "_module_running",    label + " module running",    bins, min, max)->getTH1F();
00120     TH1F * efficiency = dqm->book1D(label + "_module_efficiency", label + " module efficiency", bins, min, max)->getTH1F();
00121     for (size_t i = 1; i <= bins; ++i) {
00122       const char * module = counter->GetXaxis()->GetBinLabel(i);
00123       average   ->GetXaxis()->SetBinLabel(i, module);
00124       running   ->GetXaxis()->SetBinLabel(i, module);
00125       efficiency->GetXaxis()->SetBinLabel(i, module);
00126       double x = total  ->GetBinContent(i);
00127       double n = counter->GetBinContent(i);
00128       double p = counter->GetBinContent(i+1);
00129       average   ->SetBinContent(i, x / events);
00130       if (n) {
00131         running   ->SetBinContent(i, x / n);
00132         efficiency->SetBinContent(i, p / n);
00133       }
00134     }
00135   }
00136 
00137 }
00138 
00139 void
00140 FastTimerServiceClient::beginLuminosityBlock(edm::LuminosityBlock const & lumi, edm::EventSetup const & setup)
00141 {
00142 }
00143 
00144 void
00145 FastTimerServiceClient::endLuminosityBlock(edm::LuminosityBlock const & lumi, edm::EventSetup const & setup)
00146 {
00147 }
00148 
00149 void
00150 FastTimerServiceClient::fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
00151   // The following says we do not know what parameters are allowed so do no validation
00152   // Please change this to state exactly what you do use, even if it is no parameters
00153   edm::ParameterSetDescription desc;
00154   desc.setUnknown();
00155   descriptions.addDefault(desc);
00156 }
00157 
00158 //define this as a plug-in
00159 #include "FWCore/Framework/interface/MakerMacros.h"
00160 DEFINE_FWK_MODULE(FastTimerServiceClient);