ATLAS Offline Software
Loading...
Searching...
No Matches
IPCMat.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <GaudiKernel/StatusCode.h>
6#include <GaudiKernel/IMessageSvc.h>
7#include <GaudiKernel/MsgStream.h>
9#include <cstring>
10
11namespace Trk {
12
13/*
14IPCMat::IPCMat()
15 : m_msgSvc(0),
16 m_ncalls(0),
17 m_msgid(0),
18 m_name("GlobAlign::IPCMat")
19{}
20*/
21
22IPCMat::IPCMat(IMessageSvc *msgSvc)
23 : m_msgSvc(msgSvc),
24 m_ncalls(0),
25 m_msgid(0),
26 m_name("GlobAlign::IPCMat"),
27 m_log(new MsgStream(msgSvc,name()))
28{
29}
30
31
32const std::string& IPCMat::name() const {
33 return m_name;
34}
35
36//=====================================================================
37// IncMat
38//=====================================================================
39StatusCode IPCMat::incMat(uint32_t a, uint32_t b, double c){
40 //MsgStream log(m_msgSvc,name());
41
42 m_ipcmat_msgp.mtype = M_INCR_M;
43 m_ipcmat_msgp.data.matrix.i = a;
44 m_ipcmat_msgp.data.matrix.j = b;
45 m_ipcmat_msgp.data.matrix.v = c;
46
47 if (msgsnd(m_msgid,&m_ipcmat_msgp, sizeof(long)+2*sizeof(uint32_t)+sizeof(double),0)<0) {
48 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__ << " Error number is " << errno << endmsg;
49 return StatusCode::FAILURE;
50 }
51
52 return StatusCode::SUCCESS;
53}
54
55//=====================================================================
56// incVec
57//=====================================================================
58StatusCode IPCMat::incVec(uint32_t a, double c){
59 //MsgStream log(m_msgSvc,name());
60
61 m_ipcmat_msgp.mtype = M_INCR_V;
62 m_ipcmat_msgp.data.matrix.i = a;
63 m_ipcmat_msgp.data.matrix.j = 0;
64 m_ipcmat_msgp.data.matrix.v = c;
65
66 if (m_log->level()>=MSG::DEBUG)
67 *m_log << MSG::DEBUG << "call number " << std::setw(8) << m_ncalls
68 << endmsg;
69
70 if (msgsnd(m_msgid,&m_ipcmat_msgp, sizeof(long)+2*sizeof(uint32_t)+sizeof(double),0)<0) {
71 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
72 << " Error number is " << errno << endmsg;
73 return StatusCode::FAILURE;
74 }
75
76 m_ncalls++;
77 return StatusCode::SUCCESS;
78}
79
80//=====================================================================
81// scaleMat
82//=====================================================================
83StatusCode IPCMat::scaleMat(int scale){
84 //MsgStream log(m_msgSvc,name());
85 if (m_log->level()>=MSG::INFO)
86 *m_log << MSG::INFO << "in ipcmat_scaleMat with scale=" << scale << endmsg;
87
89 m_ipcmat_msgp.data.scale = scale;
90
91 if (msgsnd(m_msgid,&m_ipcmat_msgp, sizeof(long)+sizeof(double),0)<0) {
92 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
93 << " Error number is " << errno << endmsg;
94 return StatusCode::FAILURE;
95 }
96
97 return StatusCode::SUCCESS;
98}
99
100//=====================================================================
101// scaleVec
102//=====================================================================
103StatusCode IPCMat::scaleVec(int scale){
104 //MsgStream log(m_msgSvc,name());
105 if (m_log->level()>=MSG::INFO)
106 *m_log << MSG::INFO << "in ipcmat_scaleVec with scale=" << scale << endmsg;
107
108 m_ipcmat_msgp.mtype = M_SCALE_V;
109 m_ipcmat_msgp.data.scale = scale;
110
111 if (msgsnd(m_msgid,&m_ipcmat_msgp, sizeof(long)+sizeof(double),0)<0) {
112 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__ << " Error number is " << errno << endmsg;
113 return StatusCode::FAILURE;
114 }
115
116 return StatusCode::SUCCESS;
117}
118
119//=====================================================================
120// reSize
121//=====================================================================
122StatusCode IPCMat::reSize(int newsize){
123 //MsgStream log(m_msgSvc,name());
124 if (m_log->level()>=MSG::INFO)
125 *m_log << MSG::INFO << "in ipcmat_resize" << endmsg;
126
127 m_ipcmat_msgp.mtype = M_RESIZE;
128 m_ipcmat_msgp.data.n = newsize;
129
130 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
131 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__ << " Error number is " << errno << endmsg;
132 return StatusCode::FAILURE;
133 }
134
135 return StatusCode::SUCCESS;
136}
137
138//=====================================================================
139// removeModule
140//=====================================================================
141StatusCode IPCMat::removeModule(int mod){
142 //MsgStream log(m_msgSvc,name());
143
145 m_ipcmat_msgp.data.n = mod;
146
147 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
148 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
149 << " Error number is " << errno << endmsg;
150 return StatusCode::FAILURE;
151 }
152
153 return StatusCode::SUCCESS;
154}
155
156//=====================================================================
157// removeAlignPar
158//=====================================================================
159StatusCode IPCMat::removeAlignPar(int alpar){
160 //MsgStream log(m_msgSvc,name());
161
163 m_ipcmat_msgp.data.n = alpar;
164
165 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
166 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
167 << " Error number is " << errno << endmsg;
168 return StatusCode::FAILURE;
169 }
170
171 return StatusCode::SUCCESS;
172}
173
174//=====================================================================
175// init
176//=====================================================================
177StatusCode IPCMat::init(void){
178 //MsgStream log(m_msgSvc,name());
179 if (m_log->level()>=MSG::INFO) {
180 *m_log << MSG::INFO; m_log->setColor(MSG::BLUE);
181 *m_log << "in IPCMat::ipcmat_init" << endmsg;
182 }
183
184 key_t key;
185
186 if ((key = ftok("/dev/null", 69)) == -1) {
187 *m_log << MSG::ERROR << "Unable to get key" << endmsg;
188 return StatusCode::FAILURE;
189 }
190 else{
191 if (m_log->level()>=MSG::INFO)
192 *m_log << MSG::INFO << "Got key " << key << endmsg;
193 }
194
195 // destroy message queue if existed
196 msgctl(m_msgid, IPC_RMID, nullptr);
197
198 m_msgid = msgget(key, IPC_CREAT | 0666);
199 if(m_msgid < 0) {
200 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__ << " key: " << key
201 << " Error number is " << errno << endmsg;
202 return StatusCode::FAILURE;
203 }else{
204 if (m_log->level()>=MSG::INFO)
205 *m_log << MSG::INFO << "m_msgid = " << m_msgid << endmsg;
206 }
207
208 // fork receiver
209 if ((m_ipcmat_pid = fork()) < 0) {
210 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__ << " key: " << key
211 << " Error number is " << errno << endmsg;
212 return StatusCode::FAILURE;
213 }
214 if (m_log->level()>=MSG::INFO)
215 *m_log << MSG::INFO << "ipcmat_pid = " << m_ipcmat_pid << endmsg;
216
217 if (m_ipcmat_pid == 0)
218 {
219 // ipcmatr compiled in 64 bits using same struct for message queue
220 // as declared in IPCMat.h. Must be in PATH
221 if (execlp("ipcmatr", "", NULL) < 0)
222 {
223 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__ << " key: " << key
224 << " Error number is " << errno << endmsg;
225 return StatusCode::FAILURE;
226 }
227 }
228
229 // let the children start
230 sleep(1);
231
232 return StatusCode::SUCCESS;
233}
234
235//=====================================================================
236// allocate
237//=====================================================================
238StatusCode IPCMat::allocate(int size){
239 //MsgStream log(m_msgSvc,name());
240 if (m_log->level()>=MSG::INFO) {
241 *m_log << MSG::INFO; m_log->setColor(MSG::BLUE);
242 *m_log << "in IPCMat::ipcmat_allocate" << endmsg;
243 }
244
246 m_ipcmat_msgp.data.n = size;
247
248 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
249 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
250 << " Error number is " << errno << endmsg;
251 return StatusCode::FAILURE;
252 }
253
254 return StatusCode::SUCCESS;
255}
256
257//=====================================================================
258// setScale
259//=====================================================================
260StatusCode IPCMat::setScale(int scale){
261 //MsgStream log(m_msgSvc,name());
262 if (m_log->level()>=MSG::INFO)
263 *m_log << MSG::INFO << "setting m_scale to : " << scale << endmsg;
264
266 m_ipcmat_msgp.data.scale = scale;
267
268 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
269 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
270 << " Error number is " << errno << endmsg;
271 return StatusCode::FAILURE;
272 }
273
274 return StatusCode::SUCCESS;
275}
276
277//=====================================================================
278// setVersion
279//=====================================================================
280StatusCode IPCMat::setVersion(float version, bool isMatrix){
281 //MsgStream log(m_msgSvc,name());
282
284 m_ipcmat_msgp.data.version = version;
285
286 std::string mType = isMatrix ? "MatVersion" : "VecVersion";
287 if (m_log->level()>=MSG::INFO)
288 *m_log << MSG::INFO << "setting " << mType << " to = " << version << endmsg;
289
290
291 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
292 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
293 << " Error number is " << errno << endmsg;
294 return StatusCode::FAILURE;
295 }
296
297 return StatusCode::SUCCESS;
298}
299
300//=====================================================================
301// write
302//=====================================================================
303StatusCode IPCMat::write(const std::string& ipcname, bool isMatrix){
304 //MsgStream log(m_msgSvc,name());
305 if (m_log->level()>=MSG::INFO)
306 *m_log << MSG::INFO << "Writting ipcmat. Selected name is : " << ipcname
307 << endmsg;
308
309 m_ipcmat_msgp.mtype = isMatrix ? M_WRITE_M : M_WRITE_V;
310 strncpy(m_ipcmat_msgp.data.fname, ipcname.c_str(), sizeof(m_ipcmat_msgp.data.fname)-1);
311 m_ipcmat_msgp.data.fname[sizeof(m_ipcmat_msgp.data.fname) - 1] = '\0';
312
313 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(m_ipcmat_msgp)-sizeof(long), IPC_NOWAIT) < 0) {
314 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
315 << " Error number is " << errno << endmsg;
316 return StatusCode::FAILURE;
317 }
318 return StatusCode::SUCCESS;
319}
320
321//=====================================================================
322// end
323//=====================================================================
324StatusCode IPCMat::end(){
325 //MsgStream log(m_msgSvc,name());
326
327 m_ipcmat_msgp.mtype = M_END;
328 if (msgsnd(m_msgid, &m_ipcmat_msgp, sizeof(long)+sizeof(uint32_t), IPC_NOWAIT) < 0) {
329 *m_log << MSG::ERROR << "ipcmats: line: " << __LINE__
330 << " Error number is " << errno << endmsg;
331 return StatusCode::FAILURE;
332 }
333
334 // let chid finish its jobs
335 wait4(m_ipcmat_pid, nullptr, 0, nullptr);
336 return StatusCode::SUCCESS;
337}
338
339//=====================================================================
340// summary
341//=====================================================================
343 //MsgStream log(m_msgSvc,name());
344
345 if (m_log->level()>=MSG::INFO) {
346 *m_log << MSG::INFO << "++++++++++++++++++++++++++++++++++++++++" << endmsg;
347 *m_log << MSG::INFO << " Total calls = " << m_ncalls << endmsg;
348 *m_log << MSG::INFO << "++++++++++++++++++++++++++++++++++++++++" << endmsg;
349 }
350}
351
352} // end namespace Trk
#define endmsg
#define M_RESIZE
Definition IPCMat.h:24
#define M_REMOVE_MOD
Definition IPCMat.h:25
#define M_INCR_V
Definition IPCMat.h:19
#define M_SETVERSION
Definition IPCMat.h:28
#define M_ALLOCATE
Definition IPCMat.h:17
#define M_WRITE_M
Definition IPCMat.h:22
#define M_REMOVE_PAR
Definition IPCMat.h:26
#define M_WRITE_V
Definition IPCMat.h:23
#define M_SETSCALE
Definition IPCMat.h:27
#define M_SCALE_V
Definition IPCMat.h:21
#define M_INCR_M
Definition IPCMat.h:18
#define M_END
Definition IPCMat.h:29
#define M_SCALE_M
Definition IPCMat.h:20
static Double_t a
StatusCode removeModule(int)
Definition IPCMat.cxx:141
StatusCode reSize(int)
Definition IPCMat.cxx:122
const std::string & name() const
Definition IPCMat.cxx:32
StatusCode allocate(int)
Definition IPCMat.cxx:238
StatusCode incVec(uint32_t, double)
Definition IPCMat.cxx:58
std::string m_name
Definition IPCMat.h:72
struct Trk::IPCMat::MsgBuf m_ipcmat_msgp
StatusCode incMat(uint32_t, uint32_t, double)
Definition IPCMat.cxx:39
StatusCode setScale(int)
Definition IPCMat.cxx:260
MsgStream * m_log
Definition IPCMat.h:73
StatusCode setVersion(float, bool)
Definition IPCMat.cxx:280
StatusCode scaleVec(int)
Definition IPCMat.cxx:103
StatusCode end()
Definition IPCMat.cxx:324
int m_msgid
Definition IPCMat.h:71
StatusCode removeAlignPar(int)
Definition IPCMat.cxx:159
pid_t m_ipcmat_pid
Definition IPCMat.h:74
void summary()
Definition IPCMat.cxx:342
StatusCode write(const std::string &, bool)
Definition IPCMat.cxx:303
int m_ncalls
Definition IPCMat.h:70
IMessageSvc * m_msgSvc
Definition IPCMat.h:69
StatusCode scaleMat(int)
Definition IPCMat.cxx:83
StatusCode init(void)
Definition IPCMat.cxx:177
Ensure that the ATLAS eigen extensions are properly loaded.