9#include "daq/rfarm/manager/RFEventProcessor.h"
19#define RFOTSOUT stdout
26RFEventProcessor::RFEventProcessor(
const string& conffile)
29 m_conf =
new RFConf(conffile.c_str());
32 strcpy(m_nodename,
"evp_");
34 gethostname(&m_nodename[4],
sizeof(m_nodename) - 4);
37 char hostnamebuf[256];
38 gethostname(hostnamebuf,
sizeof(hostnamebuf));
39 strcat(&m_nodename[4], &hostnamebuf[6]);
40 int lend = strlen(m_nodename);
41 m_nodename[lend + 1] = (char)0;
42 m_nodename[lend] = m_nodename[lend - 1];
43 strncpy(&m_nodename[lend - 1],
"0", 1);
46 printf(
"nodename = %s\n", m_nodename);
49 string execdir = string(m_conf->getconf(
"system",
"execdir_base")) +
"/" + string(m_nodename);
50 printf(
"execdir = %s\n", execdir.c_str());
52 mkdir(execdir.c_str(), 0755);
53 chdir(execdir.c_str());
56 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
58 m_shm =
new RFSharedMem(
const_cast<char*
>(shmname.c_str()));
61 m_proc =
new RFProcessManager(m_nodename);
65 string rbufin = string(m_conf->getconf(
"system",
"unitname")) +
":" +
66 string(m_conf->getconf(
"processor",
"ringbufin"));
67 int rbinsize = m_conf->getconfi(
"processor",
"ringbufinsize");
69 m_rbufin =
new RingBuffer(rbufin.c_str(), rbinsize);
71 string rbufout = string(m_conf->getconf(
"system",
"unitname")) +
":" +
72 string(m_conf->getconf(
"processor",
"ringbufout"));
73 int rboutsize = m_conf->getconfi(
"processor",
"ringbufoutsize");
75 m_rbufout =
new RingBuffer(rbufout.c_str(), rboutsize);
78 m_log =
new RFLogManager(m_nodename, m_conf->getconf(
"system",
"lognode"));
81 m_flow =
new RFFlowStat(
const_cast<char*
>(shmname.c_str()));
92RFEventProcessor::~RFEventProcessor()
106int RFEventProcessor::Configure(NSMmsg* , NSMcontext* )
112 string rbufin = string(m_conf->getconf(
"system",
"unitname")) +
":" +
113 string(m_conf->getconf(
"processor",
"ringbufin"));
115 string rbufout = string(m_conf->getconf(
"system",
"unitname")) +
":" +
116 string(m_conf->getconf(
"processor",
"ringbufout"));
118 string shmname = string(m_conf->getconf(
"system",
"unitname")) +
":" +
122 char* hrecv = m_conf->getconf(
"processor",
"historecv",
"script");
123 char* hport = m_conf->getconf(
"processor",
"historecv",
"port");
124 char* mapfile = m_conf->getconf(
"processor",
"historecv",
"mapfile");
125 m_pid_hrecv = m_proc->Execute(hrecv, hport, mapfile);
130 char* hrelay = m_conf->getconf(
"processor",
"historelay",
"script");
131 char* dqmdest = m_conf->getconf(
"dqmserver",
"host");
132 char* dqmport = m_conf->getconf(
"dqmserver",
"port");
133 char* interval = m_conf->getconf(
"processor",
"historelay",
"interval");
134 m_pid_hrelay = m_proc->Execute(hrelay, mapfile, dqmdest, dqmport, interval);
137 char* sender = m_conf->getconf(
"processor",
"sender",
"script");
138 char* port = m_conf->getconf(
"processor",
"sender",
"port");
139 m_pid_sender = m_proc->Execute(sender,
const_cast<char*
>(rbufout.c_str()), port,
const_cast<char*
>(shmname.c_str()),
140 const_cast<char*
>(
"1"));
154 char* receiver = m_conf->getconf(
"processor",
"receiver",
"script");
155 char* srchost = m_conf->getconf(
"distributor",
"host");
157 int portbase = m_conf->getconfi(
"distributor",
"sender",
"portbase");
168 sscanf(&m_nodename[strlen(m_nodename) - 2],
"%d", &rport);
171 sprintf(portchar,
"%d", rport);
172 m_pid_receiver = m_proc->Execute(receiver,
const_cast<char*
>(rbufin.c_str()), srchost, portchar,
const_cast<char*
>(shmname.c_str()),
173 const_cast<char*
>(
"0"));
176 printf(
"Configure : done\n");
180 m_rbufin->forceClear();
181 m_rbufout->forceClear();
187int RFEventProcessor::UnConfigure(NSMmsg*, NSMcontext*)
193 system(
"killall -9 python");
197 if (m_pid_sender != 0) {
198 printf(
"RFEventProcessor : killing sender pid=%d\n", m_pid_sender);
199 kill(m_pid_sender, SIGINT);
200 waitpid(m_pid_sender, &status, 0);
202 if (m_pid_basf2 != 0) {
203 printf(
"RFEventProcessor : killing basf2 pid=%d\n", m_pid_basf2);
205 kill(m_pid_basf2, SIGINT);
206 waitpid(m_pid_basf2, &status, 0);
209 if (m_pid_receiver != 0) {
210 printf(
"RFEventProcessor : killing receiver pid=%d\n", m_pid_receiver);
211 kill(m_pid_receiver, SIGINT);
212 waitpid(m_pid_receiver, &status, 0);
214 if (m_pid_hrecv != 0) {
215 printf(
"RFEventProcessor : killing hserver pid=%d\n", m_pid_hrecv);
216 kill(m_pid_hrecv, SIGINT);
217 waitpid(m_pid_hrecv, &status, 0);
219 if (m_pid_hrelay != 0) {
220 printf(
"RFEventProcessor : killing hrelay pid=%d\n", m_pid_hrelay);
221 kill(m_pid_hrelay, SIGINT);
222 waitpid(m_pid_hrelay, &status, 0);
226 m_rbufin->forceClear();
227 m_rbufout->forceClear();
230 m_flow->fillProcessStatus(GetNodeInfo());
232 printf(
"Unconfigure : done\n");
237int RFEventProcessor::Start(NSMmsg* nsmm, NSMcontext* )
239 string rbufin = string(m_conf->getconf(
"system",
"unitname")) +
":" +
240 string(m_conf->getconf(
"processor",
"ringbufin"));
241 string rbufout = string(m_conf->getconf(
"system",
"unitname")) +
":" +
242 string(m_conf->getconf(
"processor",
"ringbufout"));
243 char* hport = m_conf->getconf(
"processor",
"historecv",
"port");
246 m_expno = nsmm->pars[0];
247 m_runno = nsmm->pars[1];
250 m_rbufout->forceClear();
251 m_rbufin->forceClear();
254 char* basf2 = m_conf->getconf(
"processor",
"basf2",
"script");
256 basf2 =
const_cast<char*
>(nsmm->datap);
257 printf(
"Configure: basf2 script overridden : %s\n", basf2);
259 m_pid_basf2 = m_proc->Execute(basf2,
const_cast<char*
>(rbufin.c_str()),
const_cast<char*
>(rbufout.c_str()), hport);
264int RFEventProcessor::Stop(NSMmsg* , NSMcontext* )
266 printf(
"RFEventProcessor : STOP processing started\n");
299 if (m_pid_basf2 != 0) {
300 printf(
"RFEventProcessor : killing basf2 pid=%d\n", m_pid_basf2);
301 kill(m_pid_basf2, SIGINT);
302 waitpid(m_pid_basf2, &status, 0);
305 sprintf(outfile,
"dqm_e%4.4dr%6.6d.root", m_expno, m_runno);
306 std::rename(
"histofile.root", outfile);
307 printf(
"output file name = %s\n", outfile);
311 printf(
"RFEventProcessor : STOP processing done\n");
316int RFEventProcessor::Restart(NSMmsg*, NSMcontext*)
318 printf(
"RFEventProcessor : Restarting!!!!!\n");
344 NSMmsg* nsmmsg = NULL;
345 NSMcontext* nsmcontext = NULL;
346 RFEventProcessor::UnConfigure(nsmmsg, nsmcontext);
348 RFEventProcessor::Configure(nsmmsg, nsmcontext);
354void RFEventProcessor::server()
357 m_flow->fillProcessStatus(GetNodeInfo());
360 pid_t pid = m_proc->CheckProcess();
362 printf(
"RFEventProcessor : process dead pid=%d\n", pid);
363 if (pid == m_pid_sender) {
364 m_log->Fatal(
"RFEventProcessor : sender dead. pid=%d\n", m_pid_sender);
366 }
else if (pid == m_pid_basf2) {
367 m_log->Fatal(
"RFEventProcessor : basf2 dead. pid=%d\n", m_pid_basf2);
369 }
else if (pid == m_pid_receiver) {
370 m_log->Fatal(
"RFEventProcessor : receiver dead. pid=%d\n", m_pid_receiver);
372 }
else if (pid == m_pid_hrecv) {
373 m_log->Fatal(
"RFEventProcessor : hserver dead. pid=%d\n", m_pid_hrecv);
375 }
else if (pid == m_pid_hrelay) {
376 m_log->Fatal(
"RFEventProcessor : hrelay dead. pid=%d\n", m_pid_hrelay);
380 int st = m_proc->CheckOutput();
382 perror(
"RFEventProcessor::server");
385 m_log->ProcessLog(m_proc->GetFd());
387 m_flow->fillNodeInfo(0, GetNodeInfo(),
false);
388 m_flow->fillNodeInfo(1, GetNodeInfo(),
true);
389 m_flow->fillProcessStatus(GetNodeInfo(), m_pid_receiver, m_pid_sender, m_pid_basf2,
390 m_pid_hrecv, m_pid_hrelay);
394void RFEventProcessor::cleanup()
396 printf(
"RFEventProcessor : cleaning up\n");
397 UnConfigure(NULL, NULL);
398 printf(
"RFEventProcessor: Done. Exitting\n");
Abstract base class for different kinds of events.