8 #include <daq/hbasf2/modules/HLTDQM2ZMQ.h>
9 #include <framework/pcore/zmq/messages/ZMQMessageFactory.h>
10 #include <framework/pcore/RbTuple.h>
11 #include <framework/core/HistoModule.h>
21 "Module to collect DQM histograms (written out by HistoModules) and "
22 "send them every time period to a running ZMQ DQM server "
23 "(either a finalhistoserver or a proxyhistorver). "
24 "The address as well as the send interval are module parameters. "
25 "As the old DQM module, this module works by streaming everything in the current ROOT main "
26 "directory, which is either a TDirectory or a TH1. For the specific implementation on how "
27 "the streaming is done, please see the HLTStreamHelper class. "
28 "The histogram sending is handled via a confirmed connection (output in this case), "
29 "so all the usual conventions for a confirmed connection apply. "
30 "This module does only makes sense to run on the HLT, it is not useful for local "
33 setPropertyFlags(EModulePropFlags::c_ParallelProcessingCertified);
35 addParam(
"output", m_param_output,
"ZMQ address to send the histograms to (the local histo server)");
36 addParam(
"sendOutInterval", m_param_sendOutInterval,
"Time interval in seconds to send out the histograms. "
37 "Please note that the full stack of DQM histo servers"
38 "could delay this, as each of them have a timeout.",
39 m_param_sendOutInterval);
42 void HLTDQM2ZMQModule::event()
46 m_streamHelper.initialize();
49 m_start = std::chrono::system_clock::now();
54 auto currentTime = std::chrono::system_clock::now();
55 auto timeDifference = std::chrono::duration_cast<std::chrono::seconds>(currentTime - m_start).count();
56 if (timeDifference > m_param_sendOutInterval) {
58 m_start = std::chrono::system_clock::now();
60 }
catch (zmq::error_t& error) {
61 if (error.num() == EINTR) {
63 B2DEBUG(10,
"Received an signal interrupt during the event call. Will return");
67 B2ERROR(
"ZMQ Error while calling the event: " << error.num());
71 void HLTDQM2ZMQModule::beginRun()
73 if (m_histogramsDefined) {
76 const auto& modules = RbTupleManager::Instance().getHistDefiningModules();
77 for (
const auto& module : modules) {
78 B2INFO(module->getName() <<
" is a histo module");
79 auto* histoModule =
dynamic_cast<HistoModule*
>(module);
80 B2ASSERT(
"The added module is not a histogram module!", histoModule);
81 histoModule->defineHisto();
84 m_histogramsDefined =
true;
87 void HLTDQM2ZMQModule::endRun()
94 B2DEBUG(10,
"Sending out old run message");
96 auto message = ZMQMessageFactory::createMessage(EMessageTypes::c_lastEventMessage);
97 m_output->handleEvent(std::move(message),
false, 1000);
98 }
catch (zmq::error_t& error) {
99 if (error.num() == EINTR) {
101 B2DEBUG(10,
"Received an signal interrupt during the event call. Will return");
105 B2ERROR(
"ZMQ Error while calling the event: " << error.num());
111 void HLTDQM2ZMQModule::terminate()
118 B2DEBUG(10,
"Sending out terminate message");
119 auto message = ZMQMessageFactory::createMessage(EMessageTypes::c_terminateMessage);
120 m_output->handleEvent(std::move(message));
121 }
catch (zmq::error_t& error) {
122 if (error.num() == EINTR) {
124 B2DEBUG(10,
"Received an signal interrupt during the event call. Will return");
128 B2ERROR(
"ZMQ Error while calling the event: " << error.num());
132 void HLTDQM2ZMQModule::sendOutHistograms()
138 auto msg = m_streamHelper.streamHistograms();
139 m_output->handleEvent(std::move(msg),
false, 1000);
Module to collect DQM histograms (written out by HistoModules) and send them every time period to a r...
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Output part of a confirmed connection.
A helper class for creating ZMQ sockets keeping track of the ZMQ context and terminating it if needed...
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.