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 */
15 
16 #include <algorithm>
17 #include <iostream>
18 #include <sstream>
19 #include <fstream>
20 #include <string>
21 #include <vector>
22 #include <memory>
23 #include <cstdio>
24 #include <cmath>
25 #include <map>
26 
27 #include <sys/time.h>
28 #include <TSystem.h>
29 
30 #include <boost/algorithm/string/join.hpp>
31 
32 class DQMEventInfo : public DQMOneEDAnalyzer<> {
33 public:
36 
38  ~DQMEventInfo() override = default;
39 
40 protected:
42  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
43  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
44 
45 private:
48 
50  double runStartTime_;
52  int64_t evtRateCount_;
53  int64_t pEvent_;
54 
64 
83 };
84 
85 static inline double stampToReal(edm::Timestamp time) {
86  return (time.value() >> 32) + 1e-6 * (time.value() & 0xffffffff);
87 }
88 
89 static inline double stampToReal(const timeval& time) { return time.tv_sec + 1e-6 * time.tv_usec; }
90 
92  struct timeval now;
93  gettimeofday(&now, nullptr);
94 
95  pEvent_ = 0;
96  evtRateCount_ = 0;
98 
99  // read config parms
100  std::string folder = ps.getUntrackedParameter<std::string>("eventInfoFolder", "EventInfo");
101  subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");
102 
104  evtRateWindow_ = ps.getUntrackedParameter<double>("eventRateWindow", 0.5);
105  if (evtRateWindow_ <= 0.15)
106  evtRateWindow_ = 0.15;
107 }
108 
110  edm::Run const& iRun,
111  edm::EventSetup const& /* iSetup */) {
113 
114  //Event specific contents
115  runId_ = ibooker.bookInt("iRun");
116  runId_->Fill(iRun.id().run());
117  lumisecId_ = ibooker.bookInt("iLumiSection");
118  lumisecId_->Fill(-1);
119  eventId_ = ibooker.bookInt("iEvent");
120  eventId_->Fill(-1);
121  eventTimeStamp_ = ibooker.bookFloat("eventTimeStamp");
122 
124  //Process specific contents
125  processTimeStamp_ = ibooker.bookFloat("processTimeStamp");
127  processLatency_ = ibooker.bookFloat("processLatency");
128  processTimeStamp_->Fill(-1);
129  processEvents_ = ibooker.bookInt("processedEvents");
131  processEventRate_ = ibooker.bookFloat("processEventRate");
132  processEventRate_->Fill(-1);
133  nUpdates_ = ibooker.bookInt("processUpdates");
134  nUpdates_->Fill(-1);
135 
136  //Static Contents
137  processId_ = ibooker.bookInt("processID");
138  processId_->Fill(getpid());
139  processStartTimeStamp_ = ibooker.bookFloat("processStartTimeStamp");
141  runStartTimeStamp_ = ibooker.bookFloat("runStartTimeStamp");
143  char hostname[65];
144  gethostname(hostname, 64);
145  hostname[64] = 0;
146  hostName_ = ibooker.bookString("hostName", hostname);
147  processName_ = ibooker.bookString("processName", subsystemname_);
148  char* pwd = getcwd(nullptr, 0);
149  workingDir_ = ibooker.bookString("workingDir", pwd);
150  free(pwd);
151  cmsswVer_ = ibooker.bookString("CMSSW_Version", edm::getReleaseVersion());
152 
153  // Folder to be populated by sub-systems' code
154  std::string subfolder = eventInfoFolder_ + "/reportSummaryContents";
155  ibooker.setCurrentFolder(subfolder);
156 
157  //Online static histograms
158  const edm::ParameterSet& sourcePSet =
160 
161  if (sourcePSet.getParameter<std::string>("@module_type") == "DQMStreamerReader") {
162  std::string evSelection;
163  std::vector<std::string> evSelectionList;
164  std::string delimiter(", ");
165  evSelectionList = sourcePSet.getUntrackedParameter<std::vector<std::string> >("SelectEvents");
166  // add single quotes inline in the vector of HLT paths:
167  // we do copy assignment, and getUntrackedParameter returns
168  // a by-value copy of the vector of strings
169  std::for_each(evSelectionList.begin(), evSelectionList.end(), [](std::string& s) {
170  std::string squote("'");
171  s = squote + s + squote;
172  });
173  evSelection = boost::algorithm::join(evSelectionList, delimiter);
174  // if no HLT paths are specified, no selections are performed:
175  // we mark this with an asterisk.
176  if (evSelection.empty()) {
177  evSelection = std::string("'*'");
178  }
180  ibooker.bookString("eventSelection", evSelection);
181  }
182 }
183 
185  //Filling lumi here guarantees that the lumi number corresponds to the event when
186  // using multiple concurrent lumis in a job
187  lumisecId_->Fill(e.id().luminosityBlock());
188  eventId_->Fill(e.id().event()); // Handing edm::EventNumber_t to Fill method which will handle further casting
189  eventTimeStamp_->Fill(stampToReal(e.time()));
190 
191  pEvent_++;
192  evtRateCount_++;
194 
195  struct timeval now;
196  gettimeofday(&now, nullptr);
199 
202 
203  double delta = currentTime_ - lastAvgTime_;
204  if (delta >= (evtRateWindow_ * 60.0)) {
206  evtRateCount_ = 0;
208  }
209 
210  return;
211 }
212 
double evtRateWindow_
Definition: DQMEventInfo.cc:51
double currentTime_
Definition: DQMEventInfo.cc:49
MonitorElement * hostName_
of event processed so far
Definition: DQMEventInfo.cc:75
MonitorElement * workingDir_
DQM "name" of the job (eg, Hcal or DT)
Definition: DQMEventInfo.cc:77
double lastUpdateTime_
Definition: DQMEventInfo.cc:49
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:63
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
MonitorElement * processId_
Number of collector updates (TBD)
Definition: DQMEventInfo.cc:69
MonitorElement * processStartTimeStamp_
The PID associated with this job.
Definition: DQMEventInfo.cc:70
ParameterSet const & getParameterSet(std::string const &) const
int64_t pEvent_
Definition: DQMEventInfo.cc:53
MonitorElement * errSummaryEtaPhi_
Subdetector-specific error summary (float)
Definition: DQMEventInfo.cc:81
MonitorElement * bookString(TString const &name, TString const &value, FUNC onbooking=NOOP())
Definition: DQMStore.h:87
T getUntrackedParameter(std::string const &, T const &) const
void Fill(long long x)
MonitorElement * cmsswVer_
Current working directory of the job.
Definition: DQMEventInfo.cc:78
void free(void *ptr) noexcept
MonitorElement * eventId_
UTC time of the run start.
Definition: DQMEventInfo.cc:61
std::string eventInfoFolder_
Definition: DQMEventInfo.cc:46
MonitorElement * lumisecId_
Definition: DQMEventInfo.cc:62
MonitorElement * runStartTimeStamp_
Definition: DQMEventInfo.cc:60
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DQMEventInfo(const edm::ParameterSet &ps)
Constructor.
Definition: DQMEventInfo.cc:91
double lastAvgTime_
Definition: DQMEventInfo.cc:49
MonitorElement * processEvents_
Avg # of events in programmable window (default: 5 min)
Definition: DQMEventInfo.cc:74
MonitorElement * processLatency_
The UTC time of the last event.
Definition: DQMEventInfo.cc:72
MonitorElement * processName_
Hostname of the local machine.
Definition: DQMEventInfo.cc:76
MonitorElement * errSummary_
DQM patch version for this job.
Definition: DQMEventInfo.cc:80
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
std::string getReleaseVersion()
int64_t evtRateCount_
Definition: DQMEventInfo.cc:52
MonitorElement * runId_
Definition: DQMEventInfo.cc:59
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:68
MonitorElement * bookInt(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:73
MonitorElement * processEventRate_
Time elapsed since the last event.
Definition: DQMEventInfo.cc:73
Timestamp const & beginTime() const
Definition: RunBase.h:41
double runStartTime_
Definition: DQMEventInfo.cc:50
MonitorElement * dqmPatch_
CMSSW version run for this job.
Definition: DQMEventInfo.cc:79
MonitorElement * errSummarySegment_[10]
Subdetector-specific etaPhi summary (float)
Definition: DQMEventInfo.cc:82
MonitorElement * processTimeStamp_
The UTC time of the first event processed.
Definition: DQMEventInfo.cc:71
static double stampToReal(edm::Timestamp time)
Definition: DQMEventInfo.cc:85
std::string subsystemname_
Definition: DQMEventInfo.cc:47
RunNumber_t run() const
Definition: RunID.h:26
Definition: Run.h:45