Belle II Software development
RawHeader_v0.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_V0_H
10#define RAWHEADER_V0_H
11
12#include <stdio.h>
13#include <string.h>
14#include <rawdata/switch_basf2_standalone.h>
15
16//#include <framework/datastore/DataStore.h>
17
18
19//#define HEADER_SIZE 16
20
21namespace Belle2 {
33 // class RawHeader_v0 : public TObject {
35 public:
38
40 explicit RawHeader_v0(int*);
41
44
46 int* GetBuffer() { return m_buffer; }
47
49 void SetBuffer(int* bufin) { m_buffer = bufin; }
50
52 void CheckSetBuffer();
53
55 void CheckGetBuffer();
56
58 void Initialize();
59
61 void SetNwords(int nwords);
62
64 void SetEveNo(unsigned int eve_no);
65
66 void SetNodeID(unsigned int node_id);
67
68 void SetDataType(int data_type);
69
70 void SetTruncMask(int trunc_mask);
71
72 // void SetB2LFEEHdrPart(unsigned int word1, unsigned int word2); //! set contents of header
73 // void SetFTSW2Words(int* ftsw_buf);
74
76 void SetFTSW2Words(unsigned int word1, unsigned int word2);
77
79 void SetExpRunNumber(int* exprun_buf);
80
82 void SetOffset1stFINESSE(int offset_1st_FINESSE);
83
84 void SetOffset2ndFINESSE(int offset_2nd_FINESSE);
85
86 void SetOffset3rdFINESSE(int offset_3rd_FINESSE);
87
88 void SetOffset4thFINESSE(int offset_4th_FINESSE);
89
91
93 int AddNodeInfo(int node_id);
94
96 int GetNwords();
97
98 int GetHdrNwords();
99
100 unsigned int GetExpRunSubrun();
101
102 int GetExpNo();
103
104 int GetRunNo();
105
106 int GetSubRunNo();
107
108 unsigned int GetEveNo();
109
110 unsigned int GetNodeID();
111
112 int GetDataType();
113
114 int GetTruncMask();
115
117 unsigned int GetErrorBitFlag();
118
120 void AddErrorBitFlag(unsigned int error_bit_flag);
121
124
127
130
133
135 int GetNumNodes();
136
138 int GetNodeInfo(int node_no, int* node_id);
139
141 unsigned int GetTTCtimeTRGType();
142
144 int GetTTCtime();
145
147 int GetTRGType();
148
150 unsigned int GetTTUtime();
151
153 void GetTTTimeVal(struct timeval* tv);
154
156 unsigned int GetMagicWordEntireHeader();
157
158 /*
159 Experimental(10bit) #, Run#(14bit), restat# bit mask(8bit)
160 */
161 enum {
162 FORMAT_VERSION__MASK = 0x0000FF00,
163 FORMAT_VERSION_SHIFT = 8
164 };
165
166 enum {
167 EXP_MASK = 0xFFC00000,
168 EXP_SHIFT = 22,
169 RUNNO_MASK = 0x003FFF00,
170 RUNNO_SHIFT = 8,
171 SUBRUNNO_MASK = 0x000000FF
172 };
173
174 enum {
175 RAWHEADER_NWORDS = 20
176 };
177
178 /* Data Format : Fixed length part*/
179 enum {
180 POS_NWORDS = 0,
181 POS_HDR_NWORDS = 1,
182 POS_EXP_RUN_NO = 2,
183 POS_EVE_NO = 3,
184 POS_TTCTIME_TRGTYPE = 4,
185 POS_TTUTIME = 5,
186 POS_NODE_ID = 6,
187 POS_TRUNC_MASK_DATATYPE = 7,
188 POS_OFFSET_1ST_FINESSE = 8,
189 POS_OFFSET_2ND_FINESSE = 9,
190 POS_OFFSET_3RD_FINESSE = 10,
191 POS_OFFSET_4TH_FINESSE = 11,
192 POS_RESVD_1 = 12,
193 POS_RESVD_2 = 13,
194 POS_NUM_NODES = 14,
195 POS_NODES_1 = 15,
196 POS_NODES_2 = 16,
197 POS_NODES_3 = 17,
198 POS_NODES_4 = 18,
199 POS_TERM_HEADER = 19
200 };
201 /* Data Format : Node info */
202 enum {
203 NUM_MAX_NODES = 4 /* (NUM_MAX_NODES + 1) slots are available in m_buffer.
204 (NUM_MAX_NODES +1 )th slot is filled with -1, when the number of total nodes
205 exceeds NUM_MAX_NODES */
206 };
207
208 /* Data Format : Magic word */
209 enum {
210 MAGIC_WORD_TERM_HEADER = 0x7fff0005
211 };
212
213 /* To extract ctime */
214 enum {
215 TTCTIME_MASK = 0x7FFFFFF0,
216 TTCTIME_SHIFT = 4,
217 TRGTYPE_MASK = 0xF
218 };
219
220 private:
222 int* m_buffer;
223
225 // ver.2 Do not record m_buffer pointer. (Dec.19, 2014)
226 // ClassDef(RawHeader_v0, 2);
227 };
228
229
231 {
232 if (m_buffer == NULL) {
233 B2FATAL("m_buffer is NULL. Exiting...");
234 }
235 }
236
238 {
239 if (m_buffer == NULL) {
240 B2FATAL("m_buffer is NULL. Data is corrupted or header info has not yet filled. Exiting...");
241 } else if (m_buffer[ POS_TERM_HEADER ] != MAGIC_WORD_TERM_HEADER) {
242 B2FATAL("magic word is invalid(0x" << std::hex << m_buffer[ POS_TERM_HEADER ] << "," << m_buffer << " pos " << std::dec <<
243 POS_TERM_HEADER
244 << "). Data is corrupted or header info has not yet filled. Exiting...");
245 }
246 }
247
248
249
250//
251// Set info.
252//
254 {
256 memset(m_buffer, 0, sizeof(int)*RAWHEADER_NWORDS);
257 m_buffer[ POS_HDR_NWORDS ] = RAWHEADER_NWORDS;
258 m_buffer[ POS_NUM_NODES ] = 0;
259
260 }
261
263 {
264 m_buffer[ POS_TERM_HEADER ] = MAGIC_WORD_TERM_HEADER;
265 }
266
267 inline void RawHeader_v0::SetNwords(int nwords)
268 {
270 m_buffer[ POS_NWORDS ] = nwords;
271
272 }
273
274 inline void RawHeader_v0::SetEveNo(unsigned int eve_no)
275 {
277 m_buffer[ POS_EVE_NO ] = eve_no;
278 }
279
280 inline void RawHeader_v0::SetNodeID(unsigned int node_id)
281 {
283 m_buffer[ POS_NODE_ID ] = node_id;
284 }
285
286 inline void RawHeader_v0::SetDataType(int data_type)
287 {
289 m_buffer[ POS_TRUNC_MASK_DATATYPE ] =
290 (data_type & 0x7FFFFFFF) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x80000000);
291 }
292
293 inline void RawHeader_v0::SetTruncMask(int trunc_mask)
294 {
296 /* cppcheck-suppress shiftTooManyBitsSigned */
297 m_buffer[ POS_TRUNC_MASK_DATATYPE ] = (trunc_mask << 31) | (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
298 }
299
300 /* inline void RawHeader_v0::SetB2LFEEHdrPart(unsigned int word1, unsigned int word2) */
301 /* { */
302 /* m_buffer[ POS_HSLB_1 ] = word1; */
303 /* m_buffer[ POS_HSLB_2 ] = word2; */
304 /* } */
305
306
307 inline void RawHeader_v0::SetOffset1stFINESSE(int offset_1st_FINESSE)
308 {
310 m_buffer[ POS_OFFSET_1ST_FINESSE ] = offset_1st_FINESSE;
311 }
312
313 inline void RawHeader_v0::SetOffset2ndFINESSE(int offset_2nd_FINESSE)
314 {
316 m_buffer[ POS_OFFSET_2ND_FINESSE ] = offset_2nd_FINESSE;
317 }
318
319 inline void RawHeader_v0::SetOffset3rdFINESSE(int offset_3rd_FINESSE)
320 {
322 m_buffer[ POS_OFFSET_3RD_FINESSE ] = offset_3rd_FINESSE;
323 }
324
325 inline void RawHeader_v0::SetOffset4thFINESSE(int offset_4th_FINESSE)
326 {
328 m_buffer[ POS_OFFSET_4TH_FINESSE ] = offset_4th_FINESSE;
329 }
330
331 /* inline void RawHeader_v0::SetFTSW2Words(int* ftsw_buf) */
332 /* { */
333 /* CheckSetBuffer(); */
334 /* memcpy(&(m_buffer[ POS_HSLB_1 ]), (char*)ftsw_buf, sizeof(int) * 2); */
335 /* return; */
336 /* } */
337
338 inline void RawHeader_v0::SetFTSW2Words(unsigned int word1,
339 unsigned int word2)
340 {
342 m_buffer[ POS_TTCTIME_TRGTYPE ] = word1;
343 m_buffer[ POS_TTUTIME ] = word2;
344 return;
345 }
346
347
348 inline void RawHeader_v0::SetExpRunNumber(int* exprun_buf)
349 {
351 memcpy(&(m_buffer[ POS_EXP_RUN_NO ]), (char*)exprun_buf, sizeof(int) * 1);
352 return;
353 }
354
355
356//
357// Obtain info
358//
359
361 {
363 return m_buffer[ POS_NWORDS ];
364 }
365
367 {
368
370
371 return m_buffer[ POS_HDR_NWORDS ];
372 }
373
375 {
377 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & EXP_MASK)
378 >> EXP_SHIFT);
379 }
380
381
383 {
385 return (((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]) & RUNNO_MASK)
386 >> RUNNO_SHIFT);
387 }
388
390 {
392 return (m_buffer[ POS_EXP_RUN_NO ] & SUBRUNNO_MASK);
393 }
394
395 inline unsigned int RawHeader_v0::GetExpRunSubrun()
396 {
398 return ((unsigned int)(m_buffer[ POS_EXP_RUN_NO ]));
399 }
400
401
402 inline unsigned int RawHeader_v0::GetEveNo()
403 {
405 return m_buffer[ POS_EVE_NO ];
406 }
407
408 inline unsigned int RawHeader_v0::GetNodeID()
409 {
411 return (unsigned int)(m_buffer[ POS_NODE_ID ]);
412 }
413
415 {
417 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] & 0x7FFFFFFF);
418 }
419
421 {
423 return (m_buffer[ POS_TRUNC_MASK_DATATYPE ] >> 23) & 0x1;
424 }
425
426 inline unsigned int RawHeader_v0::GetErrorBitFlag()
427 {
429 return (unsigned int)(m_buffer[ POS_TRUNC_MASK_DATATYPE ]);
430 }
431
432 inline void RawHeader_v0::AddErrorBitFlag(unsigned int error_bit_flag)
433 {
435 m_buffer[ POS_TRUNC_MASK_DATATYPE ] |= (int)error_bit_flag;
436 return;
437 }
438
440 {
442 return m_buffer[ POS_OFFSET_1ST_FINESSE ];
443 }
444
446 {
448 return m_buffer[ POS_OFFSET_2ND_FINESSE ];
449 }
450
452 {
454 return m_buffer[ POS_OFFSET_3RD_FINESSE ];
455 }
456
458 {
460 return m_buffer[ POS_OFFSET_4TH_FINESSE ];
461 }
462
464 {
466 return m_buffer[ POS_NUM_NODES ];
467 }
468
470 {
472 return (unsigned int)(m_buffer[ POS_TTCTIME_TRGTYPE ]);
473 }
474
476 {
478 return (int)((GetTTCtimeTRGType() & TTCTIME_MASK) >> TTCTIME_SHIFT);
479 }
480
482 {
484 return (int)(GetTTCtimeTRGType() & TRGTYPE_MASK);
485 }
486
487
488 inline unsigned int RawHeader_v0::GetTTUtime()
489 {
491 return (unsigned int)(m_buffer[ POS_TTUTIME ]);
492 }
493
494 inline void RawHeader_v0::GetTTTimeVal(struct timeval* tv)
495 {
496 tv->tv_sec = GetTTUtime();
497 tv->tv_usec = (int)(((double)GetTTCtime()) / 127.216);
498 return ;
499 }
500
501
503 {
505 return m_buffer[ POS_TERM_HEADER ];
506 }
507
508
509
510
511
513}
514
515#endif
The Raw Header class ver.0 ( from August, 2013 to April, 2014 ) This class defines the format of the ...
Definition: RawHeader_v0.h:34
RawHeader_v0()
Default constructor.
Definition: RawHeader_v0.cc:17
int AddNodeInfo(int node_id)
set magic words;
Definition: RawHeader_v0.cc:34
int * m_buffer
do not record buffer ( RawCOPPER includes buffer of RawHeader_v0 and RawTrailer )
Definition: RawHeader_v0.h:222
void SetBuffer(int *bufin)
set buffer
Definition: RawHeader_v0.h:49
~RawHeader_v0()
Destructor.
Definition: RawHeader_v0.cc:29
int * GetBuffer()
Get header contents.
Definition: RawHeader_v0.h:46
int GetNodeInfo(int node_no, int *node_id)
get contents of header
Definition: RawHeader_v0.cc:48
int GetNwords()
get contents of header
Definition: RawHeader_v0.h:360
void SetTruncMask(int trunc_mask)
set contents of header
Definition: RawHeader_v0.h:293
unsigned int GetEveNo()
get restart #(8bit)
Definition: RawHeader_v0.h:402
int GetOffset1stFINESSE()
get contents of header
Definition: RawHeader_v0.h:439
void AddErrorBitFlag(unsigned int error_bit_flag)
Add Detected Error bitflag.
Definition: RawHeader_v0.h:432
int GetTTCtime()
get contents of header
Definition: RawHeader_v0.h:475
unsigned int GetMagicWordEntireHeader()
Get magic word to check the data corruption.
Definition: RawHeader_v0.h:502
void SetOffset4thFINESSE(int offset_4th_FINESSE)
set contents of header
Definition: RawHeader_v0.h:325
void GetTTTimeVal(struct timeval *tv)
get contents of header
Definition: RawHeader_v0.h:494
void SetFTSW2Words(unsigned int word1, unsigned int word2)
set contents of header
Definition: RawHeader_v0.h:338
int GetSubRunNo()
get run # (14bit)
Definition: RawHeader_v0.h:389
int GetHdrNwords()
get contents of header
Definition: RawHeader_v0.h:366
void SetOffset2ndFINESSE(int offset_2nd_FINESSE)
set contents of header
Definition: RawHeader_v0.h:313
int GetDataType()
get contents of header
Definition: RawHeader_v0.h:414
void CheckSetBuffer()
initialize header
Definition: RawHeader_v0.h:230
unsigned int GetTTUtime()
get contents of header
Definition: RawHeader_v0.h:488
void CheckGetBuffer()
check if m_buffer exists
Definition: RawHeader_v0.h:237
int GetTRGType()
get TRGType
Definition: RawHeader_v0.h:481
void SetEveNo(unsigned int eve_no)
set contents of header
Definition: RawHeader_v0.h:274
int GetNumNodes()
get contents of header
Definition: RawHeader_v0.h:463
unsigned int GetNodeID()
get contents of header
Definition: RawHeader_v0.h:408
void SetDataType(int data_type)
set contents of header
Definition: RawHeader_v0.h:286
void Initialize()
initialize header
Definition: RawHeader_v0.h:253
void SetNodeID(unsigned int node_id)
set contents of header
Definition: RawHeader_v0.h:280
int GetRunNo()
get contents of header
Definition: RawHeader_v0.h:382
void SetOffset1stFINESSE(int offset_1st_FINESSE)
set contents of header
Definition: RawHeader_v0.h:307
void SetNwords(int nwords)
set contents of header
Definition: RawHeader_v0.h:267
int GetTruncMask()
get contents of header
Definition: RawHeader_v0.h:420
int GetOffset4thFINESSE()
get contents of header
Definition: RawHeader_v0.h:457
unsigned int GetErrorBitFlag()
get contents of header
Definition: RawHeader_v0.h:426
void SetOffset3rdFINESSE(int offset_3rd_FINESSE)
set contents of header
Definition: RawHeader_v0.h:319
unsigned int GetTTCtimeTRGType()
get contents of header
Definition: RawHeader_v0.h:469
unsigned int GetExpRunSubrun()
get contents of header
Definition: RawHeader_v0.h:395
void SetExpRunNumber(int *exprun_buf)
Set a word consists of exp #, run # and subrun #.
Definition: RawHeader_v0.h:348
int GetExpNo()
get a run/exp number combined word
Definition: RawHeader_v0.h:374
int GetOffset2ndFINESSE()
get contents of header
Definition: RawHeader_v0.h:445
int GetOffset3rdFINESSE()
get contents of header
Definition: RawHeader_v0.h:451
void SetMagicWordEntireHeader()
set contents of header
Definition: RawHeader_v0.h:262
Abstract base class for different kinds of events.