Belle II Software  release-08-01-10
RawTLUFormat.cc
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 #include <rawdata/dataobjects/RawTLUFormat.h>
10 using namespace std;
11 using namespace Belle2;
12 
13 RawTLUFormat::RawTLUFormat()
14 {
15 }
16 
17 RawTLUFormat::~RawTLUFormat()
18 {
19 }
20 
21 // int RawTLUFormat::GetNwords(int n)
22 // {
23 // return m_buffer[ GetBufferPos(n) + POS_NWORDS ];
24 // }
25 
26 int RawTLUFormat::GetNwordsHeader(int n)
27 {
28  return m_buffer[ GetBufferPos(n) + POS_HDR_NWORDS ];
29 }
30 
31 
32 unsigned int RawTLUFormat::GetNodeID(int n)
33 {
34  return (unsigned int)(m_buffer[ GetBufferPos(n) + POS_NODE_ID ]);
35 }
36 
37 unsigned int RawTLUFormat::GetEveNo(int n)
38 {
39  return m_buffer[ GetBufferPos(n) + POS_EVE_NO ];
40 }
41 
42 
43 int RawTLUFormat::GetRunNo(int n)
44 {
45  return m_buffer[ GetBufferPos(n) + POS_RUN_NO ];
46 }
47 
48 
49 unsigned int RawTLUFormat::GetMagicTrailer(int n)
50 {
51  return m_buffer[ GetBufferPos(n) + POS_MAGIC_1 ];
52 }
53 
54 unsigned int RawTLUFormat::GetTLUEventTag(int n)
55 {
56  return m_buffer[ GetBufferPos(n) + POS_TLU_EVENTTAG ];
57 }
58 
59 
60 void RawTLUFormat::CheckData(int n,
61  unsigned int prev_evenum, unsigned int* cur_evenum)
62 {
63  int err_flag = 0;
64  char err_buf[500];
65  *cur_evenum = GetEveNo(n);
66 
67 #ifndef NO_DATA_CHECK
68  if (prev_evenum != 0xFFFFFFFF && *cur_evenum != 0) {
69  if ((unsigned int)(prev_evenum + 1) != *cur_evenum) {
70  sprintf(err_buf, "Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n %s %s %d\n",
71  n, prev_evenum, *cur_evenum, __FILE__, __PRETTY_FUNCTION__, __LINE__);
72  err_flag = 1;
73  }
74  }
75 #endif
76 
77  if (GetEveNo(n) != GetTLUEventTag(n)) {
78  sprintf(err_buf, "invalid TLU event tag : blodk %d header eve # %u TLU tag %u. Exiting...\n %s %s %d\n",
79  n, GetEveNo(n), GetTLUEventTag(n), __FILE__, __PRETTY_FUNCTION__, __LINE__);
80  err_flag = 1;
81  }
82 
83 
84  if (GetBlockNwords(n) != SIZE_TLU_PACKET) {
85  sprintf(err_buf, "invalid TLU packet length : block %d nwords %d must be %d : Exiting...\n %s %s %d\n",
86  n, GetBlockNwords(n), SIZE_TLU_PACKET, __FILE__, __PRETTY_FUNCTION__, __LINE__);
87  err_flag = 1;
88  }
89 
90  if (GetMagicTrailer(n) != TLU_MAGIC_TRAILER) {
91  sprintf(err_buf, "invalid magic word : block %d magic word 0x%x must be 0x%x : Exiting...\n %s %s %d\n",
92  n, GetMagicTrailer(n), TLU_MAGIC_TRAILER, __FILE__, __PRETTY_FUNCTION__, __LINE__);
93  err_flag = 1;
94  }
95 
96  if (err_flag == 1) {
97  printf("[DEBUG] ========== dump a data block : block # %d==========\n", n);
98  printf("[DEBUG] ");
99  for (int k = 0 ; k < GetBlockNwords(n); k++) {
100  printf("0x%.8x ", (GetBuffer(n))[k]);
101  if (k % 10 == 9) printf("\n[DEBUG] ");
102  }
103  fflush(stderr);
104  B2FATAL(err_buf);
105  }
106 
107  return;
108 }
Abstract base class for different kinds of events.