9#include "daq/expreco/ERecoMaster.h"
11#include "daq/rfarm/manager/RFNSM.h"
13#include <nsm2/belle2nsm.h>
28ERecoMaster::ERecoMaster(
const string& conffile)
31 m_conf =
new RFConf(conffile.c_str());
32 char* nodename = m_conf->getconf(
"master",
"nodename");
40 string execdir = string(m_conf->getconf(
"system",
"execdir_base")) +
"/master";
42 mkdir(execdir.c_str(), 0755);
43 chdir(execdir.c_str());
46 m_log =
new RFLogManager(nodename, m_conf->getconf(
"system",
"lognode"));
49 FILE* f = fopen(
"pid.data",
"w");
51 fprintf(f,
"%d", getpid());
58ERecoMaster::~ERecoMaster()
65void ERecoMaster::Hook_Message_Handlers()
68 if (b2nsm_callback(
"LOG", Log_Handler) < 0) {
69 fprintf(stderr,
"ERecoMaster : hooking INFO handler failed, %s\n",
72 printf(
"ERecoMaster: Message Handlers - Ready\n");
78void ERecoMaster::Log_Handler(NSMmsg* , NSMcontext* )
88int ERecoMaster::Configure(NSMmsg*, NSMcontext*)
93 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
94 RFNSM_Status::Instance().set_flag(0);
96 b2nsm_sendreq(dqmserver,
"RC_LOAD", 0, pars);
97 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
98 printf(
"ERecoMaster:: dqmserver configured\n");
102 const char* distributor = m_conf->getconf(
"distributor",
"nodename");
103 RFNSM_Status::Instance().set_flag(0);
105 b2nsm_sendreq(distributor,
"RC_LOAD", 0, pars);
106 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
107 printf(
"ERecoMaster:: distributor configured\n");
112 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
113 int idbase = m_conf->getconfi(
"processor",
"idbase");
114 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
115 char* badlist = m_conf->getconf(
"processor",
"badlist");
117 char hostnode[512], idname[3];
119 RFNSM_Status::Instance().set_flag(0);
120 for (
int i = 0; i < maxnodes; i++) {
121 sprintf(idname,
"%2.2d", idbase + i);
122 if (badlist == NULL ||
123 strstr(badlist, idname) == 0) {
124 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
126 b2nsm_sendreq(hostnode,
"RC_LOAD", 0, pars);
130 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
135 const char* sampler = m_conf->getconf(
"eventsampler",
"nodename");
136 RFNSM_Status::Instance().set_flag(0);
138 b2nsm_sendreq(sampler,
"RC_LOAD", 0, pars);
139 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
140 printf(
"ERecoMaster:: sampler configured\n");
145 printf(
"ERecoMaster:: event processors configured\n");
150int ERecoMaster::UnConfigure(NSMmsg*, NSMcontext*)
155 const char* sampler = m_conf->getconf(
"eventsampler",
"nodename");
156 RFNSM_Status::Instance().set_flag(0);
158 b2nsm_sendreq(sampler,
"RC_ABORT", 0, pars);
159 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
160 printf(
"ErecoMaster: sampler unconfigured.\n");
163 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
164 int idbase = m_conf->getconfi(
"processor",
"idbase");
165 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
166 char* badlist = m_conf->getconf(
"processor",
"badlist");
168 char hostnode[512], idname[3];
169 RFNSM_Status::Instance().set_flag(0);
171 for (
int i = 0; i < maxnodes; i++) {
172 sprintf(idname,
"%2.2d", idbase + i);
173 if (badlist == NULL ||
174 strstr(badlist, idname) == 0) {
175 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
177 b2nsm_sendreq(hostnode,
"RC_ABORT", 0, pars);
184 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
186 printf(
"ERecoMaster: eventprocessors unconfigured.\n");
189 const char* distributor = m_conf->getconf(
"distributor",
"nodename");
190 RFNSM_Status::Instance().set_flag(0);
192 b2nsm_sendreq(distributor,
"RC_ABORT", 0, pars);
193 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
194 printf(
"ErecoMaster: distributor unconfigured.\n");
197 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
198 RFNSM_Status::Instance().set_flag(0);
200 b2nsm_sendreq(dqmserver,
"RC_ABORT", 0, pars);
203 printf(
"ErecoMaster: dqmserver unconfigured.\n");
209int ERecoMaster::Stop(NSMmsg* msg, NSMcontext*)
212 pars[0] = msg->pars[0];
213 pars[1] = msg->pars[1];
217 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
218 int idbase = m_conf->getconfi(
"processor",
"idbase");
219 const char* hostbase = m_conf->getconf(
"processor",
"nodebase");
220 char* badlist = m_conf->getconf(
"processor",
"badlist");
222 char hostnode[512], idname[3];
223 RFNSM_Status::Instance().set_flag(0);
225 for (
int i = 0; i < maxnodes; i++) {
226 sprintf(idname,
"%2.2d", idbase + i);
227 if (badlist == NULL ||
228 strstr(badlist, idname) == 0) {
229 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
231 b2nsm_sendreq(hostnode,
"RC_STOP", 0, pars);
238 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
243 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
244 RFNSM_Status::Instance().set_flag(0);
246 b2nsm_sendreq(dqmserver,
"RC_STOP", 0, pars);
247 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
253int ERecoMaster::Restart(NSMmsg*, NSMcontext*)
258 const char* dqmserver = m_conf->getconf(
"dqmserver",
"nodename");
260 b2nsm_sendreq(dqmserver,
"RC_RECOVER", 0, pars);
264 const char* distributor = m_conf->getconf(
"distributor",
"nodename");
266 b2nsm_sendreq(distributor,
"RC_RECOVER", 0, pars);
270 int maxnodes = m_conf->getconfi(
"processor",
"nnodes");
271 int idbase = m_conf->getconfi(
"processor",
"idbase");
272 const char* hostbase = m_conf->getconf(
"processor",
"hostbase");
273 char* badlist = m_conf->getconf(
"processor",
"badlist");
275 char hostnode[512], idname[3];
276 for (
int i = 0; i < maxnodes; i++) {
277 sprintf(idname,
"%2.2d", idbase + i);
278 if (badlist == NULL ||
279 strstr(badlist, idname) == 0) {
280 sprintf(hostnode,
"evp_%s%2.2d", hostbase, idbase + i);
282 b2nsm_sendreq(hostnode,
"RC_RECOVER", 0, pars);
292void ERecoMaster::monitor_loop()
Abstract base class for different kinds of events.