CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMMonitoringService.cc
Go to the documentation of this file.
1 #include "DQMMonitoringService.h"
2 
3 #include <boost/algorithm/string.hpp>
4 
5 #include <ctime>
6 
7 /*
8  * This service is very similar to the FastMonitoringService in the HLT,
9  * except that it is used for monitoring online DQM applications
10  */
11 
12 namespace dqmservices {
13 
15  const char* x = getenv("DQMMON_UPDATE_PIPE");
16 
17  if (x) {
18  std::cerr << "Monitoring pipe: " << x << std::endl;
19  mstream_.reset(new std::ofstream(x));
20  } else {
21  std::cerr << "Monitoring file not found, disabling." << std::endl;
22  }
23 
24  nevents_ = 0;
27 
30 }
31 
33 }
34 
36  unsigned int run = iContext.luminosityBlockID().run();
37  unsigned int lumi = iContext.luminosityBlockID().luminosityBlock();
38 
39  ptree doc;
40  doc.put("cmssw_run", run);
41  doc.put("cmssw_lumi", lumi);
42  outputUpdate(doc);
43 }
44 
45 void DQMMonitoringService::evEvent(StreamID const& iContext) {
46  nevents_ += 1;
47 
48  using std::chrono::duration_cast;
50 
52  auto count = duration_cast<seconds>(now - last_report_time_).count();
53 
54  ptree doc;
55  doc.put("events_total", nevents_);
56 
57  if (count > 0) {
59  doc.put("events_rate", rate);
60  }
61 
64 
65  outputUpdate(doc);
66 }
67 
69  if (!mstream_)
70  return;
71 
72  try {
73  doc.put("update_timestamp", std::time(NULL));
74 
75  write_json(*mstream_, doc, false);
76  mstream_->flush();
77  } catch (...) {
78  // pass
79  }
80 }
81 
83  if (!mstream_)
84  return;
85 
86  *mstream_ << "\n";
87  mstream_->flush();
88 }
89 
90 
91 } // end-of-namespace
92 
94 
double seconds()
tuple lumi
Definition: fjr2json.py:35
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:52
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
#define NULL
Definition: scimark2.h:8
RunNumber_t run() const
tuple doc
Definition: asciidump.py:381
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:113
std::chrono::high_resolution_clock::time_point last_report_time_
LuminosityBlockNumber_t luminosityBlock() const
double rate(double x)
Definition: Constants.cc:3
DQMMonitoringService(const edm::ParameterSet &, edm::ActivityRegistry &)
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
Definition: DDAxes.h:10
void evLumi(GlobalContext const &)
std::shared_ptr< std::ostream > mstream_