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

Public Member Functions

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

static RFServerBase * s_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 [MAXNODES] = {}
 
int m_pid_sender [MAXNODES] = {}
 
int m_nnodes = 0
 
int m_nrecv = 0
 
RfNodeInfo * m_nsmmem = nullptr
 

Detailed Description

Definition at line 29 of file ERecoDistributor.h.

Constructor & Destructor Documentation

◆ ERecoDistributor()

ERecoDistributor ( const std::string & conffile)
explicit

Definition at line 25 of file ERecoDistributor.cc.

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

◆ ~ERecoDistributor()

Definition at line 62 of file ERecoDistributor.cc.

63{
64 delete m_log;
65 delete m_proc;
66 delete m_shm;
67 delete m_conf;
68 delete m_flow;
69 delete m_rbufin;
70}

Member Function Documentation

◆ Configure()

int Configure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 75 of file ERecoDistributor.cc.

76{
77 // 0. Global parameters
78 // char* ringbuf = m_conf->getconf("distributor", "ringbuffer");
79 string ringbuf = string(m_conf->getconf("system", "unitname")) + ":" +
80 string(m_conf->getconf("distributor", "ringbuffer"));
81
82 // char* shmname = m_conf->getconf("distributor", "nodename");
83 string shmname = string(m_conf->getconf("system", "unitname")) + ":" +
84 string(m_conf->getconf("distributor", "nodename"));
85
86 // 1. Run sender
87 m_nnodes = 0;
88 int maxnodes = m_conf->getconfi("processor", "nnodes");
89 int idbase = m_conf->getconfi("processor", "idbase");
90 //char* hostbase = m_conf->getconf("processor", "hostbase");
91 char* badlist = m_conf->getconf("processor", "badlist");
92
93 char* sender = m_conf->getconf("distributor", "sender", "script");
94 int portbase = m_conf->getconfi("distributor", "sender", "portbase");
95
96
97 char hostname[512], idname[12], shmid[12];
98 for (int i = 0; i < maxnodes; i++) {
99 snprintf(idname, sizeof(idname), "%2.2d", idbase + i);
100 snprintf(shmid, sizeof(shmid), "%2.2d", i);
101 if (badlist == NULL ||
102 strstr(badlist, idname) == 0) {
103 int port = (idbase + i) + portbase;
104 char portchar[256];
105 sprintf(portchar, "%d", port);
106 m_pid_sender[m_nnodes] = m_proc->Execute(sender, const_cast<char*>(ringbuf.c_str()), portchar, const_cast<char*>(shmname.c_str()),
107 shmid);
108 printf("Running sender to %d\n", port);
109 fflush(stdout);
110 m_nnodes++;
111 }
112 }
113
114 // 2. Run receiver
115 m_nrecv = 0;
116 int maxrecv = m_conf->getconfi("distributor", "receiver", "nnodes");
117 int ridbase = m_conf->getconfi("distributor", "receiver", "idbase");
118 const char* rhostbase = m_conf->getconf("distributor", "receiver", "hostbase");
119 char* rbadlist = m_conf->getconf("distributor", "receiver", "badlist");
120 char* port = m_conf->getconf("distributor", "receiver", "port");
121 char* receiver = m_conf->getconf("distributor", "receiver", "script");
122
123 // char hostname[512], idname[12], shmid[12];
124 for (int i = 0; i < maxrecv; i++) {
125 sprintf(hostname, "%s%2.2d", rhostbase, ridbase + i);
126 snprintf(idname, sizeof(idname), "%2.2d", ridbase + i);
127 snprintf(shmid, sizeof(shmid), "%2.2d", i + 20);
128 if (rbadlist == NULL ||
129 strstr(rbadlist, hostname) == 0) {
130 printf("Running receiver for %s\n", hostname);
131 fflush(stdout);
132 m_pid_recv[m_nrecv] = m_proc->Execute(receiver, const_cast<char*>(ringbuf.c_str()), hostname, port,
133 const_cast<char*>(shmname.c_str()), shmid);
134 m_nrecv++;
135 }
136 }
137
138 printf("ERecoDistributor : Configure done\n");
139 return 0;
140}

◆ GetNodeInfo()

virtual RfNodeInfo * GetNodeInfo ( )
inlinevirtualinherited

Definition at line 38 of file RFServerBase.h.

39 {
40 return m_nsmmem;
41 };

◆ 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 182 of file ERecoDistributor.cc.

183{
184 printf("ERecoDistributor : Restarting!!!!!\n");
185 NSMmsg* nsmmsg = NULL;
186 NSMcontext* nsmcontext = NULL;
187 ERecoDistributor::UnConfigure(nsmmsg, nsmcontext);
188 sleep(2);
189 ERecoDistributor::Configure(nsmmsg, nsmcontext);
190 return 0;
191}

◆ Resume()

virtual int Resume ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 29 of file RFServerBase.h.

29{ return 0; };

◆ server()

void server ( )

Definition at line 195 of file ERecoDistributor.cc.

