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

Public Member Functions

 RFEventServer (const std::string &conffile)
 
 RFEventServer (const RFEventServer &)=delete
 Copy constructor (disabled).
 
RFEventServer & operator= (const RFEventServer &)=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
 
void server ()
 
void cleanup ()
 
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 RFEventServer & Create (const std::string &conffile)
 
static RFEventServer & Instance ()
 

Private Attributes

RFConf * m_conf
 
RFSharedMem * m_shm
 
RFProcessManager * m_proc
 
RFLogManager * m_log
 
RFFlowStat * m_flow
 
RingBuffer * m_rbufin
 
int m_pid_recv
 
int m_pid_sender [MAXNODES]
 
int m_nnodes = 0
 
RfNodeInfo * m_nsmmem = nullptr
 

Static Private Attributes

static RFEventServer * s_instance = 0
 

Detailed Description

Definition at line 29 of file RFEventServer.h.

Constructor & Destructor Documentation

◆ RFEventServer()

RFEventServer ( const std::string & conffile)
explicit

Definition at line 28 of file RFEventServer.cc.

29{
30 // 0. Initialize configuration manager
31 m_conf = new RFConf(conffile.c_str());
32 char* nodename = m_conf->getconf("distributor", "nodename");
33 // char nodename[256];
34 // gethostname ( nodename, sizeof(nodename) );
35
36 // 1. Set execution directory
37 string execdir = string(m_conf->getconf("system", "execdir_base")) + "/distributor";
38
39 mkdir(execdir.c_str(), 0755);
40 chdir(execdir.c_str());
41
42 // 2. Initialize local shared memory
43 string shmname = string(m_conf->getconf("system", "unitname")) + ":" +
44 string(m_conf->getconf("distributor", "nodename"));
45 m_shm = new RFSharedMem(const_cast<char*>(shmname.c_str()));
46
47 // 3. Initialize process manager
48 m_proc = new RFProcessManager(nodename);
49
50 // 4. Initialize RingBuffers
51 // char* ringbuf = m_conf->getconf("distributor", "ringbuffer");
52 string ringbuf = string(m_conf->getconf("system", "unitname")) + ":" +
53 string(m_conf->getconf("distributor", "ringbuffer"));
54 int rbufsize = m_conf->getconfi("distributor", "ringbuffersize");
55 m_rbufin = new RingBuffer(ringbuf.c_str(), rbufsize);
56
57 // 5. Initialize LogManager
58 m_log = new RFLogManager(nodename, m_conf->getconf("system", "lognode"));
59
60 // 6. Initialize data flow monitor
61 m_flow = new RFFlowStat(const_cast<char*>(shmname.c_str()));
62
63 // 7. Clear PID list
64 m_pid_recv = 0;
65 for (int i = 0; i < m_nnodes; i++)
66 m_pid_sender[i] = 0 ;
67
68}

◆ ~RFEventServer()

Definition at line 70 of file RFEventServer.cc.

71{
72 delete m_log;
73 delete m_proc;
74 delete m_shm;
75 delete m_conf;
76 delete m_flow;
77 delete m_rbufin;
78}

Member Function Documentation

◆ cleanup()

void cleanup ( )

Definition at line 269 of file RFEventServer.cc.

270{
271 printf("RFEventServer : cleaning up\n");
272 UnConfigure(NULL, NULL);
273 /*
274 kill ( m_pid_recv, SIGINT );
275 int status;
276 waitpid ( m_pid_recv, &status, 0 );
277 printf ( "RFEventServer : receiver terminated.\n" );
278 for ( int i=0; i<m_nnodes; i++ ) {
279 kill ( m_pid_sender[i], SIGINT );
280 waitpid ( m_pid_sender[i], &status, 0 );
281 printf ( "RFEventServer : sender [%d] terminated.\n", i );
282 }
283 */
284 printf("RFEventServer: Done. Exitting\n");
285 exit(-1);
286}

◆ Configure()

int Configure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 97 of file RFEventServer.cc.

