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 (StreamID const &)
 
void evLumi (GlobalContext const &)
 
void keepAlive ()
 
void outputLumiUpdate ()
 
void outputUpdate (ptree &doc)
 
void tryUpdate ()
 
 ~DQMMonitoringService ()
 

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 44 of file DQMMonitoringService.h.

Constructor & Destructor Documentation

◆ DQMMonitoringService()

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

Definition at line 17 of file DQMMonitoringService.cc.

17  {
18  const char* x = std::getenv("DQM2_SOCKET");
19  if (x) {
20  std::cerr << "Monitoring pipe: " << x << std::endl;
21  mstream_.connect(boost::asio::local::stream_protocol::endpoint(x));
22  } else {
23  std::cerr << "Monitoring file not found, disabling." << std::endl;
24  }
25 
26  // init counters
27  nevents_ = 0;
28 
29  last_lumi_ = 0;
32 
33  run_ = 0;
34  lumi_ = 0;
35 
38  }

References beam_dqm_sourceclient-live_cfg::cerr, evEvent(), evLumi(), last_lumi_, last_lumi_nevents_, last_lumi_time_, lumi_, mstream_, nevents_, fileCollector::now, run_, edm::ActivityRegistry::watchPreGlobalBeginLumi(), and edm::ActivityRegistry::watchPreSourceEvent().

◆ ~DQMMonitoringService()

dqmservices::DQMMonitoringService::~DQMMonitoringService ( )

Definition at line 40 of file DQMMonitoringService.cc.

40 {}

Member Function Documentation

◆ connect()

void dqmservices::DQMMonitoringService::connect ( )

◆ evEvent()

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

Definition at line 99 of file DQMMonitoringService.cc.

99  {
100  nevents_ += 1;
101  tryUpdate();
102  }

References nevents_, and tryUpdate().

Referenced by DQMMonitoringService().

◆ evLumi()

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

Definition at line 83 of file DQMMonitoringService.cc.

83  {
84  using std::chrono::duration_cast;
85  using std::chrono::milliseconds;
86 
87  // these might be different than the numbers we want to report
88  // rate/stats per lumi are calculated from last_*_ fields
89  run_ = iContext.luminosityBlockID().run();
90  lumi_ = iContext.luminosityBlockID().luminosityBlock();
91 
93 
96  last_lumi_ = lumi_;
97  }

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

Referenced by DQMMonitoringService().

◆ keepAlive()

void dqmservices::DQMMonitoringService::keepAlive ( )

Definition at line 122 of file DQMMonitoringService.cc.

122  {
123  if (!mstream_)
124  return;
125 
126  mstream_ << "\n";
127  mstream_.flush();
128 
129  tryUpdate();
130  }

References mstream_, and tryUpdate().

◆ outputLumiUpdate()

void dqmservices::DQMMonitoringService::outputLumiUpdate ( )

Definition at line 42 of file DQMMonitoringService.cc.

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

References common_cff::doc, dqmMemoryStats::float, dqm-mbProfile::format, last_lumi_, last_lumi_nevents_, last_lumi_time_, lumi_, nevents_, fileCollector::now, outputUpdate(), RPCpg::rate(), run_, str, and ntuplemaker::time.

Referenced by evLumi(), and tryUpdate().

◆ outputUpdate()

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

Definition at line 104 of file DQMMonitoringService.cc.

104  {
105  using std::chrono::duration_cast;
106  using std::chrono::milliseconds;
107 
108  if (!mstream_)
109  return;
110 
111  try {
113  doc.put("update_timestamp", std::time(nullptr));
114 
115  write_json(mstream_, doc, false);
116  mstream_.flush();
117  } catch (...) {
118  // pass
119  }
120  }

References common_cff::doc, last_update_time_, mstream_, fileCollector::now, and ntuplemaker::time.

Referenced by outputLumiUpdate().

◆ tryUpdate()

void dqmservices::DQMMonitoringService::tryUpdate ( )

Definition at line 132 of file DQMMonitoringService.cc.

132  {
133  using std::chrono::duration_cast;
134  using std::chrono::milliseconds;
135 
136  if (!mstream_)
137  return;
138 
139  // sometimes we don't see any transition for a very long time
140  // but we still want updates
141  // luckily, keepAlive is called rather often by the input source
143  auto millis = duration_cast<milliseconds>(now - last_update_time_).count();
144  if (millis >= (25 * 1000)) {
146  }
147  }

References last_update_time_, mstream_, fileCollector::now, and outputLumiUpdate().

Referenced by evEvent(), and keepAlive().

Member Data Documentation

◆ last_lumi_

unsigned long dqmservices::DQMMonitoringService::last_lumi_
private

Definition at line 68 of file DQMMonitoringService.h.

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

◆ last_lumi_nevents_

long dqmservices::DQMMonitoringService::last_lumi_nevents_
private

Definition at line 72 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 70 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 71 of file DQMMonitoringService.h.

Referenced by outputUpdate(), and tryUpdate().

◆ lumi_

unsigned long dqmservices::DQMMonitoringService::lumi_
private

Definition at line 75 of file DQMMonitoringService.h.

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

◆ mstream_

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

Definition at line 61 of file DQMMonitoringService.h.

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

◆ nevents_

long dqmservices::DQMMonitoringService::nevents_
private

Definition at line 64 of file DQMMonitoringService.h.

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

◆ run_

unsigned long dqmservices::DQMMonitoringService::run_
private

Definition at line 74 of file DQMMonitoringService.h.

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

dqmservices::DQMMonitoringService::outputUpdate
void outputUpdate(ptree &doc)
Definition: DQMMonitoringService.cc:104
common_cff.doc
doc
Definition: common_cff.py:54
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
dqmservices::DQMMonitoringService::last_lumi_
unsigned long last_lumi_
Definition: DQMMonitoringService.h:68
dqmservices::DQMMonitoringService::lumi_
unsigned long lumi_
Definition: DQMMonitoringService.h:75
DDAxes::x
RPCpg::rate
double rate(double x)
Definition: Constants.cc:3
dqmservices::DQMMonitoringService::last_lumi_nevents_
long last_lumi_nevents_
Definition: DQMMonitoringService.h:72
dqmservices::DQMMonitoringService::run_
unsigned long run_
Definition: DQMMonitoringService.h:74
fileCollector.now
now
Definition: fileCollector.py:207
dqmservices::DQMMonitoringService::outputLumiUpdate
void outputLumiUpdate()
Definition: DQMMonitoringService.cc:42
dqm-mbProfile.format
format
Definition: dqm-mbProfile.py:16
str
#define str(s)
Definition: TestProcessor.cc:48
dqmservices::DQMMonitoringService::evEvent
void evEvent(StreamID const &)
Definition: DQMMonitoringService.cc:99
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
dqmservices::DQMMonitoringService::mstream_
boost::asio::local::stream_protocol::iostream mstream_
Definition: DQMMonitoringService.h:61
edm::ActivityRegistry::watchPreGlobalBeginLumi
void watchPreGlobalBeginLumi(PreGlobalBeginLumi::slot_type const &iSlot)
Definition: ActivityRegistry.h:333
dqmservices::DQMMonitoringService::last_lumi_time_
std::chrono::high_resolution_clock::time_point last_lumi_time_
Definition: DQMMonitoringService.h:70
edm::ActivityRegistry::watchPreSourceEvent
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:182
dqmservices::DQMMonitoringService::nevents_
long nevents_
Definition: DQMMonitoringService.h:64
dqmservices::DQMMonitoringService::evLumi
void evLumi(GlobalContext const &)
Definition: DQMMonitoringService.cc:83
ntuplemaker.time
time
Definition: ntuplemaker.py:310
dqmservices::DQMMonitoringService::last_update_time_
std::chrono::high_resolution_clock::time_point last_update_time_
Definition: DQMMonitoringService.h:71
dqmservices::DQMMonitoringService::tryUpdate
void tryUpdate()
Definition: DQMMonitoringService.cc:132