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

Public Member Functions

 ERecoMaster (const std::string &conf)
 
 ERecoMaster (const ERecoMaster &)=delete
 Copy constructor (disabled).
 
ERecoMaster & operator= (const ERecoMaster &)=delete
 Operator = (disabled).
 
int Configure (NSMmsg *, NSMcontext *) override
 
int UnConfigure (NSMmsg *, NSMcontext *) override
 
int Stop (NSMmsg *, NSMcontext *) override
 
int Restart (NSMmsg *, NSMcontext *) override
 
virtual int Start (NSMmsg *, NSMcontext *)
 
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 ERecoMaster.h.

Constructor & Destructor Documentation

◆ ERecoMaster()

ERecoMaster ( const std::string & conf)
explicit

Definition at line 28 of file ERecoMaster.cc.

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

◆ ~ERecoMaster()

Definition at line 58 of file ERecoMaster.cc.

59{
60 delete m_log;
61 // delete m_shm;
62 delete m_conf;
63}

Member Function Documentation

◆ Configure()

int Configure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 88 of file ERecoMaster.cc.

89{
90 int* pars = nullptr;
91
92 // 0. Configure DqmServer
93 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
94 RFNSM_Status::Instance().set_flag(0);
95 // b2nsm_sendreq(dqmserver, "RF_CONFIGURE", 0, pars);
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");
99 sleep(2);
100
101 // 1. Configure distributor
102 const char* distributor = m_conf->getconf("distributor", "nodename");
103 RFNSM_Status::Instance().set_flag(0);
104 // b2nsm_sendreq(distributor, "RF_CONFIGURE", 0, pars);
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");
108
109 sleep(2);
110
111 // 2. Configure event processors
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");
116
117 char hostnode[512], idname[3];
118 int nnodes = 0;
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);
125 // b2nsm_sendreq(hostnode, "RF_CONFIGURE", 0, pars);
126 b2nsm_sendreq(hostnode, "RC_LOAD", 0, pars);
127 nnodes++;
128 }
129 }
130 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
131
132 sleep(10);
133
134 // 3. Configure event sampler
135 const char* sampler = m_conf->getconf("eventsampler", "nodename");
136 RFNSM_Status::Instance().set_flag(0);
137 // b2nsm_sendreq(distributor, "RF_CONFIGURE", 0, pars);
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");
141
142 sleep(2);
143
144
145 printf("ERecoMaster:: event processors configured\n");
146
147 return 0;
148}

◆ 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 65 of file ERecoMaster.cc.

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

◆ Log_Handler()

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

Definition at line 78 of file ERecoMaster.cc.

79{
80 // printf ( "ERecoMaster : [INFO] received\n" );
81 // b2nsm_ok ( msg, "INFO!!", NULL );
82 // fflush ( stdout );
83}

◆ monitor_loop()

void monitor_loop ( )
static

Definition at line 292 of file ERecoMaster.cc.

293{
294 while (true) {
295 b2nsm_wait(10);
296 }
297}

◆ 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 253 of file ERecoMaster.cc.

254{
255 int* pars = nullptr;
256
257 // 0. Configure DqmServer
258 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
259 // b2nsm_sendreq(dqmserver, "RF_RESTART", 0, pars);
260 b2nsm_sendreq(dqmserver, "RC_RECOVER", 0, pars);
261 sleep(2);
262
263 // 1. Configure distributor
264 const char* distributor = m_conf->getconf("distributor", "nodename");
265 // b2nsm_sendreq(distributor, "RF_RESTART", 0, pars);
266 b2nsm_sendreq(distributor, "RC_RECOVER", 0, pars);
267 sleep(2);
268
269 // 2. Configure event processors
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");
274
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);
281 // b2nsm_sendreq(hostnode, "RF_RESTART", 0, pars);
282 b2nsm_sendreq(hostnode, "RC_RECOVER", 0, pars);
283 }
284 }
285 sleep(2);
286
287 return 0;
288}

◆ 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()

virtual int Start ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 26 of file RFServerBase.h.

26{ return 0; };

◆ 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 209 of file ERecoMaster.cc.

210{
211 int pars[10];
212 pars[0] = msg->pars[0];
213 pars[1] = msg->pars[1];
214
215 // 1. Stop worker nodes
216 // Unconfigure event processors
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");
221
222 char hostnode[512], idname[3];
223 RFNSM_Status::Instance().set_flag(0);
224 int nnodes = 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);
230 // b2nsm_sendreq(hostnode, "RF_STOP", 0, pars);
231 b2nsm_sendreq(hostnode, "RC_STOP", 0, pars);
232 nnodes++;
233 }
234 }
235#ifdef DESY
236 b2nsm_wait(5);
237#else
238 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
239#endif
240
241 // 2. Stop DqmServer node
242 // Unconfigure DqmServer
243 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
244 RFNSM_Status::Instance().set_flag(0);
245 // b2nsm_sendreq(dqmserver, "RF_STOP", 0, pars);
246 b2nsm_sendreq(dqmserver, "RC_STOP", 0, pars);
247 while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
248
249 return 0;
250}

◆ UnConfigure()

int UnConfigure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 150 of file ERecoMaster.cc.

151{
152 int* pars = nullptr;
153
154 // Unconfigure sampler
155 const char* sampler = m_conf->getconf("eventsampler", "nodename");
156 RFNSM_Status::Instance().set_flag(0);
157 // b2nsm_sendreq(distributor, "RF_UNCONFIGURE", 0, pars);
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");
161
162 // Unconfigure event processors
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");
167
168 char hostnode[512], idname[3];
169 RFNSM_Status::Instance().set_flag(0);
170 int nnodes = 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);
176 // b2nsm_sendreq(hostnode, "RF_UNCONFIGURE", 0, pars);
177 b2nsm_sendreq(hostnode, "RC_ABORT", 0, pars);
178 nnodes++;
179 }
180 }
181#ifdef DESY
182 b2nsm_wait(5);
183#else
184 while (RFNSM_Status::Instance().get_flag() != nnodes) b2nsm_wait(1);
185#endif
186 printf("ERecoMaster: eventprocessors unconfigured.\n");
187
188 // Unconfigure distributor
189 const char* distributor = m_conf->getconf("distributor", "nodename");
190 RFNSM_Status::Instance().set_flag(0);
191 // b2nsm_sendreq(distributor, "RF_UNCONFIGURE", 0, pars);
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");
195
196 // Unconfigure DqmServer
197 const char* dqmserver = m_conf->getconf("dqmserver", "nodename");
198 RFNSM_Status::Instance().set_flag(0);
199 // b2nsm_sendreq(dqmserver, "RF_UNCONFIGURE", 0, pars);
200 b2nsm_sendreq(dqmserver, "RC_ABORT", 0, pars);
201 // while (RFNSM_Status::Instance().get_flag() == 0) b2nsm_wait(1);
202 sleep(5);
203 printf("ErecoMaster: dqmserver unconfigured.\n");
204
205 return 0;
206
207}

Member Data Documentation

◆ m_conf

RFConf* m_conf
private

Definition at line 49 of file ERecoMaster.h.

◆ m_log

RFLogManager* m_log
private

Definition at line 51 of file ERecoMaster.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: