Belle II Software development
RFMaster Class Reference
Inheritance diagram for RFMaster:
RFServerBase

Public Member Functions

 RFMaster (const std::string &conf)
 
 RFMaster (const RFMaster &)=delete
 Copy constructor (disabled).
 
RFMaster & operator= (const RFMaster &)=delete
 Operator = (disabled).
 
int Configure (NSMmsg *, NSMcontext *) override
 
int UnConfigure (NSMmsg *, NSMcontext *) override
 
int Start (NSMmsg *, NSMcontext *) override
 
int Stop (NSMmsg *, NSMcontext *) override
 
int Restart (NSMmsg *, NSMcontext *) override
 
virtual int Pause (NSMmsg *, NSMcontext *)
 
virtual int Resume (NSMmsg *, NSMcontext *)
 
virtual int Status (NSMmsg *, NSMcontext *)
 
virtual void SetNodeInfo (RfNodeInfo *ptr)
 
virtual RfNodeInfo * GetNodeInfo ()
 

Static Public Member Functions

static void Hook_Message_Handlers ()
 
static void Log_Handler (NSMmsg *msg, NSMcontext *ctx)
 
static void monitor_loop ()
 

Static Public Attributes

static RFServerBase * s_instance
 

Private Attributes

RFConf * m_conf
 
RFLogManager * m_log
 
RfNodeInfo * m_nsmmem = nullptr
 

Detailed Description

Definition at line 22 of file RFMaster.h.

Constructor & Destructor Documentation

◆ RFMaster()

RFMaster ( const std::string & conf)
explicit

Definition at line 26 of file RFMaster.cc.

27{
28 // 0. Initialize configuration manager
29 m_conf = new RFConf(conffile.c_str());
30 char* nodename = m_conf->getconf("master", "nodename");
31 // char nodename[256];
32 // gethostname ( nodename, sizeof(nodename) );
33
34 // 1. Initialize local shared memory
35 // m_shm = new RFSharedMem(nodename);
36
37 // 2. Set execution directory
38 string execdir = string(m_conf->getconf("system", "execdir_base")) + "/master";
39
40 mkdir(execdir.c_str(), 0755);
41 chdir(execdir.c_str());
42
43 // 3. Initialize LogManager
44 m_log = new RFLogManager(nodename, m_conf->getconf("system", "lognode"));
45
46 // 4. Leave PID file
47 FILE* f = fopen("pid.data", "w");
48 if (f != NULL) {
49 fprintf(f, "%d", getpid());
50 fclose(f);
51 }
52
53}

◆ ~RFMaster()

~RFMaster ( )

Definition at line 55 of file RFMaster.cc.

56{
57 delete m_log;
58 // delete m_shm;
59 delete m_conf;
60}

Member Function Documentation

◆ Configure()

int Configure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 85 of file RFMaster.cc.

86{
87 int* pars = nullptr;
88
89 // 0. Configure DqmServer
90 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
91 RFNSM_Status::Instance().set_flag(0);
92 // b2nsm_sendreq(dqmserver, "RF_CONFIGURE", 0, pars);
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");
96 // sleep(2);
97
98 // 1. Configure distributor
99 const char* distributor = m_conf->getconf("distributor", "nodename");
100 RFNSM_Status::Instance().set_flag(0);
101 // b2nsm_sendreq(distributor, "RF_CONFIGURE", 0, pars);
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");
105
106 // sleep(2);
107
108 // 2. Configure event processors
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");
113
114 char hostnode[512], idname[3];
115 int nnodes = 0;
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);
122 // b2nsm_sendreq(hostnode, "RF_CONFIGURE", 0, pars);
123 b2nsm_sendreq(hostnode, "RC_LOAD", 0, pars);
124 nnodes++;
125 }
126 }
127 // while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
128 sleep(10);
129
130 printf("RFMaster:: distributor configured\n");
131
132 // 3. Configure collector
133 const char* collector = m_conf->getconf("collector", "nodename");
134 RFNSM_Status::Instance().set_flag(0);
135 // b2nsm_sendreq(collector, "RF_CONFIGURE", 0, pars);
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");
139 // sleep ( 5 );
140
141 // 4. Configure
142 const char* roisender = m_conf->getconf("roisender", "nodename");
143 RFNSM_Status::Instance().set_flag(0);
144 // b2nsm_sendreq(roisender, "RF_CONFIGURE", 0, pars);
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");
148
149 return 0;
150}