196{
197 // int nevt = 0;
198 m_flow->fillProcessStatus(GetNodeInfo());
199
200 while (true) {
201 pid_t pid = m_proc->CheckProcess();
202 if (pid > 0) {
203 printf("ERecoDistributor : process dead. pid = %d\n", pid);
204 for (int i = 0; i < m_nrecv; i++) {
205 if (pid == m_pid_recv[i]) {
206 m_log->Fatal("ERecoDistributor : receiver process (%d) dead. pid=%d\n", i, pid);
207 m_pid_recv[i] = 0;
208 }
209 }
210 for (int i = 0; i < m_nnodes; i++) {
211 if (pid == m_pid_sender[i]) {
212 m_log->Fatal("ERecoDistributor : sender process (%d) dead. pid=%d\n", i, m_pid_sender[i]);
213 m_pid_sender[i] = 0;
214 }
215 }
216 }
217
218 int st = m_proc->CheckOutput();
219 if (st < 0) {
220 perror("ERecoDistributor::server");
221 // exit ( -1 );
222 } else if (st > 0) {
223 m_log->ProcessLog(m_proc->GetFd());
224 }
225 }
226 // m_flow->fillNodeInfo(RF_INPUT_ID, GetNodeInfo(), false);
227 // m_flow->fillProcessStatus(GetNodeInfo(), m_pid_recv, m_pid_sender[sender_id]);
228 // m_flow->fillNodeInfo(0, GetNodeInfo(), false);
229 // Debug
230 // RfNodeInfo* info = GetNodeInfo();
231 //info->nevent_in = nevt++;
232 // info->nqueue_in = nevt;
233 // printf ( "FillNodeInfo called!! info->nevent_in = %d\n", info->nevent_in );
234}

◆ 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 175 of file ERecoDistributor.cc.

176{
177 m_rbufin->clear();
178 return 0;
179}

◆ Status()

virtual int Status ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 31 of file RFServerBase.h.

31{ return 0; };

◆ Stop()

virtual int Stop ( NSMmsg * ,
NSMcontext *  )
inlinevirtualinherited

Definition at line 27 of file RFServerBase.h.

27{ return 0; };

◆ UnConfigure()

int UnConfigure ( NSMmsg * ,
NSMcontext *  )
overridevirtual

Reimplemented from RFServerBase.

Definition at line 142 of file ERecoDistributor.cc.

143{
144 // system("killall sock2rbr rb2sockr");
145 int status;
146
147 printf("m_nrecv = %d\n", m_nrecv);
148 for (int i = 0; i < m_nrecv; i++) {
149 if (m_pid_recv[i] != 0) {
150 printf("ERecoDistributor : killing receiver pid=%d\n", m_pid_recv[i]);
151 kill(m_pid_recv[i], SIGKILL);
152 waitpid(m_pid_recv[i], &status, 0);
153 }
154 }
155
156 printf("m_nnodes = %d\n", m_nnodes);
157 for (int i = 0; i < m_nnodes; i++) {
158 if (m_pid_sender[i] != 0) {
159 printf("ERecoDistributor : killing sender pid=%d\n", m_pid_sender[i]);
160 // kill(m_pid_sender[i], SIGINT);
161 kill(m_pid_sender[i], SIGKILL);
162 waitpid(m_pid_sender[i], &status, 0);
163 }
164 }
165 // Clear RingBuffer
166 m_rbufin->forceClear();
167
168 // Clear process list
169 m_flow->fillProcessStatus(GetNodeInfo());
170
171 printf("ERecoDistributor : Unconfigure done\n");
172 return 0;
173}

Member Data Documentation

◆ m_conf

RFConf* m_conf
private

Definition at line 49 of file ERecoDistributor.h.

◆ m_flow

RFFlowStat* m_flow
private

Definition at line 53 of file ERecoDistributor.h.

◆ m_log

RFLogManager* m_log
private

Definition at line 52 of file ERecoDistributor.h.

◆ m_nnodes

int m_nnodes = 0
private

Definition at line 58 of file ERecoDistributor.h.

◆ m_nrecv

int m_nrecv = 0
private

Definition at line 59 of file ERecoDistributor.h.

◆ m_nsmmem

RfNodeInfo* m_nsmmem = nullptr
privateinherited

Definition at line 47 of file RFServerBase.h.

◆ m_pid_recv

int m_pid_recv[MAXNODES] = {}
private

Definition at line 56 of file ERecoDistributor.h.

56{};

◆ m_pid_sender

int m_pid_sender[MAXNODES] = {}
private

Definition at line 57 of file ERecoDistributor.h.

57{};

◆ m_proc

RFProcessManager* m_proc
private

Definition at line 51 of file ERecoDistributor.h.

◆ m_rbufin

RingBuffer* m_rbufin
private

Definition at line 54 of file ERecoDistributor.h.

◆ m_shm

RFSharedMem* m_shm
private

Definition at line 50 of file ERecoDistributor.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: