Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-07 00:41:10

0001 /*
0002  * \file DQMEventInfo.h
0003  *
0004  * \author M. Zanetti - INFN Padova
0005  *
0006 */
0007 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0008 #include "FWCore/Framework/interface/LuminosityBlock.h"
0009 #include "FWCore/Version/interface/GetReleaseVersion.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/Run.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 
0016 #include <algorithm>
0017 #include <iostream>
0018 #include <sstream>
0019 #include <fstream>
0020 #include <string>
0021 #include <vector>
0022 #include <memory>
0023 #include <cstdio>
0024 #include <cmath>
0025 #include <map>
0026 
0027 #include <sys/time.h>
0028 #include <TSystem.h>
0029 
0030 #include <boost/algorithm/string/join.hpp>
0031 
0032 class DQMEventInfo : public DQMOneEDAnalyzer<> {
0033 public:
0034   /// Constructor
0035   DQMEventInfo(const edm::ParameterSet& ps);
0036 
0037   /// Destructor
0038   ~DQMEventInfo() override = default;
0039 
0040 protected:
0041   /// Analyze
0042   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0043   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0044 
0045 private:
0046   std::string eventInfoFolder_;
0047   std::string subsystemname_;
0048 
0049   double currentTime_, lastUpdateTime_, lastAvgTime_;
0050   double runStartTime_;
0051   double evtRateWindow_;
0052   int64_t evtRateCount_;
0053   int64_t pEvent_;
0054 
0055   //////////////////////////////////////////////////////////////////
0056   ///These MEs are filled with the info from the most recent event
0057   ///   by the module
0058   //////////////////////////////////////////////////////////////////
0059   MonitorElement* runId_;
0060   MonitorElement* runStartTimeStamp_;  ///UTC time of the run start
0061   MonitorElement* eventId_;
0062   MonitorElement* lumisecId_;
0063   MonitorElement* eventTimeStamp_;
0064 
0065   //////////////////////////////////////////////////////////////////
0066   ///These MEs are either static or updated upon each analyze() call
0067   //////////////////////////////////////////////////////////////////
0068   MonitorElement* nUpdates_;               ///Number of collector updates (TBD)
0069   MonitorElement* processId_;              ///The PID associated with this job
0070   MonitorElement* processStartTimeStamp_;  ///The UTC time of the first event processed
0071   MonitorElement* processTimeStamp_;       ///The UTC time of the last event
0072   MonitorElement* processLatency_;         ///Time elapsed since the last event
0073   MonitorElement* processEventRate_;       ///Avg # of events in programmable window (default: 5 min)
0074   MonitorElement* processEvents_;          ///# of event processed so far
0075   MonitorElement* hostName_;               ///Hostname of the local machine
0076   MonitorElement* processName_;            ///DQM "name" of the job (eg, Hcal or DT)
0077   MonitorElement* workingDir_;             ///Current working directory of the job
0078   MonitorElement* cmsswVer_;               ///CMSSW version run for this job
0079   MonitorElement* dqmPatch_;               ///DQM patch version for this job
0080   MonitorElement* errSummary_;             ///Subdetector-specific error summary (float)
0081   MonitorElement* errSummaryEtaPhi_;       ///Subdetector-specific etaPhi summary (float)
0082   MonitorElement* errSummarySegment_[10];
0083 };
0084 
0085 static inline double stampToReal(edm::Timestamp time) {
0086   return (time.value() >> 32) + 1e-6 * (time.value() & 0xffffffff);
0087 }
0088 
0089 static inline double stampToReal(const timeval& time) { return time.tv_sec + 1e-6 * time.tv_usec; }
0090 
0091 DQMEventInfo::DQMEventInfo(const edm::ParameterSet& ps) {
0092   struct timeval now;
0093   gettimeofday(&now, nullptr);
0094 
0095   pEvent_ = 0;
0096   evtRateCount_ = 0;
0097   lastAvgTime_ = currentTime_ = stampToReal(now);
0098 
0099   // read config parms
0100   std::string folder = ps.getUntrackedParameter<std::string>("eventInfoFolder", "EventInfo");
0101   subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");
0102 
0103   eventInfoFolder_ = subsystemname_ + "/" + folder;
0104   evtRateWindow_ = ps.getUntrackedParameter<double>("eventRateWindow", 0.5);
0105   if (evtRateWindow_ <= 0.15)
0106     evtRateWindow_ = 0.15;
0107 }
0108 
0109 void DQMEventInfo::bookHistograms(DQMStore::IBooker& ibooker,
0110                                   edm::Run const& iRun,
0111                                   edm::EventSetup const& /* iSetup */) {
0112   ibooker.setCurrentFolder(eventInfoFolder_);
0113 
0114   //Event specific contents
0115   runId_ = ibooker.bookInt("iRun");
0116   runId_->Fill(iRun.id().run());
0117   lumisecId_ = ibooker.bookInt("iLumiSection");
0118   lumisecId_->Fill(-1);
0119   eventId_ = ibooker.bookInt("iEvent");
0120   eventId_->Fill(-1);
0121   eventTimeStamp_ = ibooker.bookFloat("eventTimeStamp");
0122 
0123   ibooker.setCurrentFolder(eventInfoFolder_);
0124   //Process specific contents
0125   processTimeStamp_ = ibooker.bookFloat("processTimeStamp");
0126   processTimeStamp_->Fill(currentTime_);
0127   processLatency_ = ibooker.bookFloat("processLatency");
0128   processTimeStamp_->Fill(-1);
0129   processEvents_ = ibooker.bookInt("processedEvents");
0130   processEvents_->Fill(pEvent_);
0131   processEventRate_ = ibooker.bookFloat("processEventRate");
0132   processEventRate_->Fill(-1);
0133   nUpdates_ = ibooker.bookInt("processUpdates");
0134   nUpdates_->Fill(-1);
0135 
0136   //Static Contents
0137   processId_ = ibooker.bookInt("processID");
0138   processId_->Fill(getpid());
0139   processStartTimeStamp_ = ibooker.bookFloat("processStartTimeStamp");
0140   processStartTimeStamp_->Fill(currentTime_);
0141   runStartTimeStamp_ = ibooker.bookFloat("runStartTimeStamp");
0142   runStartTimeStamp_->Fill(stampToReal(iRun.beginTime()));
0143   char hostname[65];
0144   gethostname(hostname, 64);
0145   hostname[64] = 0;
0146   hostName_ = ibooker.bookString("hostName", hostname);
0147   processName_ = ibooker.bookString("processName", subsystemname_);
0148   char* pwd = getcwd(nullptr, 0);
0149   workingDir_ = ibooker.bookString("workingDir", pwd);
0150   free(pwd);
0151   cmsswVer_ = ibooker.bookString("CMSSW_Version", edm::getReleaseVersion());
0152 
0153   // Folder to be populated by sub-systems' code
0154   std::string subfolder = eventInfoFolder_ + "/reportSummaryContents";
0155   ibooker.setCurrentFolder(subfolder);
0156 
0157   //Online static histograms
0158   const edm::ParameterSet& sourcePSet =
0159       edm::getProcessParameterSetContainingModule(moduleDescription()).getParameterSet("@main_input");
0160 
0161   if (sourcePSet.getParameter<std::string>("@module_type") == "DQMStreamerReader") {
0162     std::string evSelection;
0163     std::vector<std::string> evSelectionList;
0164     std::string delimiter(", ");
0165     evSelectionList = sourcePSet.getUntrackedParameter<std::vector<std::string> >("SelectEvents");
0166     // add single quotes inline in the vector of HLT paths:
0167     // we do copy assignment, and getUntrackedParameter returns
0168     // a by-value copy of the vector of strings
0169     std::for_each(evSelectionList.begin(), evSelectionList.end(), [](std::string& s) {
0170       std::string squote("'");
0171       s = squote + s + squote;
0172     });
0173     evSelection = boost::algorithm::join(evSelectionList, delimiter);
0174     // if no HLT paths are specified, no selections are performed:
0175     // we mark this with an asterisk.
0176     if (evSelection.empty()) {
0177       evSelection = std::string("'*'");
0178     }
0179     ibooker.setCurrentFolder(eventInfoFolder_);
0180     ibooker.bookString("eventSelection", evSelection);
0181   }
0182 }
0183 
0184 void DQMEventInfo::analyze(const edm::Event& e, const edm::EventSetup& c) {
0185   //Filling lumi here guarantees that the lumi number corresponds to the event when
0186   // using multiple concurrent lumis in a job
0187   lumisecId_->Fill(e.id().luminosityBlock());
0188   eventId_->Fill(e.id().event());  // Handing edm::EventNumber_t to Fill method which will handle further casting
0189   eventTimeStamp_->Fill(stampToReal(e.time()));
0190 
0191   pEvent_++;
0192   evtRateCount_++;
0193   processEvents_->Fill(pEvent_);
0194 
0195   struct timeval now;
0196   gettimeofday(&now, nullptr);
0197   lastUpdateTime_ = currentTime_;
0198   currentTime_ = stampToReal(now);
0199 
0200   processTimeStamp_->Fill(currentTime_);
0201   processLatency_->Fill(currentTime_ - lastUpdateTime_);
0202 
0203   double delta = currentTime_ - lastAvgTime_;
0204   if (delta >= (evtRateWindow_ * 60.0)) {
0205     processEventRate_->Fill(evtRateCount_ / delta);
0206     evtRateCount_ = 0;
0207     lastAvgTime_ = currentTime_;
0208   }
0209 
0210   return;
0211 }
0212 
0213 #include "FWCore/Framework/interface/MakerMacros.h"
0214 DEFINE_FWK_MODULE(DQMEventInfo);