Belle II Software development
PostRawCOPPERFormat_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 POSTRAWCOPPERFORMAT_V2_H
10#define POSTRAWCOPPERFORMAT_V2_H
11
12// Includes
13/* #include <stdio.h> */
14/* #include <stdlib.h> */
15/* #include <string> */
16/* #include <sys/time.h> */
17
18#include <rawdata/dataobjects/RawCOPPERFormat_v2.h>
19#include <rawdata/CRCCalculator.h>
20
21//#include <framework/datastore/DataStore.h>
22//#include <TObject.h>
23
24//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
25
26namespace Belle2 {
38 public:
41
43 //PostRawCOPPERFormat_v2(int* bufin, int nwords);
46
47 //
48 // Get position of or pointer to data
49 //
51 // POINTER TO "DETECTOR BUFFER"
52 //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
54
56 /* cppcheck-suppress missingOverride */
57 int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
58
60 /* cppcheck-suppress missingOverride */
61 int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
62
64 /* cppcheck-suppress missingOverride */
65 int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
66
68 /* cppcheck-suppress missingOverride */
69 int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
70
72 /* cppcheck-suppress missingOverride */
73 int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
75
77 // virtual int GetBufferPos(int n);
78
79 //
80 // Get information from 13words "COPPER header" attached by COPPER board
81 //
83 /* cppcheck-suppress missingOverride */
84 unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
85
87 /* cppcheck-suppress missingOverride */
88 int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
89
91 /* cppcheck-suppress missingOverride */
92 int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
93
94 //
95 // Get information from "B2link(attached by FEE and HLSB) header"
96 //
98 // virtual int* GetFTSW2Words(int n);
99
101 /* cppcheck-suppress missingOverride */
102 virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
103
105 /* cppcheck-suppress missingOverride */
106 virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
107
108 //
109 // read magic word to check data
110 //
112 /* cppcheck-suppress missingOverride */
113 unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
114
116 /* cppcheck-suppress missingOverride */
117 unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
118
120 /* cppcheck-suppress missingOverride */
121 unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
122
124 /* cppcheck-suppress missingOverride */
125 unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
126
128 /* cppcheck-suppress missingOverride */
129 unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
130
132 /* cppcheck-suppress missingOverride */
133 int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17;
134
136 /* cppcheck-suppress missingOverride */
137 bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
138
140 /* cppcheck-suppress missingOverride */
141 unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
142 unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
143
145 /* cppcheck-suppress missingOverride */
146 unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
147
149 /* cppcheck-suppress missingOverride */
150 unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
151
153 /* cppcheck-suppress missingOverride */
154 void CheckData(int n,
155 unsigned int prev_evenum, unsigned int* cur_evenum,
156 unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
157 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
158
160 /* cppcheck-suppress missingOverride */
161 void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
162
164 int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
165
167 int CheckCRC16(int n, int finesse_num);
168
170 /* cppcheck-suppress missingOverride */
171 int* PackDetectorBuf(int* packed_buf_nwords,
172 int* detector_buf_1st, int nwords_1st,
173 int* detector_buf_2nd, int nwords_2nd,
174 int* detector_buf_3rd, int nwords_3rd,
175 int* detector_buf_4th, int nwords_4th,
176 RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
177
178 //
179 // size of "COPPER front header" and "COPPER trailer"
180 //
182
183 enum {
184 SIZE_COPPER_DRIVER_HEADER = 0,
185 SIZE_COPPER_DRIVER_TRAILER = 0
186 };
187
188 // Data Format : "COPPER header"
189 enum {
190 SIZE_COPPER_HEADER = 0
191 };
192
193 // Data Format : "COPPER Trailer"
194 enum {
195 SIZE_COPPER_TRAILER = 0
196 };
197
198 // Data Format : "B2Link HSLB Header"
199 enum {
200 POS_B2LHSLB_MAGIC = 0,
201 SIZE_B2LHSLB_HEADER = 1
202 };
203
204
205 // Data Format : "B2Link FEE Header"
206 enum {
207 POS_B2L_CTIME = 0,
208 SIZE_B2LFEE_HEADER = 1
209 };
210
211 // Data Format : B2Link FEE Trailer
212 enum {
213 POS_B2LFEE_ERRCNT_CRC16 = 0,
214 SIZE_B2LFEE_TRAILER = 1
215 };
216
217 //
218 // Data Format : "B2Link HSLB Trailer"
219 //
220 enum {
221 SIZE_B2LHSLB_TRAILER = 0
222 };
223
224
225
226 protected :
228 // ClassDefOverride(PostRawCOPPERFormat_v2, 2);
229
230 };
231
233 {
234 int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
235 return pos_nwords;
236 }
237
239 {
240#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
241 CheckB2LFEEHeaderVersion(n);
242#endif
243 if (Get1stFINESSENwords(n) > 0) {
244 int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
245 return &(m_buffer[ pos_nwords ]);
246 }
247 return NULL;
248 }
249
251 {
252#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
253 CheckB2LFEEHeaderVersion(n);
254#endif
255 if (Get2ndFINESSENwords(n) > 0) {
256 int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
257 return &(m_buffer[ pos_nwords ]);
258 }
259 return NULL;
260 }
261
263 {
264#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
265 CheckB2LFEEHeaderVersion(n);
266#endif
267 if (Get3rdFINESSENwords(n) > 0) {
268 int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
269 return &(m_buffer[ pos_nwords ]);
270 }
271 return NULL;
272 }
273
275 {
276#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
277 CheckB2LFEEHeaderVersion(n);
278#endif
279 if (Get4thFINESSENwords(n) > 0) {
280 int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
281 return &(m_buffer[ pos_nwords ]);
282 }
283 return NULL;
284 }
285
287 {
288 int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
289 return &(m_buffer[ pos_nwords ]);
290 /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
291 /* CheckB2LFEEHeaderVersion(n); */
292 /* #endif */
293 /* int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
294 /* return &(m_buffer[ pos_nwords ]); */
295 }
296
298 {
299 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
300 - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
301 return m_buffer[ pos_nwords ];
302 }
303
304
306 {
307 char err_buf[500];
308 sprintf(err_buf, "[FATAL] This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
309 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
310 printf("%s", err_buf);
311 std::string err_str = err_buf; throw (err_str);
312 return 0;
313 }
314
316 {
317 char err_buf[500];
318 sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
319 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
320 printf("%s", err_buf);
321 std::string err_str = err_buf; throw (err_str);
322 return 0;
323 }
324
326 {
327 char err_buf[500];
328 sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
329 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
330 printf("%s", err_buf);
331 std::string err_str = err_buf; throw (err_str);
332 return 0;
333 }
334
335
337 {
338 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
339
340 // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
341
342 return (unsigned int)(m_buffer[ pos_nwords ]);
343 }
344
346 {
347 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
348 return (unsigned int)(m_buffer[ pos_nwords ]);
349 }
350
351
353 {
354 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
355 return (unsigned int)(m_buffer[ pos_nwords ]);
356 }
357
358 inline int PostRawCOPPERFormat_v2::GetEventCRC16Value(int n, int finesse_num)
359 {
360 int fin_nwords = GetFINESSENwords(n, finesse_num);
361 if (fin_nwords > 0) {
362 int* buf = GetFINESSEBuffer(n, finesse_num) + fin_nwords
363 - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
364 return (int)(*buf & 0xffff);
365 }
366 return -1;
367 }
369}
370
371#endif
The Raw COPPER class ver.2 This class stores data received by COPPER via belle2link Data from all det...
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words
int CheckCRC16(int n, int finesse_num)
check magic words
int * PackDetectorBuf(int *packed_buf_nwords, int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17
Pack data (format ver. = -1 -> Select the latest format version)
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
PostRawCOPPERFormat_v2()
Default constructor.
virtual ~PostRawCOPPERFormat_v2()
Constructor using existing pointer to raw data buffer.
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
void CheckData(int n, unsigned int prev_evenum, unsigned int *cur_evenum, unsigned int prev_copper_ctr, unsigned int *cur_copper_ctr, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
check data contents
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
RawTrailer_v2 tmp_trailer
trailer ( not recorded )
RawHeader_v2 tmp_header
header ( not recorded )
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
struct to contain header information used by RawCOPPERFormat::Packer()
virtual int GetBlockNwords(int n)
get size of a data block
virtual int GetBufferPos(int n)
get position of data block in word
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot C buffer
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17
get # of offset words for FINESSE slot A buffer position
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
int Get1stFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot A buffer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot B
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
int GetTrlNwords()
Set magic word.
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17
Get CRC16 value for an event.
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
Get checksum in RawTrailer.
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot D
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
virtual int GetOffset3rdFINESSE(int n)
get # of offset words for FINESSE slot C buffer position
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot C
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17
get Detector buffer of slot A
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot B buffer
Abstract base class for different kinds of events.