9#include "daq/rfarm/manager/RFMaster.h"
10#include "daq/rfarm/manager/RFNSM.h"
12#include <nsm2/belle2nsm.h>
26RFMaster::RFMaster(
const 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");
49 fprintf(f,
"%d", getpid());
62void RFMaster::Hook_Message_Handlers()
65 if (b2nsm_callback(
"LOG", Log_Handler) < 0) {
66 fprintf(stderr,
"RFMaster : hooking INFO handler failed, %s\n",
69 printf(
"RFMaster: Message Handlers - Ready\n");
75void RFMaster::Log_Handler(NSMmsg* , NSMcontext* )
85int RFMaster::Configure(NSMmsg*, NSMcontext*)
90 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
91 RFNSM_Status::Instance().set_flag(0);
93 b2nsm_sendreq(dqmserver,
"RC_LOAD", 0, pars);
94 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
95 printf(
"RFMaster:: dqmserver configured\n");
99 const char* distributor = m_conf->getconf(
"distributor",
"nodename");
100 RFNSM_Status::Instance().set_flag(0);
102 b2nsm_sendreq(distributor,
"RC_LOAD", 0, pars);
103 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
104 printf(
"RFMaster:: distributor configured\n");
109 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
110 int idbase = m_conf->getconfi(
"processor",
"idbase");
111 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
112 char* badlist = m_conf->getconf(
"processor",
"badlist");
114 char hostnode[512], idname[3];
116 RFNSM_Status::Instance().set_flag(0);
117 for (
int i = 0; i < maxnodes; i++) {
118 sprintf(idname,
"%2.2d", idbase + i);
119 if (badlist == NULL ||
120 strstr(badlist, idname) == 0) {
121 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
123 b2nsm_sendreq(hostnode,
"RC_LOAD", 0, pars);
130 printf(
"RFMaster:: distributor configured\n");
133 const char* collector = m_conf->getconf(
"collector",
"nodename");
134 RFNSM_Status::Instance().set_flag(0);
136 b2nsm_sendreq(collector,
"RC_LOAD", 0, pars);
137 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
138 printf(
"RFMaster:: collector configured\n");
142 const char* roisender = m_conf->getconf(
"roisender",
"nodename");
143 RFNSM_Status::Instance().set_flag(0);
145 b2nsm_sendreq(roisender,
"RC_LOAD", 0, pars);
146 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
147 printf(
"RFMaster:: roisender configured\n");
152int RFMaster::UnConfigure(NSMmsg* msgm, NSMcontext* )
155 pars[0] = msgm->pars[0];
156 pars[1] = msgm->pars[1];
159 const char* roisender = m_conf->getconf(
"roisender",
"nodename");
160 RFNSM_Status::Instance().set_flag(0);
162 b2nsm_sendreq(roisender,
"RC_ABORT", 0, pars);
163 while (RFNSM_Status::Instance().get_flag() == 1) b2nsm_wait(1);
166 const char* collector = m_conf->getconf(
"collector",
"nodename");
167 RFNSM_Status::Instance().set_flag(0);
169 b2nsm_sendreq(collector,
"RC_ABORT", 0, pars);
170 while (RFNSM_Status::Instance().get_flag() == 1) b2nsm_wait(1);
173 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
174 int idbase = m_conf->getconfi(
"processor",
"idbase");
175 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
176 char* badlist = m_conf->getconf(
"processor",
"badlist");
178 char hostnode[512], idname[3];
179 RFNSM_Status::Instance().set_flag(0);
181 for (
int i = 0; i < maxnodes; i++) {
182 sprintf(idname,
"%2.2d", idbase + i);
183 if (badlist == NULL ||
184 strstr(badlist, idname) == 0) {
185 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
187 b2nsm_sendreq(hostnode,
"RC_ABORT", 0, pars);
196 while (RFNSM_Status::Instance().get_flag() != nnodes) {
206 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
207 RFNSM_Status::Instance().set_flag(0);
209 b2nsm_sendreq(dqmserver,
"RC_ABORT", 0, pars);
210 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
213 const char* distributor = m_conf->getconf(
"distributor",
"nodename");
214 RFNSM_Status::Instance().set_flag(0);
216 b2nsm_sendreq(distributor,
"RC_ABORT", 0, pars);
217 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
219 printf(
"RFMaster : Unconfigure done.\n");
226int RFMaster::Start(NSMmsg* msgm, NSMcontext* )
229 pars[0] = msgm->pars[0];
230 pars[1] = msgm->pars[1];
231 printf(
"RFMaster : Start exp=%d, run=%d\n", pars[0], pars[1]);
235 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
236 RFNSM_Status::Instance().set_flag(0);
238 b2nsm_sendreq(dqmserver,
"RC_START", 2, pars);
239 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
242 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
243 int idbase = m_conf->getconfi(
"processor",
"idbase");
244 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
245 char* badlist = m_conf->getconf(
"processor",
"badlist");
247 char hostnode[512], idname[3];
248 RFNSM_Status::Instance().set_flag(0);
250 for (
int i = 0; i < maxnodes; i++) {
251 sprintf(idname,
"%2.2d", idbase + i);
252 if (badlist == NULL ||
253 strstr(badlist, idname) == 0) {
254 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
256 b2nsm_sendreq(hostnode,
"RC_START", 2, pars);
264int RFMaster::Stop(NSMmsg* msg, NSMcontext*)
267 pars[0] = msg->pars[0];
268 pars[1] = msg->pars[1];
272 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
273 int idbase = m_conf->getconfi(
"processor",
"idbase");
274 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
275 char* badlist = m_conf->getconf(
"processor",
"badlist");
277 char hostnode[512], idname[3];
278 RFNSM_Status::Instance().set_flag(0);
280 for (
int i = 0; i < maxnodes; i++) {
281 sprintf(idname,
"%2.2d", idbase + i);
282 if (badlist == NULL ||
283 strstr(badlist, idname) == 0) {
284 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
286 b2nsm_sendreq(hostnode,
"RC_STOP", 0, pars);
293 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
298 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
299 RFNSM_Status::Instance().set_flag(0);
301 b2nsm_sendreq(dqmserver,
"RC_STOP", 0, pars);
302 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
304 printf(
"RFMaster : Stopped. exp=%d, run=%d\n", pars[0], pars[1]);
311int RFMaster::Restart(NSMmsg*, NSMcontext*)
316 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
318 b2nsm_sendreq(dqmserver,
"RC_RECOVER", 0, pars);
322 const char* distributor = m_conf->getconf(
"distributor",
"nodename");
324 b2nsm_sendreq(distributor,
"RC_RECOVER", 0, pars);
328 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
329 int idbase = m_conf->getconfi(
"processor",
"idbase");
330 const char* hostbase = m_conf->getconf(
"processor",
"hostbase");
331 char* badlist = m_conf->getconf(
"processor",
"badlist");
333 char hostnode[512], idname[3];
334 for (
int i = 0; i < maxnodes; i++) {
335 sprintf(idname,
"%2.2d", idbase + i);
336 if (badlist == NULL ||
337 strstr(badlist, idname) == 0) {
338 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
340 b2nsm_sendreq(hostnode,
"RC_RECOVER", 0, pars);
346 const char* collector = m_conf->getconf(
"collector",
"nodename");
348 b2nsm_sendreq(collector,
"RC_RECOVER", 0, pars);
355void RFMaster::monitor_loop()
Abstract base class for different kinds of events.