Belle II Software development
PreRawCOPPERFormat_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 PRERAWCOPPERFORMAT_V1_H
10#define PRERAWCOPPERFORMAT_V1_H
11
12// Includes
13//#include <framework/datastore/DataStore.h>
14//#include <rawdata/dataobjects/RawDataBlock.h>
15#include <rawdata/dataobjects/PostRawCOPPERFormat_v1.h>
16#include <rawdata/CRCCalculator.h>
17
18//#include <TObject.h>
19//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
20
21
22namespace Belle2 {
34 public:
37
39 //PreRawCOPPERFormat_v1(int* bufin, int nwords);
41 virtual ~PreRawCOPPERFormat_v1();
42
43 //
44 // Get position of or pointer to data
45 //
47 // POINTER TO "DETECTOR BUFFER"
48 //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
50
51
53 /* cppcheck-suppress missingOverride */
54 int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
55
57 /* cppcheck-suppress missingOverride */
58 int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
59
61 /* cppcheck-suppress missingOverride */
62 int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
63
65 /* cppcheck-suppress missingOverride */
66 int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
67
69 /* cppcheck-suppress missingOverride */
70 int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
72
74 // virtual int GetBufferPos(int n);
75
76 //
77 // Get information from 13words "COPPER header" attached by COPPER board
78 //
80 /* cppcheck-suppress missingOverride */
81 unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
82
84 /* cppcheck-suppress missingOverride */
85 int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
86
88 /* cppcheck-suppress missingOverride */
89 int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
90
91 //
92 // Get information from "B2link(attached by FEE and HLSB) header"
93 //
95 // virtual int* GetFTSW2Words(int n);
96
98 /* cppcheck-suppress missingOverride */
99 virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
100
102 /* cppcheck-suppress missingOverride */
103 virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
104
105 //
106 // read magic word to check data
107 //
109 /* cppcheck-suppress missingOverride */
110 unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
111
113 /* cppcheck-suppress missingOverride */
114 unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
115
117 /* cppcheck-suppress missingOverride */
118 unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
119
121 /* cppcheck-suppress missingOverride */
122 unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
123
125 /* cppcheck-suppress missingOverride */
126 unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
127
129 /* cppcheck-suppress missingOverride */
130 bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
131
133 /* cppcheck-suppress missingOverride */
134 unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
135 unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
136
138 /* cppcheck-suppress missingOverride */
139 unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
140
142 /* cppcheck-suppress missingOverride */
143 unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
144
146 /* cppcheck-suppress missingOverride */
147 void CheckData(int n,
148 unsigned int prev_evenum, unsigned int* cur_evenum,
149 unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
150 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
151
153 /* cppcheck-suppress missingOverride */
154 void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
155
157 int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
158
160 int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
161 // int CalcReducedDataSize(RawDataBlock* raw_datablk);
162
164 void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
165 // void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
166
168 int CalcReducedNwords(int n);
169
171 int CopyReducedBuffer(int n, int* buf_to);
172
174 int CheckCRC16(int n, int finesse_num);
175
177 /* cppcheck-suppress missingOverride */
178 int* PackDetectorBuf(int* packed_buf_nwords,
179 int* detector_buf_1st, int nwords_1st,
180 int* detector_buf_2nd, int nwords_2nd,
181 int* detector_buf_3rd, int nwords_3rd,
182 int* detector_buf_4th, int nwords_4th,
183 RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
184
185 //
186 // size of "COPPER front header" and "COPPER trailer"
187 //
189 enum {
190 SIZE_COPPER_DRIVER_HEADER = 7,
191 SIZE_COPPER_DRIVER_TRAILER = 2
192 };
193
194 //
195 // Data Format : "COPPER header"
196 //
197 enum {
198 POS_MAGIC_COPPER_1 = 0,
199 POS_EVE_NUM_COPPER = 1,
200 POS_SUBSYSTEM_ID = 2,
201 POS_CRATE_ID = 3,
202 POS_SLOT_ID = 4,
203 POS_MAGIC_COPPER_2 = 7,
204 POS_DATA_LENGTH = 8,
205 POS_CH_A_DATA_LENGTH = 9,
206 POS_CH_B_DATA_LENGTH = 10,
207 POS_CH_C_DATA_LENGTH = 11,
208 POS_CH_D_DATA_LENGTH = 12,
209
210 SIZE_COPPER_HEADER = 13
211 };
212
213
214
215 //
216 // Data Format : "COPPER Trailer"
217 //
218 enum {
219 POS_MAGIC_COPPER_3 = 0,
220 POS_CHKSUM_COPPER = 1,
221 POS_MAGIC_COPPER_4 = 2,
222
223 SIZE_COPPER_TRAILER = 3
224 };
225
226 //
227 // Data Format : "B2Link HSLB Header"
228 //
229 enum {
230 POS_MAGIC_B2LHSLB = 0,
231 // POS_EVE_CNT_B2LHSLB = 1,
232 SIZE_B2LHSLB_HEADER = 1
233 };
234
235 // Data Format : "B2Link FEE Header"
236 // modified by Nov. 21, 2013, Nakao-san's New firmware?
237 enum {
238 POS_TT_CTIME_TYPE = 0,
239 POS_TT_TAG = 1,
240 POS_TT_UTIME = 2,
241 POS_EXP_RUN = 3,
242 POS_B2L_CTIME = 4,
243 SIZE_B2LFEE_HEADER = 5
244 };
245
246
247 //
248 // Data Format : B2Link FEE Trailer
249 //
250 enum {
251 POS_TT_CTIME_B2LFEE = 0,
252 POS_CHKSUM_B2LFEE = 1,
253 SIZE_B2LFEE_TRAILER = 2
254 };
255
256
257 //
258 // Data Format : "B2Link HSLB Trailer"
259 //
260 enum {
261 POS_CHKSUM_B2LHSLB = 0,
262 SIZE_B2LHSLB_TRAILER = 1
263 };
264
265
266
267 //
268 // COPPER magic words
269 //
270 enum {
271 COPPER_MAGIC_DRIVER_HEADER = 0x7FFF0008,
272 COPPER_MAGIC_FPGA_HEADER = 0xFFFFFAFA,
273 COPPER_MAGIC_FPGA_TRAILER = 0xFFFFF5F5,
274 COPPER_MAGIC_DRIVER_TRAILER = 0x7FFF0009
275 };
276
277
278 //
279 // magic words attached by HSLB
280 //
281 enum {
282 B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
283 B2LHSLB_TRAILER_MAGIC = 0xFF550000
284 };
285
288
289 protected :
291 // ClassDefOverride(PreRawCOPPERFormat_v1, 2);
292
293 };
294
295
297 {
298 int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
299 return pos_nwords;
300 }
301
302
303
305 {
306#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
307 CheckB2LFEEHeaderVersion(n);
308#endif
309 if (Get1stFINESSENwords(n) > 0) {
310 int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
311 return &(m_buffer[ pos_nwords ]);
312 }
313 return NULL;
314 }
315
317 {
318#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
319 CheckB2LFEEHeaderVersion(n);
320#endif
321 if (Get2ndFINESSENwords(n) > 0) {
322 int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
323 return &(m_buffer[ pos_nwords ]);
324 }
325 return NULL;
326 }
327
329 {
330#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
331 CheckB2LFEEHeaderVersion(n);
332#endif
333 if (Get3rdFINESSENwords(n) > 0) {
334 int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
335 return &(m_buffer[ pos_nwords ]);
336 }
337 return NULL;
338 }
339
341 {
342#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
343 CheckB2LFEEHeaderVersion(n);
344#endif
345 if (Get4thFINESSENwords(n) > 0) {
346 int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
347 return &(m_buffer[ pos_nwords ]);
348 }
349 return NULL;
350 }
351
353 {
354#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
355 CheckB2LFEEHeaderVersion(n);
356#endif
357 int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
358 return &(m_buffer[ pos_nwords ]);
359 }
360
361
362
364 {
365 int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_1;
366 return (unsigned int)(m_buffer[ pos_nwords ]);
367 }
368
370 {
371 int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_2;
372 return (unsigned int)(m_buffer[ pos_nwords ]);
373 }
374
376 {
377 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
378
379 // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
380
381 return (unsigned int)(m_buffer[ pos_nwords ]);
382 }
383
385 {
386 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
387 return (unsigned int)(m_buffer[ pos_nwords ]);
388 }
389
390
391 inline unsigned int PreRawCOPPERFormat_v1::GetDriverChkSum(int n)
392 {
393 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
394 - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
395 return m_buffer[ pos_nwords ];
396 }
397
398
400 {
401 int pos_nwords = GetBufferPos(n) + POS_EVE_NUM_COPPER + tmp_header.RAWHEADER_NWORDS;
402 return (unsigned int)(m_buffer[ pos_nwords ]);
403 }
404
405
406
407
409 {
410 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
411 return (unsigned int)(m_buffer[ pos_nwords ]);
412 }
413
414
415
416
417
419}
420#endif
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words of B2link HSLB header/trailer
int CopyReducedBuffer(int n, int *buf_to)
copy data to reduced buffer
int CheckCRC16(int n, int finesse_num)
check CRC16 in B2LFEE trailer
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)
int CalcReducedNwords(int n)
calculate reduced data size
PostRawCOPPERFormat_v1 m_reduced_rawcpr
data fromat after size reduction
PreRawCOPPERFormat_v1()
Default constructor.
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
void CopyReducedData(int *bufin, int nwords, int num_events, int num_nodes, int *buf_to, int *nwords_to)
reduce and merge header/trailer
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"
int CalcReducedDataSize(int *bufin, int nwords, int num_events, int num_nodes)
reduce and merge header/trailer
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
virtual ~PreRawCOPPERFormat_v1()
Constructor using existing pointer to raw data buffer.
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_v1 tmp_trailer
trailer ( not recorded )
RawHeader_v1 tmp_header
header ( not recorded )
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
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
get a checksum on trailer
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.