Belle II Software development
PreRawCOPPERFormat_latest.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_LATEST_H
10#define PRERAWCOPPERFORMAT_LATEST_H
11
12// Includes
13#include <rawdata/dataobjects/PostRawCOPPERFormat_latest.h>
14#include <rawdata/CRCCalculator.h>
15
16//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
17
18
19namespace Belle2 {
31 public:
34
36 //PreRawCOPPERFormat_latest(int* bufin, int nwords);
39
40 //
41 // Get position of or pointer to data
42 //
44 // POINTER TO "DETECTOR BUFFER"
45 //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
47
48
50 /* cppcheck-suppress missingOverride */
51 int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
52
54
56 // virtual int GetBufferPos(int n);
57
58 //
59 // Get information from 13words "COPPER header" attached by COPPER board
60 //
62 /* cppcheck-suppress missingOverride */
63 unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
64
65 //
66 // Get information from "B2link(attached by FEE and HLSB) header"
67 //
69 // virtual int* GetFTSW2Words(int n);
70
72 /* cppcheck-suppress missingOverride */
73 virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
74
76 /* cppcheck-suppress missingOverride */
77 virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
78
79 //
80 // read magic word to check data
81 //
83 /* cppcheck-suppress missingOverride */
84 unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
85
87 /* cppcheck-suppress missingOverride */
88 unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
89
91 /* cppcheck-suppress missingOverride */
92 unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
93
95 /* cppcheck-suppress missingOverride */
96 unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
97
99 /* cppcheck-suppress missingOverride */
100 unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
101
103 /* cppcheck-suppress missingOverride */
104 bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
105
107 /* cppcheck-suppress missingOverride */
108 unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
109 unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
110
112 /* cppcheck-suppress missingOverride */
113 unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
114
116 /* cppcheck-suppress missingOverride */
117 unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
118
120 /* cppcheck-suppress missingOverride */
121 void CheckData(int n,
122 unsigned int prev_evenum, unsigned int* cur_evenum,
123 unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
124 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
125
127 /* cppcheck-suppress missingOverride */
128 void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
129
131 int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
132
134 int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
135 // int CalcReducedDataSize(RawDataBlock* raw_datablk);
136
138 void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
139 // void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
140
142 int CalcReducedNwords(int n);
143
145 int CopyReducedBuffer(int n, int* buf_to);
146
148 int CheckCRC16(int n, int finesse_num);
149
151 /* cppcheck-suppress missingOverride */
152 int* PackDetectorBuf(int* packed_buf_nwords,
153 int* detector_buf_1st, int nwords_1st,
154 int* detector_buf_2nd, int nwords_2nd,
155 int* detector_buf_3rd, int nwords_3rd,
156 int* detector_buf_4th, int nwords_4th,
157 RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
158
160 /* cppcheck-suppress missingOverride */
161 int* PackDetectorBuf(int* packed_buf_nwords,
162 int* const(&detector_buf_ch)[MAX_PCIE40_CH],
163 int const(&nwords_ch)[MAX_PCIE40_CH],
164 RawCOPPERPackerInfo rawcpr_info) OVERRIDE_CPP17;
165
167 /* cppcheck-suppress missingOverride */
168 int* GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17;
169
172 /* cppcheck-suppress missingOverride */
173 bool CheckOnlineRemovedDataBit(int n, int finesse_num) OVERRIDE_CPP17;
174
175 //
176 // Data Format : "B2Link HSLB Header"
177 //
178 enum {
179 POS_MAGIC_B2LHSLB = 0,
180 // POS_EVE_CNT_B2LHSLB = 1,
181 SIZE_B2LHSLB_HEADER = 1
182 };
183
184 // Data Format : "B2Link FEE Header"
185 // modified by Nov. 21, 2013, Nakao-san's New firmware?
186 enum {
187 POS_TT_CTIME_TYPE = 0,
188 POS_TT_TAG = 1,
189 POS_TT_UTIME = 2,
190 POS_EXP_RUN = 3,
191 POS_B2L_CTIME = 4,
192 SIZE_B2LFEE_HEADER = 5
193 };
194
195
196 //
197 // Data Format : B2Link FEE Trailer
198 //
199 enum {
200 POS_TT_CTIME_B2LFEE = 0,
201 POS_CHKSUM_B2LFEE = 1,
202 SIZE_B2LFEE_TRAILER = 2
203 };
204
205
206 //
207 // Data Format : "B2Link HSLB Trailer"
208 //
209 enum {
210 POS_CHKSUM_B2LHSLB = 0,
211 SIZE_B2LHSLB_TRAILER = 1
212 };
213
214 //
215 // magic words attached by HSLB
216 //
217 enum {
218 B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
219 B2LHSLB_TRAILER_MAGIC = 0xFF550000
220 };
221
224
225 protected :
227 // ClassDefOverride(PreRawCOPPERFormat_latest, 2);
228
229 };
230
231
233 {
234#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
235 CheckB2LFEEHeaderVersion(n);
236#endif
237 int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
238 return &(m_buffer[ pos_nwords ]);
239 }
240
241
242
244 {
245 char err_buf[500];
246 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
247 __FILE__, __PRETTY_FUNCTION__, __LINE__);
248 printf("[DEBUG] %s\n", err_buf);
249 B2FATAL(err_buf);
250 return 0;
251 }
252
253 inline unsigned int PreRawCOPPERFormat_latest::GetMagicFPGAHeader(int/* n */)
254 {
255 char err_buf[500];
256 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
257 __FILE__, __PRETTY_FUNCTION__, __LINE__);
258 printf("[DEBUG] %s\n", err_buf);
259 B2FATAL(err_buf);
260 return 0;
261 }
262
264 {
265 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
266
267 // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
268
269 return (unsigned int)(m_buffer[ pos_nwords ]);
270 }
271
273 {
274 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
275 return (unsigned int)(m_buffer[ pos_nwords ]);
276 }
277
278
280 {
281 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
282 - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
283 return m_buffer[ pos_nwords ];
284 }
285
286
287 inline unsigned int PreRawCOPPERFormat_latest::GetCOPPERCounter(int/* n */)
288 {
289 char err_buf[500];
290 sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
291 __FILE__, __PRETTY_FUNCTION__, __LINE__);
292 printf("[DEBUG] %s\n", err_buf);
293 B2FATAL(err_buf);
294 return 0;
295 }
296
298 {
299 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
300 return (unsigned int)(m_buffer[ pos_nwords ]);
301 }
302
303 inline int* PreRawCOPPERFormat_latest::GetDetectorBuffer(int n, int finesse_num)
304 {
305 if (GetFINESSENwords(n, finesse_num) > 0) {
306 return (GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER);
307 }
308 return NULL;
309 }
310
311 inline int PreRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
312 {
313 int nwords = 0;
314 if (GetFINESSENwords(n, finesse_num) > 0) {
315 nwords = GetFINESSENwords(n, finesse_num)
316 - (static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
317 }
318 return nwords;
319 }
320
322 {
323 if (GetFINESSENwords(n, finesse_num) <= 0) return false;
324 unsigned int* buf = (unsigned int*)GetFINESSEBuffer(n, finesse_num)
325 + (GetFINESSENwords(n, finesse_num) - SIZE_B2LHSLB_TRAILER + POS_MAGIC_B2LHSLB);
326 if (*buf & (1 << ONLINE_REMOVED_DATA)) { return true; }
327 return false;
328 }
329
331}
332#endif
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
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
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_latest()
Constructor using existing pointer to raw data 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
PostRawCOPPERFormat_latest m_reduced_rawcpr
data fromat after size reduction
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
RawTrailer_latest tmp_trailer
trailer ( not recorded )
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot A buffer position
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
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
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
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
int GetTrlNwords()
Set magic word.
int * GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to detector buffer.
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
int * GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to a FINESSE buffer.
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
get a checksum on trailer
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17
Get the size of a finesse buffer.
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
bool CheckOnlineRemovedDataBit(int n, int finesse_num) OVERRIDE_CPP17
check if this channel's data has been removed on a readout PC for CDC online "masking" True : data co...
Abstract base class for different kinds of events.