8#include <daq/dqm/DqmMasterCallback.h>
9#include <daq/slc/system/LogFile.h>
10#include <framework/pcore/EvtMessage.h>
11#include <framework/pcore/MsgHandler.h>
22int DqmMasterCallback::m_running = 0;
27void* RunDqmMasterLogger(
void*)
32DqmMasterCallback::DqmMasterCallback(
ConfigFile& config) : m_histodir(config.get(
"dqmmaster.histodir")),
33 m_tmpdir(config.get(
"dqmmaster.tmpdir")), m_instance(config.get(
"dqmmaster.instance"))
35 auto host = config.get(
"dqmmaster.host");
36 auto port = config.getInt(
"dqmmaster.port");
38 LogFile::info(
"DqmMasterCallback : instance = %s, histodir = %s, tmpdir = %s", m_instance.c_str(), m_histodir.c_str(),
45DqmMasterCallback::~DqmMasterCallback()
50void DqmMasterCallback::load(
const DBObject& ,
const std::string& runtype)
53 LogFile::info(
"LOAD: runtype %s", m_runtype.c_str());
56 std::string filename = m_tmpdir +
"/dqm_" + m_instance +
"_runtype";
58 auto fh = fopen(filename.c_str(),
"wt+");
60 fprintf(fh,
"%s", m_runtype.c_str());
66void DqmMasterCallback::start(
int expno,
int runno)
73 std::string filename = m_tmpdir +
"/dqm_" + m_instance +
"_expnr";
75 auto fh = fopen(filename.c_str(),
"wt+");
77 fprintf(fh,
"%d", m_expno);
82 std::string filename = m_tmpdir +
"/dqm_" + m_instance +
"_runnr";
84 auto fh = fopen(filename.c_str(),
"wt+");
86 fprintf(fh,
"%d", m_runno);
94 TText rc_clear(0, 0,
"DQMRC:CLEAR");
95 hdl.add(&rc_clear,
"DQMRC:CLEAR");
97 TText subdir(0, 0,
"DQMInfo");
98 hdl.add(&subdir,
"SUBDIR:DQMInfo") ;
100 TH1F h_expno(
"expno", to_string(m_expno).c_str(), 1, 0, 1);
101 hdl.add(&h_expno,
"expno");
103 TH1F h_runno(
"runno", to_string(m_runno).c_str(), 1, 0, 1);
104 hdl.add(&h_runno,
"runno");
106 TH1F h_rtype(
"rtype", m_runtype.c_str(), 1, 0, 1);
107 hdl.add(&h_rtype,
"rtype");
109 TText command(0, 0,
"COMMAND:EXIT");
110 hdl.add(&command,
"SUBDIR:EXIT");
112 TText rc_merge(0, 0,
"DQMRC:MERGE");
113 hdl.add(&rc_merge,
"DQMRC:MERGE");
116 EvtMessage* msg = hdl.encode_msg(MSG_EVENT);
117 (msg->
header())->reserved[0] = 0;
118 (msg->
header())->reserved[1] = numobjs;
120 while (m_sock->send(msg) < 0) {
121 LogFile::error(
"Connection to histogramm server is missing in START: expno = %d, runno = %d, runtype %s", m_expno, m_runno,
123 m_sock->sock()->reconnect(10);
127 LogFile::info(
"START: expno = %d, runno = %d, runtype %s", m_expno, m_runno, m_runtype.c_str());
131void DqmMasterCallback::stop(
void)
133 LogFile::info(
"STOP: expno = %d, runno = %d, runtype %s", m_expno, m_runno, m_runtype.c_str());
135 if (m_running == 0)
return;
144 snprintf(outfile,
sizeof(outfile),
"DQMRC:SAVE:%s/%s_dqm_histo_e%4.4dr%6.6d.root", m_histodir.c_str(), m_instance.c_str(), m_expno,
147 TText rc_save(0, 0, outfile);
148 hdl.add(&rc_save, outfile);
151 EvtMessage* msg = hdl.encode_msg(MSG_EVENT);
152 (msg->
header())->reserved[0] = 0;
153 (msg->
header())->reserved[1] = numobjs;
155 while (m_sock->send(msg) < 0) {
156 LogFile::error(
"Connection closed during STOP, file not saved: expno = %d, runno = %d, runtype %s", m_expno, m_runno,
158 m_sock->sock()->reconnect(10);
167void DqmMasterCallback::abort(
void)
EvtHeader * header()
Get pointer to EvtHeader.
Abstract base class for different kinds of events.