Belle II Software development
RawHeader_v2.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_V2_H
10#define RAWHEADER_V2_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_v2 : public TObject {
33 public:
36
38 explicit RawHeader_v2(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 = 12
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_OFFSET_1ST_FINESSE = 8,
200 POS_OFFSET_2ND_FINESSE = 9,
201 POS_OFFSET_3RD_FINESSE = 10,
202 POS_OFFSET_4TH_FINESSE = 11,
203 };
204
205
206 /* Data Format : Node info */
207 /* enum { */
208 /* NUM_MAX_NODES = 4 /\* (NUM_MAX_NODES + 1) slots are available in m_buffer. */
209 /* (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes */
210 /* exceeds NUM_MAX_NODES *\/ */
211 /* }; */
212
213 /* /\* Data Format : Magic word *\/ */
214 /* enum { */
215 /* MAGIC_WORD_TERM_HEADER = 0x7fff0005 */
216 /* }; */
217
218
219
220 /* To extract ctime */
221 enum {
222 TTCTIME_MASK = 0x7FFFFFF0,
223 TTCTIME_SHIFT = 4,
224 TRGTYPE_MASK = 0xF
225 };
226
227 /* Error bit in POS_TRUNC_MASK_DATATYPE */
228 /* Changed from the position of error bit to actual error value ( 0 -> 0x1, 1 -> 0x2 ) */
229 enum {
230 B2LINK_PACKET_CRC_ERROR = 0x1,
231 B2LINK_EVENT_CRC_ERROR = 0x2
232 };
233
234 private:
236 int* m_buffer;
237
239 // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
240 // ClassDef(RawHeader_v2, 1);
241 };
242
243
245 {
246 if (m_buffer == NULL) {
247 B2FATAL("m_buffer is NULL. Exiting...");
248 }
249 }
250
252 {
253 if (m_buffer == NULL) {
254 B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
255// } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) {
256// B2FATAL("magic word is invalid(0x"<< std::hex() << m_buffer[ POS_TERM_HEADER ] <<"). Data is corrupted or header info has not yet filled. Exiting...");
257 }
258 }
259
260
261 inline void RawHeader_v2::SetNwords(int nwords)
262 {
264 m_buffer[ POS_NWORDS ] = nwords;
265
266 }
267
268 inline void RawHeader_v2::SetEveNo(unsigned int eve_no)
269 {
271 m_buffer[ POS_EVE_NO ] = eve_no;
272 }
273
274 inline void RawHeader_v2::SetNodeID(unsigned int node_id)
275 {
277 m_buffer[ POS_NODE_ID ] = (int)node_id;
278 }
279
280 inline void RawHeader_v2::SetDataType(int data_type)
281 {
283 m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
284 (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
285 }
286
287 inline void RawHeader_v2::SetTruncMask(int trunc_mask)
288 {
290 /* cppcheck-suppress shiftTooManyBitsSigned */
291 m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
292 }
293
294 /* inline void RawHeader_v2::SetB2LFEEHdrPart(unsigned int word1, unsigned int word2) */
295 /* { */
296 /* m_buffer[ POS_HSLB_1 ] = word1; */
297 /* m_buffer[ POS_HSLB_2 ] = word2; */
298 /* } */
299
300
301 inline void RawHeader_v2::SetOffset1stFINESSE(int offset_1st_FINESSE)
302 {
304 m_buffer[ POS_OFFSET_1ST_FINESSE ] = offset_1st_FINESSE;
305 }
306
307 inline void RawHeader_v2::SetOffset2ndFINESSE(int offset_2nd_FINESSE)
308 {
310 m_buffer[ POS_OFFSET_2ND_FINESSE ] = offset_2nd_FINESSE;
311 }
312
313 inline void RawHeader_v2::SetOffset3rdFINESSE(int offset_3rd_FINESSE)
314 {
316 m_buffer[ POS_OFFSET_3RD_FINESSE ] = offset_3rd_FINESSE;
317 }
318
319 inline void RawHeader_v2::SetOffset4thFINESSE(int offset_4th_FINESSE)
320 {
322 m_buffer[ POS_OFFSET_4TH_FINESSE ] = offset_4th_FINESSE;
323 }
324
325 /* inline void RawHeader_v2::SetFTSW2Words(int* ftsw_buf) */
326 /* { */
327 /* CheckSetBuffer(); */
328 /* memcpy(&(m_buffer[ POS_HSLB_1 ]), (char*)ftsw_buf, sizeof(int) * 2); */
329 /* return; */
330 /* } */
331
332 inline void RawHeader_v2::SetFTSW2Words(unsigned int word1,
333 unsigned int word2)
334 {
336 m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
337 m_buffer[ POS_TTUTIME ] = word2;
338 return;
339 }
340
341
342 inline void RawHeader_v2::SetExpRunNumber(int* exprun_buf)
343 {
345 memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
346 return;
347 }
348
349
350//
351// Obtain info
352//
353
355 {
357 return m_buffer[ POS_NWORDS ];
358 }
359
361 {
362
363 // CheckGetBuffer();
364 // return m_buffer[ POS_HDR_NWORDS ];
365 return RAWHEADER_NWORDS;
366 }
367
369 {
371 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
372 >> EXP_SHIFT);
373 }
374
375
377 {
379 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
380 >> RUNNO_SHIFT);
381 }
382
384 {
386 return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
387 }
388
389 inline unsigned int RawHeader_v2::GetExpRunSubrun()
390 {
392 return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
393 }
394
395
396 inline unsigned int RawHeader_v2::GetEveNo()
397 {
399 return m_buffer[ POS_EVE_NO ];
400 }
401
402 inline unsigned int RawHeader_v2::GetNodeID()
403 {
405 return (unsigned int)m_buffer[ POS_NODE_ID ];
406 }
407
409 {
411 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
412 }
413
415 {
417 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
418 }
419
420 inline unsigned int RawHeader_v2::GetErrorBitFlag()
421 {
423 return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
424 }
425
426 inline void RawHeader_v2::AddErrorBitFlag(unsigned int error_bit_flag)
427 {
429 m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
430 return;
431 }
432
434 {
436 unsigned int temp_err_flag = GetErrorBitFlag();
437 if ((temp_err_flag & B2LINK_PACKET_CRC_ERROR) == 0) {
438 return 0;
439 }
440 return 1;
441 }
442
444 {
446 unsigned int temp_err_flag = GetErrorBitFlag();
447 if ((temp_err_flag & B2LINK_EVENT_CRC_ERROR) == 0) {
448 return 0;
449 }
450 return 1;
451 }
452
454 {
456 return m_buffer[ POS_OFFSET_1ST_FINESSE ];
457 }
458
460 {
462 return m_buffer[ POS_OFFSET_2ND_FINESSE ];
463 }
464
466 {
468 return m_buffer[ POS_OFFSET_3RD_FINESSE ];
469 }
470
472 {
474 return m_buffer[ POS_OFFSET_4TH_FINESSE ];
475 }
476
477 /* inline int RawHeader_v2::GetNumNodes() */
478 /* { */
479 /* CheckGetBuffer(); */
480 /* return m_buffer[ POS_NUM_NODES ]; */
481 /* } */
482
484 {
486 return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
487 }
488
490 {
492 return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
493 }
494
496 {
498 return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
499 }
500
501 inline unsigned int RawHeader_v2::GetTTUtime()
502 {
504 return (unsigned int)(m_buffer[ POS_TTUTIME ]);
505 }
506
507 inline void RawHeader_v2::GetTTTimeVal(struct timeval* tv)
508 {
509 tv->tv_sec = GetTTUtime();
510 tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
511 return ;
512 }
513
514
515 /* inline unsigned int RawHeader_v2::GetMagicWordEntireHeader() */
516 /* { */
517 /* CheckGetBuffer(); */
518 /* return m_buffer[ POS_TERM_HEADER ]; */
519 /* } */
520
521
522
523
524
526}
527
528#endif
The Raw Header class ver.1 ( the latest version since May, 2014 ) This class defines the format of th...
Definition: RawHeader_v2.h:32
int * m_buffer
do not record buffer ( RawCOPPER includes buffer of RawHeader_v2 and RawTrailer )
Definition: RawHeader_v2.h:236
void SetBuffer(int *bufin)
set buffer
Definition: RawHeader_v2.h:47
void CheckHeader(int *buf)
Get magic word to check the data corruption.
Definition: RawHeader_v2.cc:61
RawHeader_v2()
Default constructor.
Definition: RawHeader_v2.cc:16
int * GetBuffer()
Get header contents.
Definition: RawHeader_v2.h:44
~RawHeader_v2()
Destructor.
Definition: RawHeader_v2.cc:28
int GetNwords()
set contents of header
Definition: RawHeader_v2.h:354
void SetTruncMask(int trunc_mask)
set contents of header
Definition: RawHeader_v2.h:287
unsigned int GetEveNo()
get restart #(8bit)
Definition: RawHeader_v2.h:396
int GetOffset1stFINESSE()
get contents of header
Definition: RawHeader_v2.h:453
int GetPacketCRCError()
Get Packet CRC error flag.
Definition: RawHeader_v2.h:433
void AddErrorBitFlag(unsigned int error_bit_flag)
Add Detected Error bitflag.
Definition: RawHeader_v2.h:426
int GetTTCtime()
get contents of header
Definition: RawHeader_v2.h:489
void SetOffset4thFINESSE(int offset_4th_FINESSE)
set contents of header
Definition: RawHeader_v2.h:319
void GetTTTimeVal(struct timeval *tv)
get contents of header
Definition: RawHeader_v2.h:507
void SetFTSW2Words(unsigned int word1, unsigned int word2)
Set values of FTSW info( trigger timing)
Definition: RawHeader_v2.h:332
int GetSubRunNo()
get run # (14bit)
Definition: RawHeader_v2.h:383
int GetHdrNwords()
get contents of header
Definition: RawHeader_v2.h:360
void SetOffset2ndFINESSE(int offset_2nd_FINESSE)
set contents of header
Definition: RawHeader_v2.h:307
int GetDataType()
get contents of header
Definition: RawHeader_v2.h:408
void CheckSetBuffer()
initialize header
Definition: RawHeader_v2.h:244
unsigned int GetTTUtime()
get contents of header
Definition: RawHeader_v2.h:501
void CheckGetBuffer()
check if m_buffer exists
Definition: RawHeader_v2.h:251
int GetTRGType()
get TRGType
Definition: RawHeader_v2.h:495
void SetEveNo(unsigned int eve_no)
set contents of header
Definition: RawHeader_v2.h:268
unsigned int GetNodeID()
get contents of header
Definition: RawHeader_v2.h:402
void SetDataType(int data_type)
set contents of header
Definition: RawHeader_v2.h:280
void SetNodeID(unsigned int node_id)
set contents of header
Definition: RawHeader_v2.h:274
int GetRunNo()
get contents of header
Definition: RawHeader_v2.h:376
void SetOffset1stFINESSE(int offset_1st_FINESSE)
set contents of header
Definition: RawHeader_v2.h:301
void SetNwords(int nwords)
set contents of header
Definition: RawHeader_v2.h:261
int GetTruncMask()
get contents of header
Definition: RawHeader_v2.h:414
int GetOffset4thFINESSE()
get contents of header
Definition: RawHeader_v2.h:471
unsigned int GetErrorBitFlag()
get contents of header
Definition: RawHeader_v2.h:420
int GetEventCRCError()
Get Detected Error bitflag.
Definition: RawHeader_v2.h:443
void SetOffset3rdFINESSE(int offset_3rd_FINESSE)
set contents of header
Definition: RawHeader_v2.h:313
unsigned int GetTTCtimeTRGType()
get contents of header
Definition: RawHeader_v2.h:483
unsigned int GetExpRunSubrun()
get contents of header
Definition: RawHeader_v2.h:389
void SetExpRunNumber(int *exprun_buf)
Set a word consists of exp #, run # and subrun #.
Definition: RawHeader_v2.h:342
int GetExpNo()
get a run/exp number combined word
Definition: RawHeader_v2.h:368
int GetOffset2ndFINESSE()
get contents of header
Definition: RawHeader_v2.h:459
int GetOffset3rdFINESSE()
get contents of header
Definition: RawHeader_v2.h:465
Abstract base class for different kinds of events.