Belle II Software development
RawHeader_v1.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_V1_H
10#define RAWHEADER_V1_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 {
32 // class RawHeader_v1 : public TObject {
33 public:
36
38 explicit RawHeader_v1(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
121
124
127
130
131 // int GetNumNodes(); //! get contents of header
132
133 // int GetNodeInfo(int node_no, int* node_id); //! get contents of header
134
136 unsigned int GetTTCtimeTRGType();
137
139 int GetTTCtime();
140
142 int GetTRGType();
143
145 unsigned int GetTTUtime();
146
148 void GetTTTimeVal(struct timeval* tv);
149
151 // unsigned int GetMagicWordEntireHeader();
152
154 void CheckHeader(int* buf);
155
156 /*
157 Experimental(10bit) #, Run#(14bit), restat# bit mask(8bit)
158 */
159 enum {
160 MAGIC_WORD = 0x7F7F0000,
161 MAGIC_MASK = 0xFFFF0000,
162 MAGIC_SHIFT = 16,
163 FORMAT_VERSION__MASK = 0x0000FF00,
164 FORMAT_VERSION_SHIFT = 8
165 };
166
167 enum {
168 EXP_MASK = 0xFFC00000,
169 EXP_SHIFT = 22,
170 RUNNO_MASK = 0x003FFF00,
171 RUNNO_SHIFT = 8,
172 SUBRUNNO_MASK = 0x000000FF
173 };
174
175 enum {
176 RAWHEADER_NWORDS = 12
177 };
178
179 enum {
180 HDR_NWORDS_MASK = 0x000000FF
181 };
182
183 /* Data Format : Fixed length part*/
184 enum {
185 POS_NWORDS = 0,
186 POS_VERSION_HDRNWORDS = 1,
187 POS_EXP_RUN_NO = 2,
188 POS_EVE_NO = 3,
189 POS_TTCTIME_TRGTYPE = 4,
190 POS_TTUTIME = 5,
191 POS_NODE_ID = 6,
192 POS_TRUNC_MASK_DATATYPE = 7,
193 POS_OFFSET_1ST_FINESSE = 8,
194 POS_OFFSET_2ND_FINESSE = 9,
195 POS_OFFSET_3RD_FINESSE = 10,
196 POS_OFFSET_4TH_FINESSE = 11,
197 };
198 /* Data Format : Node info */
199 /* enum { */
200 /* NUM_MAX_NODES = 4 /\* (NUM_MAX_NODES + 1) slots are available in m_buffer. */
201 /* (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes */
202 /* exceeds NUM_MAX_NODES *\/ */
203 /* }; */
204
205 /* /\* Data Format : Magic word *\/ */
206 /* enum { */
207 /* MAGIC_WORD_TERM_HEADER = 0x7fff0005 */
208 /* }; */
209
210 /* To extract ctime */
211 enum {
212 TTCTIME_MASK = 0x7FFFFFF0,
213 TTCTIME_SHIFT = 4,
214 TRGTYPE_MASK = 0xF
215 };
216
217 private:
219 int* m_buffer;
220
222 // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
223 // ClassDef(RawHeader_v1, 1);
224 };
225
226
228 {
229 if (m_buffer == NULL) {
230 B2FATAL("m_buffer is NULL. Exiting...");
231 }
232 }
233
235 {
236
237 if (m_buffer == NULL) {
238 B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
239// } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) { */
240// B2FATAL("[DEBUG] magic word is invalid(0x" << hex() << m_buffer[ POS_TERM_HEADER ] << "). Data is corrupted or header info has not yet filled. Exiting...");
241 }
242
243
244
245 }
246
247 inline void RawHeader_v1::SetNwords(int nwords)
248 {
250 m_buffer[ POS_NWORDS ] = nwords;
251
252 }
253
254 inline void RawHeader_v1::SetEveNo(unsigned int eve_no)
255 {
257 m_buffer[ POS_EVE_NO ] = eve_no;
258 }
259
260 inline void RawHeader_v1::SetNodeID(unsigned int node_id)
261 {
263 m_buffer[ POS_NODE_ID ] = (int)node_id;
264 }
265
266 inline void RawHeader_v1::SetDataType(int data_type)
267 {
269 m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
270 (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
271 }
272
273 inline void RawHeader_v1::SetTruncMask(int trunc_mask)
274 {
276 /* cppcheck-suppress shiftTooManyBitsSigned */
277 m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
278 }
279
280 /* inline void RawHeader_v1::SetB2LFEEHdrPart(unsigned int word1, unsigned int word2) */
281 /* { */
282 /* m_buffer[ POS_HSLB_1 ] = word1; */
283 /* m_buffer[ POS_HSLB_2 ] = word2; */
284 /* } */
285
286
287 inline void RawHeader_v1::SetOffset1stFINESSE(int offset_1st_FINESSE)
288 {
290 m_buffer[ POS_OFFSET_1ST_FINESSE ] = offset_1st_FINESSE;
291 }
292
293 inline void RawHeader_v1::SetOffset2ndFINESSE(int offset_2nd_FINESSE)
294 {
296 m_buffer[ POS_OFFSET_2ND_FINESSE ] = offset_2nd_FINESSE;
297 }
298
299 inline void RawHeader_v1::SetOffset3rdFINESSE(int offset_3rd_FINESSE)
300 {
302 m_buffer[ POS_OFFSET_3RD_FINESSE ] = offset_3rd_FINESSE;
303 }
304
305 inline void RawHeader_v1::SetOffset4thFINESSE(int offset_4th_FINESSE)
306 {
308 m_buffer[ POS_OFFSET_4TH_FINESSE ] = offset_4th_FINESSE;
309 }
310
311 /* inline void RawHeader_v1::SetFTSW2Words(int* ftsw_buf) */
312 /* { */
313 /* CheckSetBuffer(); */
314 /* memcpy(&(m_buffer[ POS_HSLB_1 ]), (char*)ftsw_buf, sizeof(int) * 2); */
315 /* return; */
316 /* } */
317
318 inline void RawHeader_v1::SetFTSW2Words(unsigned int word1,
319 unsigned int word2)
320 {
322 m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
323 m_buffer[ POS_TTUTIME ] = word2;
324 return;
325 }
326
327
328 inline void RawHeader_v1::SetExpRunNumber(int* exprun_buf)
329 {
331 memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
332 return;
333 }
334
335
336//
337// Obtain info
338//
339
341 {
343 return m_buffer[ POS_NWORDS ];
344 }
345
347 {
348
349 // CheckGetBuffer();
350 // return m_buffer[ POS_HDR_NWORDS ];
351 return RAWHEADER_NWORDS;
352 }
353
355 {
357 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
358 >> EXP_SHIFT);
359 }
360
362 {
364 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
365 >> RUNNO_SHIFT);
366 }
367
369 {
371 return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
372 }
373
374 inline unsigned int RawHeader_v1::GetExpRunSubrun()
375 {
377 return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
378 }
379
380
381 inline unsigned int RawHeader_v1::GetEveNo()
382 {
384 return m_buffer[ POS_EVE_NO ];
385 }
386
387 inline unsigned int RawHeader_v1::GetNodeID()
388 {
390 return (unsigned int)m_buffer[ POS_NODE_ID ];
391 }
392
394 {
396 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
397 }
398
400 {
402 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
403 }
404
405 inline unsigned int RawHeader_v1::GetErrorBitFlag()
406 {
408 return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
409 }
410
411 inline void RawHeader_v1::AddErrorBitFlag(unsigned int error_bit_flag)
412 {
414 m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
415 return;
416 }
417
419 {
421 return m_buffer[ POS_OFFSET_1ST_FINESSE ];
422 }
423
425 {
427 return m_buffer[ POS_OFFSET_2ND_FINESSE ];
428 }
429
431 {
433 return m_buffer[ POS_OFFSET_3RD_FINESSE ];
434 }
435
437 {
439 return m_buffer[ POS_OFFSET_4TH_FINESSE ];
440 }
441
442 /* inline int RawHeader_v1::GetNumNodes() */
443 /* { */
444 /* CheckGetBuffer(); */
445 /* return m_buffer[ POS_NUM_NODES ]; */
446 /* } */
447
449 {
451 return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
452 }
453
455 {
457 return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
458 }
459
461 {
463 return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
464 }
465
466 inline unsigned int RawHeader_v1::GetTTUtime()
467 {
469 return (unsigned int)(m_buffer[ POS_TTUTIME ]);
470 }
471
472 inline void RawHeader_v1::GetTTTimeVal(struct timeval* tv)
473 {
474 tv->tv_sec = GetTTUtime();
475 tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
476 return ;
477 }
478
479
480 /* inline unsigned int RawHeader_v1::GetMagicWordEntireHeader() */
481 /* { */
482 /* CheckGetBuffer(); */
483 /* return m_buffer[ POS_TERM_HEADER ]; */
484 /* } */
485
486
487
488
489
491}
492
493#endif
The Raw Header class ver.1 ( the latest version since May, 2014 ) This class defines the format of th...
Definition: RawHeader_v1.h:31
int * m_buffer
do not record buffer ( RawCOPPER includes buffer of RawHeader_v1 and RawTrailer )
Definition: RawHeader_v1.h:219
void SetBuffer(int *bufin)
set buffer
Definition: RawHeader_v1.h:47
void CheckHeader(int *buf)
Get magic word to check the data corruption.
Definition: RawHeader_v1.cc:62
RawHeader_v1()
Default constructor.
Definition: RawHeader_v1.cc:17
int * GetBuffer()
Get header contents.
Definition: RawHeader_v1.h:44
~RawHeader_v1()
Destructor.
Definition: RawHeader_v1.cc:29
int GetNwords()
set contents of header
Definition: RawHeader_v1.h:340
void SetTruncMask(int trunc_mask)
set contents of header
Definition: RawHeader_v1.h:273
unsigned int GetEveNo()
get restart #(8bit)
Definition: RawHeader_v1.h:381
int GetOffset1stFINESSE()
get contents of header
Definition: RawHeader_v1.h:418
void AddErrorBitFlag(unsigned int error_bit_flag)
Add Detected Error bitflag.
Definition: RawHeader_v1.h:411
int GetTTCtime()
get contents of header
Definition: RawHeader_v1.h:454
void SetOffset4thFINESSE(int offset_4th_FINESSE)
set contents of header
Definition: RawHeader_v1.h:305
void GetTTTimeVal(struct timeval *tv)
get contents of header
Definition: RawHeader_v1.h:472
void SetFTSW2Words(unsigned int word1, unsigned int word2)
Set values of FTSW info( trigger timing)
Definition: RawHeader_v1.h:318
int GetSubRunNo()
get run # (14bit)
Definition: RawHeader_v1.h:368
int GetHdrNwords()
get contents of header
Definition: RawHeader_v1.h:346
void SetOffset2ndFINESSE(int offset_2nd_FINESSE)
set contents of header
Definition: RawHeader_v1.h:293
int GetDataType()
get contents of header
Definition: RawHeader_v1.h:393
void CheckSetBuffer()
initialize header
Definition: RawHeader_v1.h:227
unsigned int GetTTUtime()
get contents of header
Definition: RawHeader_v1.h:466
void CheckGetBuffer()
check if m_buffer exists
Definition: RawHeader_v1.h:234
int GetTRGType()
get TRGType
Definition: RawHeader_v1.h:460
void SetEveNo(unsigned int eve_no)
set contents of header
Definition: RawHeader_v1.h:254
unsigned int GetNodeID()
get contents of header
Definition: RawHeader_v1.h:387
void SetDataType(int data_type)
set contents of header
Definition: RawHeader_v1.h:266
void SetNodeID(unsigned int node_id)
set contents of header
Definition: RawHeader_v1.h:260
int GetRunNo()
get contents of header
Definition: RawHeader_v1.h:361
void SetOffset1stFINESSE(int offset_1st_FINESSE)
set contents of header
Definition: RawHeader_v1.h:287
void SetNwords(int nwords)
set contents of header
Definition: RawHeader_v1.h:247
int GetTruncMask()
get contents of header
Definition: RawHeader_v1.h:399
int GetOffset4thFINESSE()
get contents of header
Definition: RawHeader_v1.h:436
unsigned int GetErrorBitFlag()
get contents of header
Definition: RawHeader_v1.h:405
void SetOffset3rdFINESSE(int offset_3rd_FINESSE)
set contents of header
Definition: RawHeader_v1.h:299
unsigned int GetTTCtimeTRGType()
get contents of header
Definition: RawHeader_v1.h:448
unsigned int GetExpRunSubrun()
get contents of header
Definition: RawHeader_v1.h:374
void SetExpRunNumber(int *exprun_buf)
Set a word consists of exp #, run # and subrun #.
Definition: RawHeader_v1.h:328
int GetExpNo()
get a run/exp number combined word
Definition: RawHeader_v1.h:354
int GetOffset2ndFINESSE()
get contents of header
Definition: RawHeader_v1.h:424
int GetOffset3rdFINESSE()
get contents of header
Definition: RawHeader_v1.h:430
Abstract base class for different kinds of events.