File indexing completed on 2024-06-25 22:34:53
0001
0002
0003
0004
0005
0006
0007 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0008 #include "FWCore/Framework/interface/Event.h"
0009 #include "FWCore/Framework/interface/LuminosityBlock.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 #include "FWCore/Framework/interface/Run.h"
0012 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015 #include "FWCore/ServiceRegistry/interface/Service.h"
0016 #include "FWCore/Version/interface/GetReleaseVersion.h"
0017
0018 #include <algorithm>
0019 #include <iostream>
0020 #include <sstream>
0021 #include <fstream>
0022 #include <string>
0023 #include <vector>
0024 #include <memory>
0025 #include <cstdio>
0026 #include <cmath>
0027 #include <map>
0028
0029 #include <sys/time.h>
0030 #include <TSystem.h>
0031
0032 #include <boost/algorithm/string/join.hpp>
0033
0034 class DQMEventInfo : public DQMOneEDAnalyzer<> {
0035 public:
0036
0037 DQMEventInfo(const edm::ParameterSet& ps);
0038
0039
0040 ~DQMEventInfo() override = default;
0041
0042 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0043
0044 protected:
0045
0046 void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0047 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0048 void analyzeProvInfo(const edm::Event& e);
0049
0050 private:
0051 std::string globalTag_;
0052 bool globalTagRetrieved_;
0053 bool showHLTGlobalTag_;
0054
0055 std::string eventInfoFolder_;
0056 std::string subsystemname_;
0057
0058 double currentTime_, lastUpdateTime_, lastAvgTime_;
0059 double runStartTime_;
0060 double evtRateWindow_;
0061 int64_t evtRateCount_;
0062 int64_t pEvent_;
0063
0064
0065
0066
0067
0068 MonitorElement* runId_;
0069 MonitorElement* runStartTimeStamp_;
0070 MonitorElement* eventId_;
0071 MonitorElement* lumisecId_;
0072 MonitorElement* eventTimeStamp_;
0073
0074
0075
0076
0077 MonitorElement* nUpdates_;
0078 MonitorElement* processId_;
0079 MonitorElement* processStartTimeStamp_;
0080 MonitorElement* processTimeStamp_;
0081 MonitorElement* processLatency_;
0082 MonitorElement* processEventRate_;
0083 MonitorElement* processEvents_;
0084 MonitorElement* hostName_;
0085 MonitorElement* processName_;
0086 MonitorElement* workingDir_;
0087 MonitorElement* cmsswVer_;
0088 MonitorElement* versGlobaltag_;
0089 MonitorElement* dqmPatch_;
0090 MonitorElement* errSummary_;
0091 MonitorElement* errSummaryEtaPhi_;
0092 MonitorElement* errSummarySegment_[10];
0093 };
0094
0095 static inline double stampToReal(edm::Timestamp time) {
0096 return (time.value() >> 32) + 1e-6 * (time.value() & 0xffffffff);
0097 }
0098
0099 static inline double stampToReal(const timeval& time) { return time.tv_sec + 1e-6 * time.tv_usec; }
0100
0101 DQMEventInfo::DQMEventInfo(const edm::ParameterSet& ps) {
0102 struct timeval now;
0103 gettimeofday(&now, nullptr);
0104
0105 pEvent_ = 0;
0106 evtRateCount_ = 0;
0107 lastAvgTime_ = currentTime_ = stampToReal(now);
0108
0109
0110 showHLTGlobalTag_ = ps.getUntrackedParameter<bool>("showHLTGlobalTag", false);
0111 std::string folder = ps.getUntrackedParameter<std::string>("eventInfoFolder", "EventInfo");
0112 subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");
0113
0114 eventInfoFolder_ = subsystemname_ + "/" + folder;
0115 evtRateWindow_ = ps.getUntrackedParameter<double>("eventRateWindow", 0.5);
0116 if (evtRateWindow_ <= 0.15)
0117 evtRateWindow_ = 0.15;
0118
0119
0120 globalTag_ = "MODULE::DEFAULT";
0121 globalTagRetrieved_ = false;
0122 }
0123
0124 void DQMEventInfo::bookHistograms(DQMStore::IBooker& ibooker,
0125 edm::Run const& iRun,
0126 edm::EventSetup const& ) {
0127 ibooker.setCurrentFolder(eventInfoFolder_);
0128
0129
0130 runId_ = ibooker.bookInt("iRun");
0131 runId_->Fill(iRun.id().run());
0132 lumisecId_ = ibooker.bookInt("iLumiSection");
0133 lumisecId_->Fill(-1);
0134 eventId_ = ibooker.bookInt("iEvent");
0135 eventId_->Fill(-1);
0136 eventTimeStamp_ = ibooker.bookFloat("eventTimeStamp");
0137
0138 ibooker.setCurrentFolder(eventInfoFolder_);
0139
0140 processTimeStamp_ = ibooker.bookFloat("processTimeStamp");
0141 processTimeStamp_->Fill(currentTime_);
0142 processLatency_ = ibooker.bookFloat("processLatency");
0143 processTimeStamp_->Fill(-1);
0144 processEvents_ = ibooker.bookInt("processedEvents");
0145 processEvents_->Fill(pEvent_);
0146 processEventRate_ = ibooker.bookFloat("processEventRate");
0147 processEventRate_->Fill(-1);
0148 nUpdates_ = ibooker.bookInt("processUpdates");
0149 nUpdates_->Fill(-1);
0150
0151
0152 processId_ = ibooker.bookInt("processID");
0153 processId_->Fill(getpid());
0154 processStartTimeStamp_ = ibooker.bookFloat("processStartTimeStamp");
0155 processStartTimeStamp_->Fill(currentTime_);
0156 runStartTimeStamp_ = ibooker.bookFloat("runStartTimeStamp");
0157 runStartTimeStamp_->Fill(stampToReal(iRun.beginTime()));
0158 char hostname[65];
0159 gethostname(hostname, 64);
0160 hostname[64] = 0;
0161 hostName_ = ibooker.bookString("hostName", hostname);
0162 processName_ = ibooker.bookString("processName", subsystemname_);
0163 char* pwd = getcwd(nullptr, 0);
0164 workingDir_ = ibooker.bookString("workingDir", pwd);
0165 free(pwd);
0166 cmsswVer_ = ibooker.bookString("CMSSW_Version", edm::getReleaseVersion());
0167
0168
0169 versGlobaltag_ = ibooker.bookString("Globaltag", globalTag_);
0170
0171
0172 std::string subfolder = eventInfoFolder_ + "/reportSummaryContents";
0173 ibooker.setCurrentFolder(subfolder);
0174
0175
0176 const edm::ParameterSet& sourcePSet =
0177 edm::getProcessParameterSetContainingModule(moduleDescription()).getParameterSet("@main_input");
0178
0179 if (sourcePSet.getParameter<std::string>("@module_type") == "DQMStreamerReader") {
0180 std::string evSelection;
0181 std::vector<std::string> evSelectionList;
0182 std::string delimiter(", ");
0183 evSelectionList = sourcePSet.getUntrackedParameter<std::vector<std::string> >("SelectEvents");
0184
0185
0186
0187 std::for_each(evSelectionList.begin(), evSelectionList.end(), [](std::string& s) {
0188 std::string squote("'");
0189 s = squote + s + squote;
0190 });
0191 evSelection = boost::algorithm::join(evSelectionList, delimiter);
0192
0193
0194 if (evSelection.empty()) {
0195 evSelection = std::string("'*'");
0196 }
0197 ibooker.setCurrentFolder(eventInfoFolder_);
0198 ibooker.bookString("eventSelection", evSelection);
0199 }
0200 }
0201
0202 void DQMEventInfo::analyze(const edm::Event& e, const edm::EventSetup& c) {
0203
0204
0205 lumisecId_->Fill(e.id().luminosityBlock());
0206 eventId_->Fill(e.id().event());
0207 eventTimeStamp_->Fill(stampToReal(e.time()));
0208
0209 pEvent_++;
0210 evtRateCount_++;
0211 processEvents_->Fill(pEvent_);
0212
0213 struct timeval now;
0214 gettimeofday(&now, nullptr);
0215 lastUpdateTime_ = currentTime_;
0216 currentTime_ = stampToReal(now);
0217
0218 processTimeStamp_->Fill(currentTime_);
0219 processLatency_->Fill(currentTime_ - lastUpdateTime_);
0220
0221 double delta = currentTime_ - lastAvgTime_;
0222 if (delta >= (evtRateWindow_ * 60.0)) {
0223 processEventRate_->Fill(evtRateCount_ / delta);
0224 evtRateCount_ = 0;
0225 lastAvgTime_ = currentTime_;
0226 }
0227
0228 analyzeProvInfo(e);
0229
0230 return;
0231 }
0232
0233 void DQMEventInfo::analyzeProvInfo(const edm::Event& event) {
0234
0235
0236 if (!globalTagRetrieved_) {
0237
0238 std::string processName;
0239
0240 if (showHLTGlobalTag_) {
0241
0242 std::vector<std::string> pnames;
0243 for (const auto& p : event.processHistory()) {
0244 pnames.push_back(p.processName());
0245 }
0246
0247
0248 for (auto it = pnames.rbegin(); it != pnames.rend(); ++it) {
0249 if (it->find("HLT") != std::string::npos) {
0250 processName = *it;
0251 break;
0252 }
0253 }
0254
0255
0256 if (processName.empty()) {
0257 edm::LogError("DQMEventInfo") << "Could not find any processName containing 'HLT' even if 'showHLTGlobalTag' "
0258 "was chosen.\n Falling back to current processing!"
0259 << std::endl;
0260 processName = event.processHistory()[event.processHistory().size() - 1].processName();
0261 }
0262 } else {
0263 processName = event.processHistory()[event.processHistory().size() - 1].processName();
0264 }
0265
0266
0267 edm::ParameterSet ps;
0268 event.getProcessParameterSet(processName, ps);
0269
0270
0271 if (ps.exists("PoolDBESSource@GlobalTag")) {
0272
0273 globalTag_ = ps.getParameterSet("PoolDBESSource@GlobalTag").getParameter<std::string>("globaltag");
0274 } else {
0275
0276
0277 edm::LogInfo("Configuration") << "ParameterSet 'PoolDBESSource@GlobalTag' not found. Using default global tag.";
0278 }
0279
0280 versGlobaltag_->Fill(globalTag_);
0281
0282 globalTagRetrieved_ = true;
0283 }
0284 }
0285
0286 void DQMEventInfo::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0287 edm::ParameterSetDescription desc;
0288 desc.addUntracked<bool>("showHLTGlobalTag", false);
0289 desc.addUntracked<std::string>("eventInfoFolder", "EventInfo");
0290 desc.addUntracked<std::string>("subSystemFolder", "YourSubsystem");
0291 desc.addUntracked<double>("eventRateWindow", 0.5);
0292 descriptions.addWithDefaultLabel(desc);
0293 }
0294
0295 #include "FWCore/Framework/interface/MakerMacros.h"
0296 DEFINE_FWK_MODULE(DQMEventInfo);