CMS 3D CMS Logo

DQMEventInfo.cc
Go to the documentation of this file.
1 /*
2  * \file DQMEventInfo.h
3  *
4  * \author M. Zanetti - INFN Padova
5  *
6 */
17 
18 #include <algorithm>
19 #include <iostream>
20 #include <sstream>
21 #include <fstream>
22 #include <string>
23 #include <vector>
24 #include <memory>
25 #include <cstdio>
26 #include <cmath>
27 #include <map>
28 
29 #include <sys/time.h>
30 #include <TSystem.h>
31 
32 #include <boost/algorithm/string/join.hpp>
33 
34 class DQMEventInfo : public DQMOneEDAnalyzer<> {
35 public:
38 
40  ~DQMEventInfo() override = default;
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 protected:
46  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
47  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
48  void analyzeProvInfo(const edm::Event& e);
49 
50 private:
54 
57 
59  double runStartTime_;
61  int64_t evtRateCount_;
62  int64_t pEvent_;
63 
73 
93 };
94 
95 static inline double stampToReal(edm::Timestamp time) {
96  return (time.value() >> 32) + 1e-6 * (time.value() & 0xffffffff);
97 }
98 
99 static inline double stampToReal(const timeval& time) { return time.tv_sec + 1e-6 * time.tv_usec; }
100 
102  struct timeval now;
103  gettimeofday(&now, nullptr);
104 
105  pEvent_ = 0;
106  evtRateCount_ = 0;
108 
109  // read config parms
110  showHLTGlobalTag_ = ps.getUntrackedParameter<bool>("showHLTGlobalTag", false);
111  std::string folder = ps.getUntrackedParameter<std::string>("eventInfoFolder", "EventInfo");
112  subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");
113 
115  evtRateWindow_ = ps.getUntrackedParameter<double>("eventRateWindow", 0.5);
116  if (evtRateWindow_ <= 0.15)
117  evtRateWindow_ = 0.15;
118 
119  // Initialization of the global tag
120  globalTag_ = "MODULE::DEFAULT"; // default
121  globalTagRetrieved_ = false; // set as soon as retrieved from first event
122 }
123 
125  edm::Run const& iRun,
126  edm::EventSetup const& /* iSetup */) {
128 
129  //Event specific contents
130  runId_ = ibooker.bookInt("iRun");
131  runId_->Fill(iRun.id().run());
132  lumisecId_ = ibooker.bookInt("iLumiSection");
133  lumisecId_->Fill(-1);
134  eventId_ = ibooker.bookInt("iEvent");
135  eventId_->Fill(-1);
136  eventTimeStamp_ = ibooker.bookFloat("eventTimeStamp");
137 
139  //Process specific contents
140  processTimeStamp_ = ibooker.bookFloat("processTimeStamp");
142  processLatency_ = ibooker.bookFloat("processLatency");
143  processTimeStamp_->Fill(-1);
144  processEvents_ = ibooker.bookInt("processedEvents");
146  processEventRate_ = ibooker.bookFloat("processEventRate");
147  processEventRate_->Fill(-1);
148  nUpdates_ = ibooker.bookInt("processUpdates");
149  nUpdates_->Fill(-1);
150 
151  //Static Contents
152  processId_ = ibooker.bookInt("processID");
153  processId_->Fill(getpid());
154  processStartTimeStamp_ = ibooker.bookFloat("processStartTimeStamp");
156  runStartTimeStamp_ = ibooker.bookFloat("runStartTimeStamp");
158  char hostname[65];
159  gethostname(hostname, 64);
160  hostname[64] = 0;
161  hostName_ = ibooker.bookString("hostName", hostname);
162  processName_ = ibooker.bookString("processName", subsystemname_);
163  char* pwd = getcwd(nullptr, 0);
164  workingDir_ = ibooker.bookString("workingDir", pwd);
165  free(pwd);
166  cmsswVer_ = ibooker.bookString("CMSSW_Version", edm::getReleaseVersion());
167 
168  // Element: Globaltag
169  versGlobaltag_ = ibooker.bookString("Globaltag", globalTag_);
170 
171  // Folder to be populated by sub-systems' code
172  std::string subfolder = eventInfoFolder_ + "/reportSummaryContents";
173  ibooker.setCurrentFolder(subfolder);
174 
175  //Online static histograms
176  const edm::ParameterSet& sourcePSet =
178 
179  if (sourcePSet.getParameter<std::string>("@module_type") == "DQMStreamerReader") {
180  std::string evSelection;
181  std::vector<std::string> evSelectionList;
182  std::string delimiter(", ");
183  evSelectionList = sourcePSet.getUntrackedParameter<std::vector<std::string> >("SelectEvents");
184  // add single quotes inline in the vector of HLT paths:
185  // we do copy assignment, and getUntrackedParameter returns
186  // a by-value copy of the vector of strings
187  std::for_each(evSelectionList.begin(), evSelectionList.end(), [](std::string& s) {
188  std::string squote("'");
189  s = squote + s + squote;
190  });
191  evSelection = boost::algorithm::join(evSelectionList, delimiter);
192  // if no HLT paths are specified, no selections are performed:
193  // we mark this with an asterisk.
194  if (evSelection.empty()) {
195  evSelection = std::string("'*'");
196  }
198  ibooker.bookString("eventSelection", evSelection);
199  }
200 }
201 
203  //Filling lumi here guarantees that the lumi number corresponds to the event when
204  // using multiple concurrent lumis in a job
205  lumisecId_->Fill(e.id().luminosityBlock());
206  eventId_->Fill(e.id().event()); // Handing edm::EventNumber_t to Fill method which will handle further casting
207  eventTimeStamp_->Fill(stampToReal(e.time()));
208 
209  pEvent_++;
210  evtRateCount_++;
212 
213  struct timeval now;
214  gettimeofday(&now, nullptr);
217 
220 
221  double delta = currentTime_ - lastAvgTime_;
222  if (delta >= (evtRateWindow_ * 60.0)) {
224  evtRateCount_ = 0;
226  }
227 
229 
230  return;
231 }
232 
234  // Only trying to retrieve the global tag for the first event we ever
235  // encounter.
236  if (!globalTagRetrieved_) {
237  // Initialize processName to an empty string
239 
240  if (showHLTGlobalTag_) {
241  // Getting all process names
242  std::vector<std::string> pnames;
243  for (const auto& p : event.processHistory()) {
244  pnames.push_back(p.processName());
245  }
246 
247  // Iterate through the process names in reverse to find the last one that contains "HLT"
248  for (auto it = pnames.rbegin(); it != pnames.rend(); ++it) {
249  if (it->find("HLT") != std::string::npos) {
250  processName = *it;
251  break; // Exit the loop once the last matching process name is found
252  }
253  }
254 
255  // Print the process name containing "HLT"
256  if (processName.empty()) {
257  edm::LogError("DQMEventInfo") << "Could not find any processName containing 'HLT' even if 'showHLTGlobalTag' "
258  "was chosen.\n Falling back to current processing!"
259  << std::endl;
260  processName = event.processHistory()[event.processHistory().size() - 1].processName();
261  }
262  } else {
263  processName = event.processHistory()[event.processHistory().size() - 1].processName();
264  }
265 
266  // Getting parameters for that process
268  event.getProcessParameterSet(processName, ps);
269 
270  // Check if the 'PoolDBESSource@GlobalTag' ParameterSet exists
271  if (ps.exists("PoolDBESSource@GlobalTag")) {
272  // Getting the global tag
273  globalTag_ = ps.getParameterSet("PoolDBESSource@GlobalTag").getParameter<std::string>("globaltag");
274  } else {
275  // Handle the case where 'PoolDBESSource@GlobalTag' is missing
276  // You can set a default value or take some other action
277  edm::LogInfo("Configuration") << "ParameterSet 'PoolDBESSource@GlobalTag' not found. Using default global tag.";
278  }
279 
281  // Finaly: Setting globalTagRetrieved_ to true, since we got it now
282  globalTagRetrieved_ = true;
283  }
284 }
285 
288  desc.addUntracked<bool>("showHLTGlobalTag", false);
289  desc.addUntracked<std::string>("eventInfoFolder", "EventInfo");
290  desc.addUntracked<std::string>("subSystemFolder", "YourSubsystem");
291  desc.addUntracked<double>("eventRateWindow", 0.5);
292  descriptions.addWithDefaultLabel(desc);
293 }
294 
double evtRateWindow_
Definition: DQMEventInfo.cc:60
double currentTime_
Definition: DQMEventInfo.cc:58
MonitorElement * hostName_
of event processed so far
Definition: DQMEventInfo.cc:84
MonitorElement * workingDir_
DQM "name" of the job (eg, Hcal or DT)
Definition: DQMEventInfo.cc:86
double lastUpdateTime_
Definition: DQMEventInfo.cc:58
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
MonitorElement * eventTimeStamp_
Definition: DQMEventInfo.cc:72
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
~DQMEventInfo() override=default
Destructor.
ModuleDescription const & moduleDescription() const
bool globalTagRetrieved_
Definition: DQMEventInfo.cc:52
bool exists(std::string const &parameterName) const
checks if a parameter exists
MonitorElement * processId_
Number of collector updates (TBD)
Definition: DQMEventInfo.cc:78
MonitorElement * processStartTimeStamp_
The PID associated with this job.
Definition: DQMEventInfo.cc:79
ParameterSet const & getParameterSet(std::string const &) const
int64_t pEvent_
Definition: DQMEventInfo.cc:62
Log< level::Error, false > LogError
MonitorElement * errSummaryEtaPhi_
Subdetector-specific error summary (float)
Definition: DQMEventInfo.cc:91
MonitorElement * bookString(TString const &name, TString const &value, FUNC onbooking=NOOP())
Definition: DQMStore.h:87
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
MonitorElement * cmsswVer_
Current working directory of the job.
Definition: DQMEventInfo.cc:87
void free(void *ptr) noexcept
std::string globalTag_
Definition: DQMEventInfo.cc:51
MonitorElement * eventId_
UTC time of the run start.
Definition: DQMEventInfo.cc:70
std::string eventInfoFolder_
Definition: DQMEventInfo.cc:55
MonitorElement * lumisecId_
Definition: DQMEventInfo.cc:71
MonitorElement * versGlobaltag_
CMSSW version run for this job.
Definition: DQMEventInfo.cc:88
MonitorElement * runStartTimeStamp_
Definition: DQMEventInfo.cc:69
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DQMEventInfo(const edm::ParameterSet &ps)
Constructor.
double lastAvgTime_
Definition: DQMEventInfo.cc:58
MonitorElement * processEvents_
Avg # of events in programmable window (default: 5 min)
Definition: DQMEventInfo.cc:83
MonitorElement * processLatency_
The UTC time of the last event.
Definition: DQMEventInfo.cc:81
MonitorElement * processName_
Hostname of the local machine.
Definition: DQMEventInfo.cc:85
MonitorElement * errSummary_
DQM patch version for this job.
Definition: DQMEventInfo.cc:90
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
ParameterSet const & getProcessParameterSetContainingModule(ModuleDescription const &moduleDescription)
RunID const & id() const
Definition: RunBase.h:39
Log< level::Info, false > LogInfo
std::string getReleaseVersion()
int64_t evtRateCount_
Definition: DQMEventInfo.cc:61
MonitorElement * runId_
Definition: DQMEventInfo.cc:68
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
MonitorElement * nUpdates_
These MEs are either static or updated upon each analyze() call.
Definition: DQMEventInfo.cc:77
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
MonitorElement * processEventRate_
Time elapsed since the last event.
Definition: DQMEventInfo.cc:82
Timestamp const & beginTime() const
Definition: RunBase.h:41
double runStartTime_
Definition: DQMEventInfo.cc:59
MonitorElement * dqmPatch_
GlobalTag name.
Definition: DQMEventInfo.cc:89
MonitorElement * errSummarySegment_[10]
Subdetector-specific etaPhi summary (float)
Definition: DQMEventInfo.cc:92
MonitorElement * processTimeStamp_
The UTC time of the first event processed.
Definition: DQMEventInfo.cc:80
static double stampToReal(edm::Timestamp time)
Definition: DQMEventInfo.cc:95
std::string subsystemname_
Definition: DQMEventInfo.cc:56
RunNumber_t run() const
Definition: RunID.h:26
Definition: event.py:1
Definition: Run.h:45
bool showHLTGlobalTag_
Definition: DQMEventInfo.cc:53
void analyzeProvInfo(const edm::Event &e)