CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DQMServices/Components/src/DQMEventInfo.cc

Go to the documentation of this file.
00001 /*
00002  * \file DQMEventInfo.cc
00003  * \author M. Zanetti - CERN PH
00004  * Last Update:
00005  * $Date: 2011/03/25 09:26:49 $
00006  * $Revision: 1.33 $
00007  * $Author: lilopera $
00008  *
00009  */
00010 #include "DQMEventInfo.h"
00011 #include "FWCore/Framework/interface/LuminosityBlock.h"
00012 #include "FWCore/Version/interface/GetReleaseVersion.h"
00013 #include "FWCore/ParameterSet/interface/Registry.h"
00014 #include <TSystem.h>
00015 
00016 #include <stdio.h>
00017 #include <sstream>
00018 #include <math.h>
00019 
00020 
00021 static inline double stampToReal(edm::Timestamp time)
00022 { return (time.value() >> 32) + 1e-6*(time.value() & 0xffffffff); }
00023 
00024 static inline double stampToReal(const timeval &time)
00025 { return time.tv_sec + 1e-6*time.tv_usec; }
00026 
00027 
00028 DQMEventInfo::DQMEventInfo(const edm::ParameterSet& ps){
00029   
00030   struct timeval now;
00031   gettimeofday(&now, 0);
00032 
00033   parameters_ = ps;
00034   pEvent_ = 0;
00035   evtRateCount_ = 0;
00036   lastAvgTime_ = currentTime_ = stampToReal(now);
00037 
00038   // read config parms  
00039   std::string folder = parameters_.getUntrackedParameter<std::string>("eventInfoFolder", "EventInfo") ;
00040   std::string subsystemname = parameters_.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem") ;
00041   
00042   eventInfoFolder_ = subsystemname + "/" +  folder ;
00043   evtRateWindow_ = parameters_.getUntrackedParameter<double>("eventRateWindow", 0.5);
00044   if(evtRateWindow_<=0.15) evtRateWindow_=0.15;
00045 
00046   // 
00047   dbe_ = edm::Service<DQMStore>().operator->();
00048 
00049   dbe_->setCurrentFolder(eventInfoFolder_) ;
00050 
00051   //Event specific contents
00052   runId_     = dbe_->bookInt("iRun");
00053   runId_->Fill(-1);
00054   lumisecId_ = dbe_->bookInt("iLumiSection");
00055   lumisecId_->Fill(-1);
00056   eventId_   = dbe_->bookInt("iEvent");
00057   eventId_->Fill(-1);
00058   eventTimeStamp_ = dbe_->bookFloat("eventTimeStamp");
00059   
00060   dbe_->setCurrentFolder(eventInfoFolder_) ;
00061   //Process specific contents
00062   processTimeStamp_ = dbe_->bookFloat("processTimeStamp");
00063   processTimeStamp_->Fill(currentTime_);
00064   processLatency_ = dbe_->bookFloat("processLatency");
00065   processTimeStamp_->Fill(-1);
00066   processEvents_ = dbe_->bookInt("processedEvents");
00067   processEvents_->Fill(pEvent_);
00068   processEventRate_ = dbe_->bookFloat("processEventRate");
00069   processEventRate_->Fill(-1); 
00070   nUpdates_= dbe_->bookInt("processUpdates");
00071   nUpdates_->Fill(-1);
00072 
00073   //Static Contents
00074   processId_= dbe_->bookInt("processID"); 
00075   processId_->Fill(gSystem->GetPid());
00076   processStartTimeStamp_ = dbe_->bookFloat("processStartTimeStamp");
00077   processStartTimeStamp_->Fill(currentTime_);
00078   runStartTimeStamp_ = dbe_->bookFloat("runStartTimeStamp");
00079   hostName_= dbe_->bookString("hostName",gSystem->HostName());
00080   processName_= dbe_->bookString("processName",subsystemname);
00081   workingDir_= dbe_->bookString("workingDir",gSystem->pwd());
00082   cmsswVer_= dbe_->bookString("CMSSW_Version",edm::getReleaseVersion());
00083  
00084   // Folder to be populated by sub-systems' code
00085   std::string subfolder = eventInfoFolder_ + "/reportSummaryContents" ;
00086   dbe_->setCurrentFolder(subfolder);
00087 
00088 }
00089 
00090 DQMEventInfo::~DQMEventInfo(){
00091 }
00092 
00093 void DQMEventInfo::beginRun(const edm::Run& r, const edm::EventSetup &c ) 
00094 {
00095     
00096   runId_->Fill(r.id().run());
00097   runStartTimeStamp_->Fill(stampToReal(r.beginTime()));
00098   
00099   //Online static histograms
00100   const edm::ParameterSet &sourcePSet = edm::getProcessParameterSet().getParameterSet("@main_input");
00101   if (sourcePSet.getParameter<std::string>("@module_type") == "EventStreamHttpReader" ){
00102     std::string evSelection;
00103     std::vector<std::string> evSelectionList; 
00104     const edm::ParameterSet &evSelectionPSet = sourcePSet.getUntrackedParameterSet("SelectEvents");
00105     evSelectionList = evSelectionPSet.getParameter<std::vector<std::string> >("SelectEvents");
00106     for ( std::vector<std::string>::iterator it = evSelectionList.begin(); it <  evSelectionList.end(); it++ )
00107       evSelection += "'"+ *it + "', ";
00108       
00109     evSelection.resize(evSelection.length()-2);
00110     dbe_->setCurrentFolder(eventInfoFolder_);
00111     dbe_->bookString("eventSelection",evSelection);
00112   }
00113   
00114 } 
00115 
00116 void DQMEventInfo::beginLuminosityBlock(const edm::LuminosityBlock& l, const edm::EventSetup& c) {
00117 
00118   lumisecId_->Fill(l.id().luminosityBlock());
00119 
00120 }
00121 
00122 void DQMEventInfo::analyze(const edm::Event& e, const edm::EventSetup& c){
00123  
00124   eventId_->Fill(int64_t(e.id().event()));
00125   eventTimeStamp_->Fill(stampToReal(e.time()));
00126 
00127   pEvent_++;
00128   evtRateCount_++;
00129   processEvents_->Fill(pEvent_);
00130 
00131   struct timeval now;
00132   gettimeofday(&now, 0);
00133   lastUpdateTime_ = currentTime_;
00134   currentTime_ = stampToReal(now);
00135 
00136   processTimeStamp_->Fill(currentTime_);
00137   processLatency_->Fill(currentTime_ - lastUpdateTime_);
00138 
00139   double delta = currentTime_ - lastAvgTime_;
00140   if (delta >= (evtRateWindow_*60.0))
00141   {
00142     processEventRate_->Fill(evtRateCount_/delta);
00143     evtRateCount_ = 0;
00144     lastAvgTime_ = currentTime_;    
00145   }
00146   
00147   return;
00148 }