Belle II Software development
RawHeader_latest.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#ifndef RAWHEADER_LATEST_H
10#define RAWHEADER_LATEST_H
11
12#include <stdio.h>
13#include <string.h>
14#include <rawdata/switch_basf2_standalone.h>
15
16
17//#define HEADER_SIZE 16
18
19namespace Belle2 {
31 // class RawHeader_latest : public TObject {
33 public:
36
38 explicit RawHeader_latest(int*);
39
42
44 int* GetBuffer() { return m_buffer; }
45
47 void SetBuffer(int* bufin) { m_buffer = bufin; }
48
50 void CheckSetBuffer();
51
53 void CheckGetBuffer();
54
56 void SetNwords(int nwords);
57
59 void SetEveNo(unsigned int eve_no);
60
62 void SetNodeID(unsigned int node_id);
63
65 void SetDataType(int data_type);
66
68 void SetTruncMask(int trunc_mask);
69
70 // void SetB2LFEEHdrPart(unsigned int word1, unsigned int word2); //! set contents of header
71 // void SetFTSW2Words(int* ftsw_buf);
72
74 void SetFTSW2Words(unsigned int word1, unsigned int word2);
75
77 void SetExpRunNumber(int* exprun_buf);
78
80 void SetOffset1stFINESSE(int offset_1st_FINESSE);
81
82 void SetOffset2ndFINESSE(int offset_2nd_FINESSE);
83
84 void SetOffset3rdFINESSE(int offset_3rd_FINESSE);
85
86 void SetOffset4thFINESSE(int offset_4th_FINESSE);
87
88 // void SetMagicWordEntireHeader(); //! set magic words;
89
91 // int AddNodeInfo(int node_id);
92
93 int GetNwords();
94
95 int GetHdrNwords();
96
97 unsigned int GetExpRunSubrun();
98
99 int GetExpNo();
100
101 int GetRunNo();
102
103 int GetSubRunNo();
104
105 unsigned int GetEveNo();
106
107 unsigned int GetNodeID();
108
109 int GetDataType();
110
111 int GetTruncMask();
112
114 unsigned int GetErrorBitFlag();
115
117 void AddErrorBitFlag(unsigned int error_bit_flag);
118
120 int GetPacketCRCError();
121
123 int GetEventCRCError();
124
127
130
133
136
137 // int GetNumNodes(); //! get contents of header
138
139 // int GetNodeInfo(int node_no, int* node_id); //! get contents of header
140
142 unsigned int GetTTCtimeTRGType();
143
145 int GetTTCtime();
146
148 int GetTRGType();
149
151 unsigned int GetTTUtime();
152
154 void GetTTTimeVal(struct timeval* tv);
155
157 // unsigned int GetMagicWordEntireHeader();
158
160 void CheckHeader(int* buf);
161
162 /*
163 Experimental(10bit) #, Run#(14bit), restat# bit mask(8bit)
164 */
165 enum {
166 MAGIC_WORD = 0x7F7F0000,
167 MAGIC_MASK = 0xFFFF0000,
168 MAGIC_SHIFT = 16,
169 FORMAT_VERSION__MASK = 0x0000FF00,
170 FORMAT_VERSION_SHIFT = 8
171 };
172
173 enum {
174 EXP_MASK = 0xFFC00000,
175 EXP_SHIFT = 22,
176 RUNNO_MASK = 0x003FFF00,
177 RUNNO_SHIFT = 8,
178 SUBRUNNO_MASK = 0x000000FF
179 };
180
181 enum {
182 RAWHEADER_NWORDS = 56
183 };
184
185 enum {
186 HDR_NWORDS_MASK = 0x000000FF
187 };
188
189 /* Data Format : Fixed length part*/
190 enum {
191 POS_NWORDS = 0,
192 POS_VERSION_HDRNWORDS = 1,
193 POS_EXP_RUN_NO = 2,
194 POS_EVE_NO = 3,
195 POS_TTCTIME_TRGTYPE = 4,
196 POS_TTUTIME = 5,
197 POS_NODE_ID = 6,
198 POS_TRUNC_MASK_DATATYPE = 7,
199 POS_CH_POS_TABLE = 8
200 };
201
202
203 /* Data Format : Node info */
204 /* enum { */
205 /* NUM_MAX_NODES = 4 /\* (NUM_MAX_NODES + 1) slots are available in m_buffer. */
206 /* (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes */
207 /* exceeds NUM_MAX_NODES *\/ */
208 /* }; */
209
210 /* /\* Data Format : Magic word *\/ */
211 /* enum { */
212 /* MAGIC_WORD_TERM_HEADER = 0x7fff0005 */
213 /* }; */
214
215
216
217 /* To extract ctime */
218 enum {
219 TTCTIME_MASK = 0x7FFFFFF0,
220 TTCTIME_SHIFT = 4,
221 TRGTYPE_MASK = 0xF
222 };
223
224 /* Error bit in POS_TRUNC_MASK_DATATYPE */
225 /* Changed from the position of error bit to actual error value ( 0 -> 0x1, 1 -> 0x2 ) */
226 enum {
227 B2LINK_PACKET_CRC_ERROR = 0x1,
228 B2LINK_EVENT_CRC_ERROR = 0x2
229 };
230
231 private:
233 int* m_buffer;
234
236 // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
237 // ClassDef(RawHeader_latest, 1);
238 };
239
240
242 {
243 if (m_buffer == NULL) {
244 B2FATAL("m_buffer is NULL. Exiting...");
245 }
246 }
247
249 {
250 if (m_buffer == NULL) {
251 B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
252// } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) {
253// B2FATAL("magic word is invalid(0x"<< std::hex() << m_buffer[ POS_TERM_HEADER ] <<"). Data is corrupted or header info has not yet filled. Exiting...");
254 }
255 }
256
257
258 inline void RawHeader_latest::SetNwords(int nwords)
259 {
261 m_buffer[ POS_NWORDS ] = nwords;
262
263 }
264
265 inline void RawHeader_latest::SetEveNo(unsigned int eve_no)
266 {
268 m_buffer[ POS_EVE_NO ] = eve_no;
269 }
270
271 inline void RawHeader_latest::SetNodeID(unsigned int node_id)
272 {
274 m_buffer[ POS_NODE_ID ] = (int)node_id;
275 }
276
277 inline void RawHeader_latest::SetDataType(int data_type)
278 {
280 m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
281 (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
282 }
283
284 inline void RawHeader_latest::SetTruncMask(int trunc_mask)
285 {
287 /* cppcheck-suppress shiftTooManyBitsSigned */
288 m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
289 }
290
291 inline void RawHeader_latest::SetFTSW2Words(unsigned int word1,
292 unsigned int word2)
293 {
295 m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
296 m_buffer[ POS_TTUTIME ] = word2;
297 return;
298 }
299
300
301 inline void RawHeader_latest::SetExpRunNumber(int* exprun_buf)
302 {
304 memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
305 return;
306 }
307
308
309//
310// Obtain info
311//
312
314 {
316 return m_buffer[ POS_NWORDS ];
317 }
318
320 {
321
322 // CheckGetBuffer();
323 // return m_buffer[ POS_HDR_NWORDS ];
324 return RAWHEADER_NWORDS;
325 }
326
328 {
330 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
331 >> EXP_SHIFT);
332 }
333
334
336 {
338 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
339 >> RUNNO_SHIFT);
340 }
341
343 {
345 return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
346 }
347
349 {
351 return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
352 }
353
354
355 inline unsigned int RawHeader_latest::GetEveNo()
356 {
358 return m_buffer[ POS_EVE_NO ];
359 }
360
361 inline unsigned int RawHeader_latest::GetNodeID()
362 {
364 return (unsigned int)m_buffer[ POS_NODE_ID ];
365 }
366
368 {
370 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
371 }
372
374 {
376 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
377 }
378
380 {
382 return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
383 }
384
385 inline void RawHeader_latest::AddErrorBitFlag(unsigned int error_bit_flag)
386 {
388 m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
389 return;
390 }
391
393 {
395 unsigned int temp_err_flag = GetErrorBitFlag();
396 if ((temp_err_flag & B2LINK_PACKET_CRC_ERROR) == 0) {
397 return 0;
398 }
399 return 1;
400 }
401
403 {
405 unsigned int temp_err_flag = GetErrorBitFlag();
406 if ((temp_err_flag & B2LINK_EVENT_CRC_ERROR) == 0) {
407 return 0;
408 }
409 return 1;
410 }
411
412
413 /* inline int RawHeader_latest::GetNumNodes() */
414 /* { */
415 /* CheckGetBuffer(); */
416 /* return m_buffer[ POS_NUM_NODES ]; */
417 /* } */
418
420 {
422 return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
423 }
424
426 {
428 return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
429 }
430
432 {
434 return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
435 }
436
437 inline unsigned int RawHeader_latest::GetTTUtime()
438 {
440 return (unsigned int)(m_buffer[ POS_TTUTIME ]);
441 }
442
443 inline void RawHeader_latest::GetTTTimeVal(struct timeval* tv)
444 {
445 tv->tv_sec = GetTTUtime();
446 tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
447 return ;
448 }
449
450
451 /* inline unsigned int RawHeader_latest::GetMagicWordEntireHeader() */
452 /* { */
453 /* CheckGetBuffer(); */
454 /* return m_buffer[ POS_TERM_HEADER ]; */
455 /* } */
456
457
458
459
460
462}
463
464#endif
The Raw Header class ver.1 ( the latest version since May, 2014 ) This class defines the format of th...
int GetOffset1stFINESSE()
get contents of header
void SetOffset4thFINESSE(int offset_4th_FINESSE)
set contents of header
int * m_buffer
do not record buffer ( RawCOPPER includes buffer of RawHeader_latest and RawTrailer )
void SetOffset2ndFINESSE(int offset_2nd_FINESSE)
set contents of header
void SetBuffer(int *bufin)
set buffer
void CheckHeader(int *buf)
Get magic word to check the data corruption.
RawHeader_latest()
Default constructor.
void SetOffset1stFINESSE(int offset_1st_FINESSE)
set contents of header
int GetOffset4thFINESSE()
get contents of header
void SetOffset3rdFINESSE(int offset_3rd_FINESSE)
set contents of header
int * GetBuffer()
Get header contents.
int GetOffset2ndFINESSE()
get contents of header
int GetOffset3rdFINESSE()
get contents of header
int GetNwords()
set contents of header
void SetTruncMask(int trunc_mask)
set contents of header
unsigned int GetEveNo()
get restart #(8bit)
int GetPacketCRCError()
Get Packet CRC error flag.
void AddErrorBitFlag(unsigned int error_bit_flag)
Add Detected Error bitflag.
int GetTTCtime()
get contents of header
void GetTTTimeVal(struct timeval *tv)
get contents of header
void SetFTSW2Words(unsigned int word1, unsigned int word2)
Set values of FTSW info( trigger timing)
int GetSubRunNo()
get run # (14bit)
int GetHdrNwords()
get contents of header
int GetDataType()
get contents of header
void CheckSetBuffer()
initialize header
unsigned int GetTTUtime()
get contents of header
void CheckGetBuffer()
check if m_buffer exists
int GetTRGType()
get TRGType
void SetEveNo(unsigned int eve_no)
set contents of header
unsigned int GetNodeID()
get contents of header
void SetDataType(int data_type)
set contents of header
void SetNodeID(unsigned int node_id)
set contents of header
int GetRunNo()
get contents of header
void SetNwords(int nwords)
set contents of header
int GetTruncMask()
get contents of header
unsigned int GetErrorBitFlag()
get contents of header
int GetEventCRCError()
Get Detected Error bitflag.
unsigned int GetTTCtimeTRGType()
get contents of header
unsigned int GetExpRunSubrun()
get contents of header
void SetExpRunNumber(int *exprun_buf)
Set a word consists of exp #, run # and subrun #.
int GetExpNo()
get a run/exp number combined word
Abstract base class for different kinds of events.