CMS 3D CMS Logo

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