8#include <daq/dqm/HistoServer2.h>
10#include <framework/pcore/MsgHandler.h>
18HistoServer2::HistoServer2(
int port,
const string& filename)
22 m_filename = filename;
25HistoServer2::~HistoServer2()
32int HistoServer2::init()
42int HistoServer2::server()
48 char* buffer =
new char[c_maxBufSize];
53 while (m_force_exit == 0) {
55 int exam_stat = m_man->examine();
57 }
else if (exam_stat == 1) {
59 vector<int>& recvsock = m_man->connected_socket_list();
60 for (vector<int>::iterator it = recvsock.begin();
61 it != recvsock.end(); ++it) {
63 if (m_man->connected(fd)) {
64 struct sockaddr_in isa;
65 socklen_t isize =
sizeof(isa);
66 getpeername(fd, (
struct sockaddr*)&isa, &isize);
67 char address[INET_ADDRSTRLEN];
68 strcpy(address, inet_ntoa(isa.sin_addr));
69 char* ptr = strrchr(address,
'.');
74 m_unit_last_conn_time[address] = now;
76 int is = sio.get(fd, buffer, c_maxBufSize);
79 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
80 printf(
"[%s] HistoServer2: fd %d / %s disconnected\n", mbstr, fd, address);
89 vector<TObject*> objlist;
90 vector<string> strlist;
91 msghdl.decode_msg(hmsg, objlist, strlist);
92 int nobjs = (hmsg->
header())->reserved[1];
96 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
97 m_unit_last_packet_time[address] = now;
98 printf(
"[%s] HistoServer2 : received nobjs = %d from %s\n", mbstr, nobjs, address);
99 if (nobjs > 0) m_unit_last_content_time[address] = now;
100 for (
int i = 0; i < nobjs; i++) {
103 string objname = strlist.at(i);
104 if (objname ==
string(
"DQMRC:CLEAR")) {
108 m_last_merge_time = time(0);
109 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&m_last_merge_time));
110 printf(
"[%s] HistoServer2: CLEAR\n", mbstr);
113 if (objname ==
string(
"DQMRC:MERGE")) {
116 m_last_merge_time = time(0);
117 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&m_last_merge_time));
118 printf(
"[%s] HistoServer2: MERGE\n", mbstr);
121 auto lpos = objname.find(
"DQMRC:SAVE:");
122 if (lpos != string::npos) {
123 auto filename = objname.substr(11);
124 m_hman->filedump(filename);
127 lpos = objname.find(
"SUBDIR:");
128 if (lpos != string::npos) {
129 subdir = objname.substr(7);
130 if (subdir ==
"EXIT") subdir =
"";
134 m_hman->update(subdir, strlist.at(i), fd, (TH1*)objlist.at(i));
143 if (loop_counter % c_mergeIntervall == 0) {
145 m_last_merge_time = time(0);
146 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&m_last_merge_time));
147 printf(
"[%s] HistoServer2: merging histograms\n", mbstr);
162 std::string name =
"/tmp/dqm_hserver_state_" + m_filename;
163 FILE* fh = fopen(name.c_str(),
"wt+");
165 time_t now = time(0);
166 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
167 strftime(mbstr2,
sizeof(mbstr2),
"%F %T", localtime(&m_last_merge_time));
168 fprintf(fh,
"%s,%s,%s\n", m_filename.c_str(), mbstr, mbstr2);
171 int nr = it.second.first;
172 int con = it.second.second;
173 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&m_unit_last_conn_time[it.first]));
174 strftime(mbstr2,
sizeof(mbstr2),
"%F %T", localtime(&m_unit_last_packet_time[it.first]));
175 strftime(mbstr3,
sizeof(mbstr3),
"%F %T", localtime(&m_unit_last_content_time[it.first]));
176 if (it.first ==
"127.0.0.1") {
177 fprintf(fh,
"RUNCONTROL,");
179 if (nr >= 0 and nr < 20) {
180 fprintf(fh,
"HLT%d,", nr);
181 }
else if (nr > 100 and nr < 110) {
182 fprintf(fh,
"ERECO%d,", nr - 100);
184 fprintf(fh,
"UNKNOWN,");
187 fprintf(fh,
"%s,%d,%s,%s,%s\n", it.first.c_str(), con, mbstr, mbstr2, mbstr3);
Class to manage streamed object.
EvtHeader * header()
Get pointer to EvtHeader.
std::map< std::string, std::pair< int, bool > > m_units_connected
connection IP, state and last update time
void write_state(void)
Write connection state to a file.
A class to encode/decode an EvtMessage.
Abstract base class for different kinds of events.