Belle II Software  release-05-01-25
RawCOPPERFormat.cc
1 //+
2 // File : RawCOPPERFormat.cc
3 // Description : Module to handle raw data from COPPER.
4 //
5 // Author : Satoru Yamada, IPNS, KEK
6 // Date : 3 - July - 2014
7 //-
8 
9 #include <rawdata/dataobjects/RawCOPPERFormat.h>
10 
11 using namespace std;
12 using namespace Belle2;
13 //ClassImp(RawCOPPERFormat);
14 
15 
16 RawCOPPERFormat::RawCOPPERFormat()
17 {
18 // m_nwords = 0;
19 // m_num_nodes = 0;
20 // m_num_events = 0;
21 // m_buffer = NULL;
22 }
23 
24 unsigned int RawCOPPERFormat::CalcXORChecksum(int* buf, int nwords)
25 {
26  unsigned int checksum = 0;
27  for (int i = 0; i < nwords; i++) {
28  checksum = checksum ^ buf[ i ];
29  }
30  return checksum;
31 }
32 
33 
34 
35 
36 int RawCOPPERFormat::GetOffsetFINESSE(int n, int finesse_num)
37 {
38  switch (finesse_num) {
39  case 0 :
40  return GetOffset1stFINESSE(n);
41  break;
42  case 1 :
43  return GetOffset2ndFINESSE(n);
44  break;
45  case 2 :
46  return GetOffset3rdFINESSE(n);
47  break;
48  case 3 :
49  return GetOffset4thFINESSE(n);
50  break;
51  default :
52  break;
53  }
54 
55  char err_buf[500];
56  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
57  __FILE__, __PRETTY_FUNCTION__, __LINE__);
58  printf("%s", err_buf); fflush(stdout);
59  B2FATAL(err_buf);
60 }
61 
62 
63 
64 
65 int* RawCOPPERFormat::GetFINESSEBuffer(int n, int finesse_num)
66 {
67  switch (finesse_num) {
68  case 0 :
69  return Get1stFINESSEBuffer(n);
70  break;
71  case 1 :
72  return Get2ndFINESSEBuffer(n);
73  break;
74  case 2 :
75  return Get3rdFINESSEBuffer(n);
76  break;
77  case 3 :
78  return Get4thFINESSEBuffer(n);
79  break;
80  default :
81  break;
82  }
83 
84  char err_buf[500];
85  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
86  __FILE__, __PRETTY_FUNCTION__, __LINE__);
87  printf("%s", err_buf); fflush(stdout);
88  B2FATAL(err_buf);
89 }
90 
91 
92 
93 
94 int* RawCOPPERFormat::GetDetectorBuffer(int n, int finesse_num)
95 {
96  switch (finesse_num) {
97  case 0 :
98  return Get1stDetectorBuffer(n);
99  break;
100  case 1 :
101  return Get2ndDetectorBuffer(n);
102  break;
103  case 2 :
104  return Get3rdDetectorBuffer(n);
105  break;
106  case 3 :
107  return Get4thDetectorBuffer(n);
108  break;
109  default :
110  break;
111  }
112 
113  char err_buf[500];
114  sprintf(err_buf, "[FATAL] Specifined FINESSE number( = %d ) is invalid. Exiting...\n%s %s %d\n", finesse_num,
115  __FILE__, __PRETTY_FUNCTION__, __LINE__);
116  printf("%s", err_buf); fflush(stdout);
117  B2FATAL(err_buf);
118 }
119 
120 
121 
122 unsigned int RawCOPPERFormat::GetB2LHeaderWord(int n, int finesse_buffer_pos)
123 {
124  unsigned int word[4];
125  unsigned int ret_word = 0;
126  int flag = 0, err_flag = 0;
127 
128  for (int i = 0; i < 4; i++) {
129  if (GetFINESSENwords(n, i) > 0) {
130  word[ i ] = m_buffer[ GetOffsetFINESSE(n, i) + finesse_buffer_pos ];
131  if (flag != 0 && (ret_word != word[ i ])) {
132  err_flag = 1;
133  }
134  ret_word = word[ i ];
135  flag = 1;
136  }
137  }
138 
139  if (flag == 0) {
140  char err_buf[500];
141  sprintf(err_buf, "[FATAL] ERROR_EVENT : No HSLB data in COPPER data. Exiting...\n %s %s %d\n",
142  __FILE__, __PRETTY_FUNCTION__, __LINE__);
143  printf("%s", err_buf); fflush(stdout);
144  B2FATAL(err_buf);
145  }
146 
147  if (err_flag == 1) {
148  char err_buf[500];
149  sprintf(err_buf, "[FATAL] ERROR_EVENT : Different event number over HSLBs : slot A 0x%x : B 0x%x :C 0x%x : D 0x%x\n %s %s %d\n",
150  word[ 0 ], word[ 1 ], word[ 2 ], word[ 3 ],
151  __FILE__, __PRETTY_FUNCTION__, __LINE__);
152  printf("[DEBUG] %s\n", err_buf);
153 #ifndef NO_DATA_CHECK
154  B2FATAL(err_buf);
155 #endif
156  }
157  return ret_word;
158 }
159 
160 
161 // This function is available after RawCOPPER/Header ver.2
162 int RawCOPPERFormat::GetPacketCRCError(int n)
163 {
164  char err_buf[500];
165  sprintf(err_buf,
166  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d : %s %s %d: Exiting...\n",
167  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
168  printf("%s\n", err_buf); fflush(stdout);
169  B2FATAL(err_buf);
170  return -1;
171 }
172 
173 // This function is available after RawCOPPER/Header ver.2
174 int RawCOPPERFormat::GetEventCRCError(int n)
175 {
176  char err_buf[500];
177  sprintf(err_buf,
178  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d : %s %s %d: Exiting...\n",
179  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
180  printf("%s\n", err_buf); fflush(stdout);
181  B2FATAL(err_buf);
182  return -1;
183 }
184 
185 int RawCOPPERFormat::GetEventCRC16Value(int n, int finesse_num)
186 {
187  char err_buf[500];
188  sprintf(err_buf,
189  "[FATAL] This function is not supported in the version of RawCOPPER format that you're using. n=%d fin=%d : %s %s %d: Exiting...\n",
190  n, finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
191  printf("%s\n", err_buf); fflush(stdout);
192  B2FATAL(err_buf);
193  return -1;
194 }
195 
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19