◆ GetNodeInfo()

virtual RfNodeInfo * GetNodeInfo ( )
inlinevirtualinherited

Definition at line 38 of file RFServerBase.h.

39 {
40 return m_nsmmem;
41 };

◆ Hook_Message_Handlers()

void Hook_Message_Handlers ( )
static

Definition at line 62 of file RFMaster.cc.

63{
64 // 5. Hook message handlers
65 if (b2nsm_callback("LOG", Log_Handler) < 0) {
66 fprintf(stderr, "RFMaster : hooking INFO handler failed, %s\n",
67 b2nsm_strerror());
68 }
69 printf("RFMaster: Message Handlers - Ready\n");
70
71}

◆ Log_Handler()

void Log_Handler ( NSMmsg * msg,
NSMcontext * ctx )
static

Definition at line 75 of file RFMaster.cc.

76{
77 // printf ( "RFMaster : [INFO] received\n" );
78 // b2nsm_ok ( msg, "INFO!!", NULL );
79 // fflush ( stdout );
80}

◆ monitor_loop()

void monitor_loop ( )
static

Definition at line 355 of file RFMaster.cc.

356{
357 while (true) {
358 b2nsm_wait(10);
359 }
360}

◆ Pause()

virtual int Pause ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 28 of file RFServerBase.h.

28{ return 0; };

◆ Restart()

int Restart ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 311 of file RFMaster.cc.

312{
313 int* pars = nullptr;
314
315 // 0. Configure DqmServer
316 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
317 // b2nsm_sendreq(dqmserver, "RF_RESTART", 0, pars);
318 b2nsm_sendreq(dqmserver, "RC_RECOVER", 0, pars);
319 sleep(2);
320
321 // 1. Configure distributor
322 const char* distributor = m_conf->getconf("distributor", "nodename");
323 // b2nsm_sendreq(distributor, "RF_RESTART", 0, pars);
324 b2nsm_sendreq(distributor, "RC_RECOVER", 0, pars);
325 sleep(2);
326
327 // 2. Configure event processors
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");
332
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);
339 // b2nsm_sendreq(hostnode, "RF_RESTART", 0, pars);
340 b2nsm_sendreq(hostnode, "RC_RECOVER", 0, pars);
341 }
342 }
343 sleep(2);
344
345 // 3. Configure collector
346 const char* collector = m_conf->getconf("collector", "nodename");
347 // b2nsm_sendreq(collector, "RF_RESTART", 0, pars);
348 b2nsm_sendreq(collector, "RC_RECOVER", 0, pars);
349
350 return 0;
351}

◆ Resume()

virtual int Resume ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 29 of file RFServerBase.h.

29{ return 0; };

◆ SetNodeInfo()

virtual void SetNodeInfo ( RfNodeInfo * ptr)
inlinevirtualinherited

Definition at line 33 of file RFServerBase.h.

34 {
35 m_nsmmem = ptr;
36 };

◆ Start()

int Start ( NSMmsg * msgm,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 226 of file RFMaster.cc.

227{
228 int pars[10];
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]);
232 fflush(stdout);
233
234 // 0. Start DQMserver
235 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
236 RFNSM_Status::Instance().set_flag(0);
237 // b2nsm_sendreq(dqmserver, "RF_STOP", 0, pars);
238 b2nsm_sendreq(dqmserver, "RC_START", 2, pars);
239 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
240
241 // 1. Start worker nodes
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");
246
247 char hostnode[512], idname[3];
248 RFNSM_Status::Instance().set_flag(0);
249 int nnodes = 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);
255 // b2nsm_sendreq(hostnode, "RF_STOP", 0, pars);
256 b2nsm_sendreq(hostnode, "RC_START", 2, pars);
257 nnodes++;
258 }
259 }
260
261 return 0;
262}

◆ Status()

virtual int Status ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 31 of file RFServerBase.h.

31{ return 0; };

◆ Stop()

