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  if (count < 30) {
55  // we don't want to report too often
56  return;
57  }
58 
59  ptree doc;
60  doc.put("events_total", nevents_);
61 
62  if (count > 0) {
64  doc.put("events_rate", rate);
65  }
66 
69 
70  outputUpdate(doc);
71 }
72 
74  if (!mstream_)
75  return;
76 
77  try {
78  doc.put("update_timestamp", std::time(NULL));
79 
80  write_json(*mstream_, doc, false);
81  mstream_->flush();
82  } catch (...) {
83  // pass
84  }
85 }
86 
88  if (!mstream_)
89  return;
90 
91  *mstream_ << "\n";
92  mstream_->flush();
93 }
94 
95 
96 } // end-of-namespace
97 
99 
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_