98{
99 // 0. Global parameters
100 // char* ringbuf = m_conf->getconf("distributor", "ringbuffer");
101 string ringbuf = string(m_conf->getconf("system", "unitname")) + ":" +
102 string(m_conf->getconf("distributor", "ringbuffer"));
103
104 // char* shmname = m_conf->getconf("distributor", "nodename");
105 string shmname = string(m_conf->getconf("system", "unitname")) + ":" +
106 string(m_conf->getconf("distributor", "nodename"));
107
108 // 2. Run sender
109 m_nnodes = 0;
110 int maxnodes = m_conf->getconfi("processor", "nnodes");
111 int idbase = m_conf->getconfi("processor", "idbase");
112 // char* hostbase = m_conf->getconf("processor", "hostbase");
113 char* badlist = m_conf->getconf("processor", "badlist");
114
115 char* sender = m_conf->getconf("distributor", "sender", "script");
116 int portbase = m_conf->getconfi("distributor", "sender", "portbase");
117
118 char idname[12], shmid[12];
119 for (int i = 0; i < maxnodes; i++) {
120 snprintf(idname, sizeof(idname), "%2.2d", idbase + i);
121 snprintf(shmid, sizeof(shmid), "%2.2d", i);
122 if (badlist == NULL ||
123 strstr(badlist, idname) == 0) {
124 int port = (idbase + i) + portbase;
125 char portchar[256];
126 sprintf(portchar, "%d", port);
127 m_pid_sender[m_nnodes] = m_proc->Execute(sender, const_cast<char*>(ringbuf.c_str()), portchar, const_cast<char*>(shmname.c_str()),
128 shmid);
129 m_flow->clear(i);
130 m_nnodes++;
131 }
132 }
133
134 // 1. Run receiver
135 char* srcG = m_conf->getconf("distributor", "source");
136 if (strstr(srcG, "net") != 0) {
137 // Run receiver
138 char* receiver = m_conf->getconf("distributor", "receiver", "script");
139 char* src = m_conf->getconf("distributor", "receiver", "host");
140 char* port = m_conf->getconf("distributor", "receiver", "port");
141 // char* ringbuf = m_conf->getconf("distributor", "ringbuffer");
142 char idbuf[3];
143 sprintf(idbuf, "%2.2d", RF_INPUT_ID);
144 m_pid_recv = m_proc->Execute(receiver, const_cast<char*>(ringbuf.c_str()), src, port, const_cast<char*>(shmname.c_str()), idbuf);
145 m_flow->clear(RF_INPUT_ID);
146 } else if (strstr(srcG, "file") != 0) {
147 // Run file reader
148 char* filein = m_conf->getconf("distributor", "fileinput", "script");
149 char* file = m_conf->getconf("distributor", "fileinput", "filename");
150 // char* ringbuf = m_conf->getconf("distributor", "ringbuffer");
151 char* nnodechr = m_conf->getconf("distributor", "nnodes");
152 m_pid_recv = m_proc->Execute(filein, const_cast<char*>(ringbuf.c_str()), file, nnodechr);
153 }
154
155 m_rbufin->forceClear();
156
157 // else none
158 return 0;
159}

◆ Create()

RFEventServer & Create ( const std::string & conffile)
static

Definition at line 81 of file RFEventServer.cc.

82{
83 if (!s_instance) {
84 s_instance = new RFEventServer(conffile);
85 }
86 return *s_instance;
87}

◆ GetNodeInfo()

virtual RfNodeInfo * GetNodeInfo ( )
inlinevirtualinherited

Definition at line 38 of file RFServerBase.h.

39 {
40 return m_nsmmem;
41 };

◆ Instance()

RFEventServer & Instance ( )
static

Definition at line 89 of file RFEventServer.cc.

90{
91 return *s_instance;
92}

◆ 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 201 of file RFEventServer.cc.

202{
203 printf("RFEventServer : Restarting!!!!!\n");
204 /* Original impl.
205 if (m_pid_recv != 0) {
206 kill(m_pid_recv, SIGINT);
207 }
208 for (int i = 0; i < m_nnodes; i++) {
209 if (m_pid_sender[i] != 0) {
210 printf("RFEventServer:: killing sender pid=%d\n", m_pid_sender[i]);
211 kill(m_pid_sender[i], SIGINT);
212 }
213 }
214 // Simple implementation
215 system("killall sock2rbr rb2sockr");
216 fflush(stdout);
217 */
218 NSMmsg* nsmmsg = NULL;
219 NSMcontext* nsmcontext = NULL;
220 RFEventServer::UnConfigure(nsmmsg, nsmcontext);
221 sleep(2);
222 RFEventServer::Configure(nsmmsg, nsmcontext);
223 return 0;
224}

◆ Resume()

virtual int Resume ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 29 of file RFServerBase.h.

29{ return 0; };