int Stop ( NSMmsg * msg,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 264 of file RFMaster.cc.

265{
266 int pars[10];
267 pars[0] = msg->pars[0];
268 pars[1] = msg->pars[1];
269
270 // 1. Stop worker nodes
271 // Unconfigure event processors
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");
276
277 char hostnode[512], idname[3];
278 RFNSM_Status::Instance().set_flag(0);
279 int nnodes = 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);
285 // b2nsm_sendreq(hostnode, "RF_STOP", 0, pars);
286 b2nsm_sendreq(hostnode, "RC_STOP", 0, pars);
287 nnodes++;
288 }
289 }
290#ifdef DESY
291 b2nsm_wait(5);
292#else
293 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
294#endif
295
296 // 2. Stop DqmServer node
297 // Unconfigure DqmServer
298 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
299 RFNSM_Status::Instance().set_flag(0);
300 // b2nsm_sendreq(dqmserver, "RF_STOP", 0, pars);
301 b2nsm_sendreq(dqmserver, "RC_STOP", 0, pars);
302 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
303
304 printf("RFMaster : Stopped. exp=%d, run=%d\n", pars[0], pars[1]);
305 fflush(stdout);
306
307 return 0;
308}

◆ UnConfigure()

int UnConfigure ( NSMmsg * msgm,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 152 of file RFMaster.cc.

153{
154 int pars[10];
155 pars[0] = msgm->pars[0];
156 pars[1] = msgm->pars[1];
157
158 // Unconfigure RoiSender
159 const char* roisender = m_conf->getconf("roisender", "nodename");
160 RFNSM_Status::Instance().set_flag(0);
161 // b2nsm_sendreq(roisender, "RF_UNCONFIGURE", 0, pars);
162 b2nsm_sendreq(roisender, "RC_ABORT", 0, pars);
163 while (RFNSM_Status::Instance().get_flag() == 1) b2nsm_wait(1);
164
165 // Unconfigure collector
166 const char* collector = m_conf->getconf("collector", "nodename");
167 RFNSM_Status::Instance().set_flag(0);
168 // b2nsm_sendreq(collector, "RF_UNCONFIGURE", 0, pars);
169 b2nsm_sendreq(collector, "RC_ABORT", 0, pars);
170 while (RFNSM_Status::Instance().get_flag() == 1) b2nsm_wait(1);
171
172 // Unconfigure event processors
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");
177
178 char hostnode[512], idname[3];
179 RFNSM_Status::Instance().set_flag(0);
180 int nnodes = 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);
186 // b2nsm_sendreq(hostnode, "RF_UNCONFIGURE", 0, pars);
187 b2nsm_sendreq(hostnode, "RC_ABORT", 0, pars);
188 nnodes++;
189 }
190 }
191#ifdef DESY
192 b2nsm_wait(5);
193#else
194 // printf ( "RFMaster : Unconfigure : started. - nnodes=%d, flag=%d\n",
195 // nnodes, RFNSM_Status::Instance().get_flag() );
196 while (RFNSM_Status::Instance().get_flag() != nnodes) {
197 b2nsm_wait(1);
198 // printf ( "RFMaster : Unconfigure : in prog. - nnodes=%d, flag=%d\n",
199 // nnodes, RFNSM_Status::Instance().get_flag() );
200 }
201 // printf ( "RFMaster : Unconfigure - done: nnodes=%d, flag=%d\n",
202 // nnodes, RFNSM_Status::Instance().get_flag() );
203#endif
204
205 // Unconfigure DqmServer
206 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
207 RFNSM_Status::Instance().set_flag(0);
208 // b2nsm_sendreq(dqmserver, "RF_UNCONFIGURE", 0, pars);
209 b2nsm_sendreq(dqmserver, "RC_ABORT", 0, pars);
210 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
211
212 // Unconfigure distributor
213 const char* distributor = m_conf->getconf("distributor", "nodename");
214 RFNSM_Status::Instance().set_flag(0);
215 // b2nsm_sendreq(distributor, "RF_UNCONFIGURE", 0, pars);
216 b2nsm_sendreq(distributor, "RC_ABORT", 0, pars);
217 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
218
219 printf("RFMaster : Unconfigure done.\n");
220 fflush(stdout);
221
222 return 0;
223
224}

Member Data Documentation

◆ m_conf

RFConf* m_conf
private

Definition at line 50 of file RFMaster.h.

◆ m_log

RFLogManager* m_log
private

Definition at line 52 of file RFMaster.h.

◆ m_nsmmem

RfNodeInfo* m_nsmmem = nullptr
privateinherited

Definition at line 47 of file RFServerBase.h.

◆ s_instance

RFServerBase* s_instance
staticinherited

Definition at line 44 of file RFServerBase.h.


The documentation for this class was generated from the following files: