CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
dqmservices::DQMMonitoringService Class Reference

#include <DQMMonitoringService.h>

Public Member Functions

void connect ()
 
 DQMMonitoringService (const edm::ParameterSet &, edm::ActivityRegistry &)
 
void evEvent (edm::StreamID const &)
 
void evLumi (edm::GlobalContext const &)
 
void keepAlive ()
 
void outputLumiUpdate ()
 
void outputUpdate (boost::property_tree::ptree &doc)
 
void tryUpdate ()
 
 ~DQMMonitoringService ()=default
 

Private Attributes

unsigned long last_lumi_
 
long last_lumi_nevents_
 
std::chrono::high_resolution_clock::time_point last_lumi_time_
 
std::chrono::high_resolution_clock::time_point last_update_time_
 
unsigned long lumi_
 
boost::asio::local::stream_protocol::iostream mstream_
 
long nevents_
 
unsigned long run_
 

Detailed Description

Definition at line 23 of file DQMMonitoringService.h.

Constructor & Destructor Documentation

◆ DQMMonitoringService()

dqmservices::DQMMonitoringService::DQMMonitoringService ( const edm::ParameterSet pset,
edm::ActivityRegistry ar 
)

Definition at line 26 of file DQMMonitoringService.cc.

References DMR_cfg::cerr, evEvent(), evLumi(), last_lumi_, last_lumi_nevents_, last_lumi_time_, lumi_, mstream_, nevents_, submitPVValidationJobs::now, run_, edm::ActivityRegistry::watchPreGlobalBeginLumi(), edm::ActivityRegistry::watchPreSourceEvent(), and x.

26  {
27  const char* x = std::getenv("DQM2_SOCKET");
28  if (x) {
29  std::cerr << "Monitoring pipe: " << x << std::endl;
30  mstream_.connect(boost::asio::local::stream_protocol::endpoint(x));
31  } else {
32  std::cerr << "Monitoring file not found, disabling." << std::endl;
33  }
34 
35  // init counters
36  nevents_ = 0;
37 
38  last_lumi_ = 0;
41 
42  run_ = 0;
43  lumi_ = 0;
44 
47  }
void evEvent(edm::StreamID const &)
void evLumi(edm::GlobalContext const &)
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
boost::asio::local::stream_protocol::iostream mstream_
std::chrono::high_resolution_clock::time_point last_lumi_time_
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)

◆ ~DQMMonitoringService()

dqmservices::DQMMonitoringService::~DQMMonitoringService ( )
default

Member Function Documentation

◆ connect()

void dqmservices::DQMMonitoringService::connect ( )

◆ evEvent()

void dqmservices::DQMMonitoringService::evEvent ( edm::StreamID const &  iContext)

Definition at line 100 of file DQMMonitoringService.cc.

References nevents_, and tryUpdate().

Referenced by DQMMonitoringService().

◆ evLumi()

void dqmservices::DQMMonitoringService::evLumi ( edm::GlobalContext const &  iContext)

Definition at line 87 of file DQMMonitoringService.cc.

References last_lumi_, last_lumi_nevents_, last_lumi_time_, lumi_, edm::LuminosityBlockID::luminosityBlock(), edm::GlobalContext::luminosityBlockID(), nevents_, submitPVValidationJobs::now, outputLumiUpdate(), edm::LuminosityBlockID::run(), and run_.

Referenced by DQMMonitoringService().

87  {
88  // these might be different than the numbers we want to report
89  // rate/stats per lumi are calculated from last_*_ fields
90  run_ = iContext.luminosityBlockID().run();
91  lumi_ = iContext.luminosityBlockID().luminosityBlock();
92 
94 
97  last_lumi_ = lumi_;
98  }
std::chrono::high_resolution_clock::time_point last_lumi_time_

◆ keepAlive()

void dqmservices::DQMMonitoringService::keepAlive ( )

Definition at line 120 of file DQMMonitoringService.cc.

References mstream_, and tryUpdate().

120  {
121  if (!mstream_)
122  return;
123 
124  mstream_ << "\n";
125  mstream_.flush();
126 
127  tryUpdate();
128  }
boost::asio::local::stream_protocol::iostream mstream_

◆ outputLumiUpdate()

void dqmservices::DQMMonitoringService::outputLumiUpdate ( )

Definition at line 49 of file DQMMonitoringService.cc.

References submitPVResolutionJobs::count, hcalRecHitTable_cff::doc, nano_mu_digi_cff::float, last_lumi_, last_lumi_nevents_, last_lumi_time_, lumi_, nevents_, submitPVValidationJobs::now, outputUpdate(), RPCpg::rate(), run_, and hcalRecHitTable_cff::time.

Referenced by evLumi(), and tryUpdate().

49  {
51 
52  boost::property_tree::ptree doc;
53 
54  // these might be different than the numbers we want to report
55  // rate/stats per lumi are calculated from last_*_ fields
56  doc.put("cmssw_run", run_);
57  doc.put("cmssw_lumi", lumi_);
58  doc.put("events_total", nevents_);
59 
60  // do statistics for the last (elapsed) ls
61  auto lumi_millis = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_lumi_time_).count();
62  auto lumi_events = nevents_ - last_lumi_nevents_;
63  auto lumi_last = last_lumi_;
64 
65  if ((lumi_last > 0) && (lumi_millis > 0)) {
66  doc.put("lumi_number", lumi_last);
67  doc.put("lumi_events", lumi_events);
68  doc.put("lumi_duration_ms", lumi_millis);
69 
70  float rate = ((float)lumi_events * 1000) / lumi_millis;
71  doc.put("events_rate", rate);
72 
73  // also save the history entry
74  boost::property_tree::ptree plumi;
75  plumi.put("n", lumi_last);
76  plumi.put("nevents", lumi_events);
77  plumi.put("nmillis", lumi_millis);
78  plumi.put("rate", rate);
79 
80  std::time_t hkey = std::time(nullptr);
81  doc.add_child(fmt::sprintf("extra.lumi_stats.%d", hkey), plumi);
82  }
83 
85  }
std::chrono::high_resolution_clock::time_point last_lumi_time_
double rate(double x)
Definition: Constants.cc:3
void outputUpdate(boost::property_tree::ptree &doc)

◆ outputUpdate()

void dqmservices::DQMMonitoringService::outputUpdate ( boost::property_tree::ptree &  doc)

Definition at line 105 of file DQMMonitoringService.cc.

References hcalRecHitTable_cff::doc, cppFunctionSkipper::exception, last_update_time_, LogDebug, mstream_, submitPVValidationJobs::now, and hcalRecHitTable_cff::time.

Referenced by outputLumiUpdate().

105  {
106  if (!mstream_)
107  return;
108 
109  try {
111  doc.put("update_timestamp", std::time(nullptr));
112 
113  write_json(mstream_, doc, false);
114  mstream_.flush();
115  } catch (std::exception const& exc) {
116  LogDebug("DQMMonitoringService") << "Exception thrown in outputUpdate method: " << exc.what();
117  }
118  }
boost::asio::local::stream_protocol::iostream mstream_
std::chrono::high_resolution_clock::time_point last_update_time_
#define LogDebug(id)

◆ tryUpdate()

void dqmservices::DQMMonitoringService::tryUpdate ( )

Definition at line 130 of file DQMMonitoringService.cc.

References submitPVResolutionJobs::count, last_update_time_, mstream_, submitPVValidationJobs::now, and outputLumiUpdate().

Referenced by evEvent(), and keepAlive().

130  {
131  if (!mstream_)
132  return;
133 
134  // sometimes we don't see any transition for a very long time
135  // but we still want updates
136  // luckily, keepAlive is called rather often by the input source
138  auto const millis = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update_time_).count();
139  if (millis >= (25 * 1000)) {
141  }
142  }
boost::asio::local::stream_protocol::iostream mstream_
std::chrono::high_resolution_clock::time_point last_update_time_

Member Data Documentation

◆ last_lumi_

unsigned long dqmservices::DQMMonitoringService::last_lumi_
private

Definition at line 50 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), evLumi(), and outputLumiUpdate().

◆ last_lumi_nevents_

long dqmservices::DQMMonitoringService::last_lumi_nevents_
private

Definition at line 48 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), evLumi(), and outputLumiUpdate().

◆ last_lumi_time_

std::chrono::high_resolution_clock::time_point dqmservices::DQMMonitoringService::last_lumi_time_
private

Definition at line 46 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), evLumi(), and outputLumiUpdate().

◆ last_update_time_

std::chrono::high_resolution_clock::time_point dqmservices::DQMMonitoringService::last_update_time_
private

Definition at line 47 of file DQMMonitoringService.h.

Referenced by outputUpdate(), and tryUpdate().

◆ lumi_

unsigned long dqmservices::DQMMonitoringService::lumi_
private

Definition at line 53 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), evLumi(), and outputLumiUpdate().

◆ mstream_

boost::asio::local::stream_protocol::iostream dqmservices::DQMMonitoringService::mstream_
private

Definition at line 40 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), keepAlive(), outputUpdate(), and tryUpdate().

◆ nevents_

long dqmservices::DQMMonitoringService::nevents_
private

Definition at line 43 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), evEvent(), evLumi(), and outputLumiUpdate().

◆ run_

unsigned long dqmservices::DQMMonitoringService::run_
private

Definition at line 52 of file DQMMonitoringService.h.

Referenced by DQMMonitoringService(), evLumi(), and outputLumiUpdate().