9#include "daq/rfarm/manager/RFMaster.h"
10#include "daq/rfarm/manager/RFNSM.h"
12#include <nsm2/belle2nsm.h>
26RFMaster::RFMaster(
string conffile)
29 m_conf =
new RFConf(conffile.c_str());
30 char* nodename = m_conf->getconf(
"master",
"nodename");
38 string execdir = string(m_conf->getconf(
"system",
"execdir_base")) +
"/master";
40 mkdir(execdir.c_str(), 0755);
41 chdir(execdir.c_str());
44 m_log =
new RFLogManager(nodename, m_conf->getconf(
"system",
"lognode"));
47 FILE* f = fopen(
"pid.data",
"w");
48 fprintf(f,
"%d", getpid());
60void RFMaster::Hook_Message_Handlers()
63 if (b2nsm_callback(
"LOG", Log_Handler) < 0) {
64 fprintf(stderr,
"RFMaster : hooking INFO handler failed, %s\n",
67 printf(
"RFMaster: Message Handlers - Ready\n");
88 char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
89 RFNSM_Status::Instance().set_flag(0);
91 b2nsm_sendreq(dqmserver,
"RC_LOAD", 0, pars);
92 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
93 printf(
"RFMaster:: dqmserver configured\n");
97 char* distributor = m_conf->getconf(
"distributor",
"nodename");
98 RFNSM_Status::Instance().set_flag(0);
100 b2nsm_sendreq(distributor,
"RC_LOAD", 0, pars);
101 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
102 printf(
"RFMaster:: distributor configured\n");
107 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
108 int idbase = m_conf->getconfi(
"processor",
"idbase");
109 char* hostbase = m_conf->getconf(
"processor",
"nodebase");
110 char* badlist = m_conf->getconf(
"processor",
"badlist");
112 char hostnode[512], idname[3];
114 RFNSM_Status::Instance().set_flag(0);
115 for (
int i = 0; i < maxnodes; i++) {
116 sprintf(idname,
"%2.2d", idbase + i);
117 if (badlist == NULL ||
118 strstr(badlist, idname) == 0) {
119 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
121 b2nsm_sendreq(hostnode,
"RC_LOAD", 0, pars);
128 printf(
"RFMaster:: distributor configured\n");
131 char* collector = m_conf->getconf(
"collector",
"nodename");
132 RFNSM_Status::Instance().set_flag(0);
134 b2nsm_sendreq(collector,
"RC_LOAD", 0, pars);
135 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
136 printf(
"RFMaster:: collector configured\n");
140 char* roisender = m_conf->getconf(
"roisender",
"nodename");
141 RFNSM_Status::Instance().set_flag(0);
143 b2nsm_sendreq(roisender,
"RC_LOAD", 0, pars);
144 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
145 printf(
"RFMaster:: roisender configured\n");
153 pars[0] = msgm->pars[0];
154 pars[1] = msgm->pars[1];
157 char* roisender = m_conf->getconf(
"roisender",
"nodename");
158 RFNSM_Status::Instance().set_flag(0);
160 b2nsm_sendreq(roisender,
"RC_ABORT", 0, pars);
161 while (RFNSM_Status::Instance().get_flag() == 1) b2nsm_wait(1);
164 char* collector = m_conf->getconf(
"collector",
"nodename");
165 RFNSM_Status::Instance().set_flag(0);
167 b2nsm_sendreq(collector,
"RC_ABORT", 0, pars);
168 while (RFNSM_Status::Instance().get_flag() == 1) b2nsm_wait(1);
171 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
172 int idbase = m_conf->getconfi(
"processor",
"idbase");
173 char* hostbase = m_conf->getconf(
"processor",
"nodebase");
174 char* badlist = m_conf->getconf(
"processor",
"badlist");
176 char hostnode[512], idname[3];
177 RFNSM_Status::Instance().set_flag(0);
179 for (
int i = 0; i < maxnodes; i++) {
180 sprintf(idname,
"%2.2d", idbase + i);
181 if (badlist == NULL ||
182 strstr(badlist, idname) == 0) {
183 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
185 b2nsm_sendreq(hostnode,
"RC_ABORT", 0, pars);
194 while (RFNSM_Status::Instance().get_flag() != nnodes) {
204 char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
205 RFNSM_Status::Instance().set_flag(0);
207 b2nsm_sendreq(dqmserver,
"RC_ABORT", 0, pars);
208 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
211 char* distributor = m_conf->getconf(
"distributor",
"nodename");
212 RFNSM_Status::Instance().set_flag(0);
214 b2nsm_sendreq(distributor,
"RC_ABORT", 0, pars);
215 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
217 printf(
"RFMaster : Unconfigure done.\n");
227 pars[0] = msgm->pars[0];
228 pars[1] = msgm->pars[1];
229 printf(
"RFMaster : Start exp=%d, run=%d\n", pars[0], pars[1]);
233 char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
234 RFNSM_Status::Instance().set_flag(0);
236 b2nsm_sendreq(dqmserver,
"RC_START", 2, pars);
237 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
240 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
241 int idbase = m_conf->getconfi(
"processor",
"idbase");
242 char* hostbase = m_conf->getconf(
"processor",
"nodebase");
243 char* badlist = m_conf->getconf(
"processor",
"badlist");
245 char hostnode[512], idname[3];
246 RFNSM_Status::Instance().set_flag(0);
248 for (
int i = 0; i < maxnodes; i++) {
249 sprintf(idname,
"%2.2d", idbase + i);
250 if (badlist == NULL ||
251 strstr(badlist, idname) == 0) {
252 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
254 b2nsm_sendreq(hostnode,
"RC_START", 2, pars);
265 pars[0] = msg->pars[0];
266 pars[1] = msg->pars[1];
270 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
271 int idbase = m_conf->getconfi(
"processor",
"idbase");
272 char* hostbase = m_conf->getconf(
"processor",
"nodebase");
273 char* badlist = m_conf->getconf(
"processor",
"badlist");
275 char hostnode[512], idname[3];
276 RFNSM_Status::Instance().set_flag(0);
278 for (
int i = 0; i < maxnodes; i++) {
279 sprintf(idname,
"%2.2d", idbase + i);
280 if (badlist == NULL ||
281 strstr(badlist, idname) == 0) {
282 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
284 b2nsm_sendreq(hostnode,
"RC_STOP", 0, pars);
291 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
296 char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
297 RFNSM_Status::Instance().set_flag(0);
299 b2nsm_sendreq(dqmserver,
"RC_STOP", 0, pars);
300 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
302 printf(
"RFMaster : Stopped. exp=%d, run=%d\n", pars[0], pars[1]);
314 char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
316 b2nsm_sendreq(dqmserver,
"RC_RECOVER", 0, pars);
320 char* distributor = m_conf->getconf(
"distributor",
"nodename");
322 b2nsm_sendreq(distributor,
"RC_RECOVER", 0, pars);
326 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
327 int idbase = m_conf->getconfi(
"processor",
"idbase");
328 char* hostbase = m_conf->getconf(
"processor",
"hostbase");
329 char* badlist = m_conf->getconf(
"processor",
"badlist");
331 char hostnode[512], idname[3];
332 for (
int i = 0; i < maxnodes; i++) {
333 sprintf(idname,
"%2.2d", idbase + i);
334 if (badlist == NULL ||
335 strstr(badlist, idname) == 0) {
336 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
338 b2nsm_sendreq(hostnode,
"RC_RECOVER", 0, pars);
344 char* collector = m_conf->getconf(
"collector",
"nodename");
346 b2nsm_sendreq(collector,
"RC_RECOVER", 0, pars);
353void RFMaster::monitor_loop()
Abstract base class for different kinds of events.