◆ server()

void server ( )

Definition at line 228 of file RFEventServer.cc.

229{
230 // int nevt = 0;
231 m_flow->fillProcessStatus(GetNodeInfo());
232
233 while (true) {
234 int sender_id = 0;
235 pid_t pid = m_proc->CheckProcess();
236 if (pid > 0) {
237 printf("RFEventServer : process dead. pid = %d\n", pid);
238 if (pid == m_pid_recv) {
239 m_log->Fatal("RFEventServer : receiver process dead. pid=%d\n", pid);
240 m_pid_recv = 0;
241 } else {
242 for (int i = 0; i < m_nnodes; i++) {
243 if (pid == m_pid_sender[i]) {
244 m_log->Fatal("RFEventServer : sender process (%d) dead. pid=%d\n", i, m_pid_sender[i]);
245 m_pid_sender[i] = 0;
246 sender_id = i;
247 }
248 }
249 }
250 }
251 int st = m_proc->CheckOutput();
252 if (st < 0) {
253 perror("RFEventServer::server");
254 // exit ( -1 );
255 } else if (st > 0) {
256 m_log->ProcessLog(m_proc->GetFd());
257 }
258 m_flow->fillNodeInfo(RF_INPUT_ID, GetNodeInfo(), false);
259 m_flow->fillProcessStatus(GetNodeInfo(), m_pid_recv, m_pid_sender[sender_id]);
260 // m_flow->fillNodeInfo(0, GetNodeInfo(), false);
261 // Debug
262 // RfNodeInfo* info = GetNodeInfo();
263 //info->nevent_in = nevt++;
264 // info->nqueue_in = nevt;
265 // printf ( "FillNodeInfo called!! info->nevent_in = %d\n", info->nevent_in );
266 }
267}

◆ 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 * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 187 of file RFEventServer.cc.

188{
189 // m_rbufin->clear();
190 // m_rbufin->forceClear();
191 return 0;
192}

◆ Status()

virtual int Status ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 31 of file RFServerBase.h.

31{ return 0; };

◆ Stop()

int Stop ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 194 of file RFEventServer.cc.

195{
196 m_rbufin->clear();
197 return 0;
198}

◆ UnConfigure()

int UnConfigure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 161 of file RFEventServer.cc.

162{
163 // system("killall sock2rbr rb2sockr");
164 int status;
165 if (m_pid_recv != 0) {
166 kill(m_pid_recv, SIGINT);
167 waitpid(m_pid_recv, &status, 0);
168 }
169 for (int i = 0; i < m_nnodes; i++) {
170 if (m_pid_sender[i] != 0) {
171 printf("RFEventServer:: killing sender pid=%d\n", m_pid_sender[i]);
172 // kill(m_pid_sender[i], SIGINT);
173 kill(m_pid_sender[i], SIGINT);
174 waitpid(m_pid_sender[i], &status, 0);
175 }
176 }
177 // Clear RingBuffer
178 m_rbufin->forceClear();
179
180 // Clear process list
181 m_flow->fillProcessStatus(GetNodeInfo());
182
183 printf("Unconfigure : done\n");
184 return 0;
185}

Member Data Documentation

◆ m_conf

RFConf* m_conf
private

Definition at line 57 of file RFEventServer.h.

◆ m_flow

RFFlowStat* m_flow
private

Definition at line 61 of file RFEventServer.h.

◆ m_log

RFLogManager* m_log
private

Definition at line 60 of file RFEventServer.h.

◆ m_nnodes

int m_nnodes = 0
private

Definition at line 66 of file RFEventServer.h.

◆ m_nsmmem

RfNodeInfo* m_nsmmem = nullptr
privateinherited

Definition at line 47 of file RFServerBase.h.

◆ m_pid_recv

int m_pid_recv
private

Definition at line 64 of file RFEventServer.h.

◆ m_pid_sender

int m_pid_sender[MAXNODES]
private

Definition at line 65 of file RFEventServer.h.

◆ m_proc

RFProcessManager* m_proc
private

Definition at line 59 of file RFEventServer.h.

◆ m_rbufin

RingBuffer* m_rbufin
private

Definition at line 62 of file RFEventServer.h.

◆ m_shm

RFSharedMem* m_shm
private

Definition at line 58 of file RFEventServer.h.

◆ s_instance

RFEventServer * s_instance = 0
staticprivate

Definition at line 70 of file RFEventServer.h.


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