ATLAS Offline Software
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 
11 namespace Trk {
12 
13 /*
14 IPCMat::IPCMat()
15  : m_msgSvc(0),
16  m_ncalls(0),
17  m_msgid(0),
18  m_name("GlobAlign::IPCMat")
19 {}
20 */
21 
22 IPCMat::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 
32 const std::string& IPCMat::name() const {
33  return m_name;
34 }
35 
36 //=====================================================================
37 // IncMat
38 //=====================================================================
40  //MsgStream log(m_msgSvc,name());
41 
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 //=====================================================================
59  //MsgStream log(m_msgSvc,name());
60 
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 //=====================================================================
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 
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 //=====================================================================
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 
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 //=====================================================================
123  //MsgStream log(m_msgSvc,name());
124  if (m_log->level()>=MSG::INFO)
125  *m_log << MSG::INFO << "in ipcmat_resize" << endmsg;
126 
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 //=====================================================================
142  //MsgStream log(m_msgSvc,name());
143 
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 //=====================================================================
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 //=====================================================================
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 //=====================================================================
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 
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 //=====================================================================
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 
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 //=====================================================================
280 StatusCode IPCMat::setVersion(float version, bool isMatrix){
281  //MsgStream log(m_msgSvc,name());
282 
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 //=====================================================================
303 StatusCode 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 //=====================================================================
325  //MsgStream log(m_msgSvc,name());
326 
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
Trk::IPCMat::end
StatusCode end()
Definition: IPCMat.cxx:324
M_SCALE_M
#define M_SCALE_M
Definition: IPCMat.h:20
Trk::IPCMat::setVersion
StatusCode setVersion(float, bool)
Definition: IPCMat.cxx:280
Trk::IPCMat::allocate
StatusCode allocate(int)
Definition: IPCMat.cxx:238
IPCMat.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
M_REMOVE_PAR
#define M_REMOVE_PAR
Definition: IPCMat.h:26
Trk::IPCMat::removeAlignPar
StatusCode removeAlignPar(int)
Definition: IPCMat.cxx:159
Trk::IPCMat::scaleMat
StatusCode scaleMat(int)
Definition: IPCMat.cxx:83
Trk::IPCMat::MsgBuf::fname
char fname[100]
Definition: IPCMat.h:81
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
M_INCR_M
#define M_INCR_M
Definition: IPCMat.h:18
Trk::IPCMat::MsgBuf::scale
double scale
Definition: IPCMat.h:83
M_WRITE_V
#define M_WRITE_V
Definition: IPCMat.h:23
Trk::IPCMat::m_log
MsgStream * m_log
Definition: IPCMat.h:73
Trk::IPCMat::init
StatusCode init(void)
Definition: IPCMat.cxx:177
M_SETVERSION
#define M_SETVERSION
Definition: IPCMat.h:28
M_REMOVE_MOD
#define M_REMOVE_MOD
Definition: IPCMat.h:25
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
Trk::IPCMat::m_ipcmat_msgp
struct Trk::IPCMat::MsgBuf m_ipcmat_msgp
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Trk::IPCMat::IPCMat
IPCMat()
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::IPCMat::MsgBuf::n
uint32_t n
Definition: IPCMat.h:82
Trk::IPCMat::incMat
StatusCode incMat(uint32_t, uint32_t, double)
Definition: IPCMat.cxx:39
Trk::IPCMat::m_ncalls
int m_ncalls
Definition: IPCMat.h:70
M_INCR_V
#define M_INCR_V
Definition: IPCMat.h:19
Trk::IPCMat::MsgBuf::matrix
struct Trk::IPCMat::MsgBuf::@229::@230 matrix
Trk::IPCMat::summary
void summary()
Definition: IPCMat.cxx:342
Trk::IPCMat::MsgBuf::data
union Trk::IPCMat::MsgBuf::@229 data
Trk::IPCMat::m_ipcmat_pid
pid_t m_ipcmat_pid
Definition: IPCMat.h:74
M_SCALE_V
#define M_SCALE_V
Definition: IPCMat.h:21
Trk::IPCMat::m_name
std::string m_name
Definition: IPCMat.h:72
Trk::IPCMat::setScale
StatusCode setScale(int)
Definition: IPCMat.cxx:260
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::IPCMat::MsgBuf::mtype
long mtype
Definition: IPCMat.h:77
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Trk::IPCMat::removeModule
StatusCode removeModule(int)
Definition: IPCMat.cxx:141
M_RESIZE
#define M_RESIZE
Definition: IPCMat.h:24
Trk::IPCMat::incVec
StatusCode incVec(uint32_t, double)
Definition: IPCMat.cxx:58
M_WRITE_M
#define M_WRITE_M
Definition: IPCMat.h:22
get_generator_info.version
version
Definition: get_generator_info.py:33
Trk::IPCMat::scaleVec
StatusCode scaleVec(int)
Definition: IPCMat.cxx:103
a
TList * a
Definition: liststreamerinfos.cxx:10
M_ALLOCATE
#define M_ALLOCATE
Definition: IPCMat.h:17
Trk::IPCMat::reSize
StatusCode reSize(int)
Definition: IPCMat.cxx:122
DEBUG
#define DEBUG
Definition: page_access.h:11
Trk::IPCMat::write
StatusCode write(const std::string &, bool)
Definition: IPCMat.cxx:303
M_SETSCALE
#define M_SETSCALE
Definition: IPCMat.h:27
Trk::IPCMat::name
const std::string & name() const
Definition: IPCMat.cxx:32
M_END
#define M_END
Definition: IPCMat.h:29
python.compressB64.c
def c
Definition: compressB64.py:93
Trk::IPCMat::m_msgid
int m_msgid
Definition: IPCMat.h:71
Trk::IPCMat::MsgBuf::version
float version
Definition: IPCMat.h:84
python.logger.BLUE
BLUE
Definition: DataQuality/DQUtils/python/logger.py:15
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37