Belle II Software development
PostRawCOPPERFormat_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 POSTRAWCOPPERFORMAT_LATEST_H
10#define POSTRAWCOPPERFORMAT_LATEST_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_latest.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_latest(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
62 // virtual int GetBufferPos(int n);
63
64 //
65 // Get information from 13words "COPPER header" attached by COPPER board
66 //
68 /* cppcheck-suppress missingOverride */
69 unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
70
71 //
72 // Get information from "B2link(attached by FEE and HLSB) header"
73 //
75 // virtual int* GetFTSW2Words(int n);
76
78 /* cppcheck-suppress missingOverride */
79 virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
80
82 /* cppcheck-suppress missingOverride */
83 virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
84
85 //
86 // read magic word to check data
87 //
89 /* cppcheck-suppress missingOverride */
90 unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
91
93 /* cppcheck-suppress missingOverride */
94 unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
95
97 /* cppcheck-suppress missingOverride */
98 unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
99
101 /* cppcheck-suppress missingOverride */
102 unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
103
105 /* cppcheck-suppress missingOverride */
106 unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
107
109 /* cppcheck-suppress missingOverride */
110 int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17;
111
113 /* cppcheck-suppress missingOverride */
114 bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
115
117 /* cppcheck-suppress missingOverride */
118 unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
119 unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
120
122 /* cppcheck-suppress missingOverride */
123 unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
124
126 /* cppcheck-suppress missingOverride */
127 unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
128
130 /* cppcheck-suppress missingOverride */
131 void CheckData(int n,
132 unsigned int prev_evenum, unsigned int* cur_evenum,
133 unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
134 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
135
137 /* cppcheck-suppress missingOverride */
138 void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
139
141 int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
142
144 int CheckCRC16(int n, int finesse_num);
145
147 /* cppcheck-suppress missingOverride */
148 int* PackDetectorBuf(int* packed_buf_nwords,
149 int* detector_buf_1st, int nwords_1st,
150 int* detector_buf_2nd, int nwords_2nd,
151 int* detector_buf_3rd, int nwords_3rd,
152 int* detector_buf_4th, int nwords_4th,
153 RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
154
156 /* cppcheck-suppress missingOverride */
157 int* PackDetectorBuf(int* packed_buf_nwords,
158 int* const(&detector_buf_ch)[MAX_PCIE40_CH],
159 int const(&nwords_ch)[MAX_PCIE40_CH],
160 RawCOPPERPackerInfo rawcpr_info) OVERRIDE_CPP17;
161
163 /* cppcheck-suppress missingOverride */
164 int* GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17;
165
168 /* cppcheck-suppress missingOverride */
169 bool CheckOnlineRemovedDataBit(int n, int finesse_num) OVERRIDE_CPP17;
170
171 // Data Format : "B2Link PCIe40 ch Header"
172 enum {
173 POS_B2LHSLB_MAGIC = 0,
174 SIZE_B2LHSLB_HEADER = 1
175 };
176
177
178 // Data Format : "B2Link FEE Header"
179 enum {
180 POS_B2L_CTIME = 0,
181 SIZE_B2LFEE_HEADER = 1
182 };
183
184 // Data Format : B2Link FEE Trailer
185 enum {
186 POS_B2LFEE_ERRCNT_CRC16 = 0,
187 SIZE_B2LFEE_TRAILER = 1
188 };
189
190 //
191 // Data Format : "B2Link HSLB Trailer"
192 //
193 enum {
194 POS_B2LHSLB_TRL_MAGIC = 0,
195 SIZE_B2LHSLB_TRAILER = 1
196 };
197
198
199
200 protected :
202 // ClassDefOverride(PostRawCOPPERFormat_latest, 2);
203
204 };
205
207 {
208 int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
209 return &(m_buffer[ pos_nwords ]);
210 /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
211 /* CheckB2LFEEHeaderVersion(n); */
212 /* #endif */
213 /* int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
214 /* return &(m_buffer[ pos_nwords ]); */
215 }
216
218 {
219 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
220 - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
221 return m_buffer[ pos_nwords ];
222 }
223
224
226 {
227 char err_buf[500];
228 sprintf(err_buf, "[FATAL] This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
229 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
230 printf("%s", err_buf);
231 std::string err_str = err_buf; throw (err_str);
232 return 0;
233 }
234
236 {
237 char err_buf[500];
238 sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
239 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
240 printf("%s", err_buf);
241 std::string err_str = err_buf; throw (err_str);
242 return 0;
243 }
244
246 {
247 char err_buf[500];
248 sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
249 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
250 printf("%s", err_buf);
251 std::string err_str = err_buf; throw (err_str);
252 return 0;
253 }
254
255
257 {
258 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
259
260 // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
261
262 return (unsigned int)(m_buffer[ pos_nwords ]);
263 }
264
266 {
267 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
268 return (unsigned int)(m_buffer[ pos_nwords ]);
269 }
270
271
273 {
274 int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
275 return (unsigned int)(m_buffer[ pos_nwords ]);
276 }
277
278 inline int PostRawCOPPERFormat_latest::GetEventCRC16Value(int n, int finesse_num)
279 {
280 int fin_nwords = GetFINESSENwords(n, finesse_num);
281 if (fin_nwords > 0) {
282 int* buf = GetFINESSEBuffer(n, finesse_num) + fin_nwords
283 - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
284 return (int)(*buf & 0xffff);
285 }
286 return -1;
287 }
288
289 inline int* PostRawCOPPERFormat_latest::GetDetectorBuffer(int n, int finesse_num)
290 {
291 if (GetFINESSENwords(n, finesse_num) > 0) {
292 return (GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER);
293 }
294 return NULL;
295 }
296
297
298 inline int PostRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
299 {
300 int nwords = 0;
301 if (GetFINESSENwords(n, finesse_num) > 0) {
302 nwords = GetFINESSENwords(n, finesse_num)
303 - (static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
304 }
305 return nwords;
306 }
307
309 {
310 if (GetFINESSENwords(n, finesse_num) <= 0) return false;
311 unsigned int* buf = (unsigned int*)GetFINESSEBuffer(n, finesse_num)
312 + (GetFINESSENwords(n, finesse_num) - SIZE_B2LHSLB_TRAILER + POS_B2LHSLB_MAGIC);
313 if (*buf & (1 << ONLINE_REMOVED_DATA)) { return true; }
314 return false;
315 }
316
318}
319
320
321#endif
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"
virtual ~PostRawCOPPERFormat_latest()
Constructor using existing pointer to raw data buffer.
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
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_latest tmp_trailer
trailer ( not recorded )
RawHeader_latest 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
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.
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.
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.