9#include <rawdata/dataobjects/PostRawCOPPERFormat_latest.h>
30 sprintf(err_buf,
"[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
31 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
32 printf(
"[DEBUG] %s\n", err_buf);
47 "[FATAL] %s ch=%d : ERROR_EVENT : No event # in B2LFEE header. (block %d) Exiting... : eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
51 __FILE__, __PRETTY_FUNCTION__, __LINE__);
52 printf(
"[DEBUG] %s\n", err_buf);
60 unsigned int prev_evenum,
unsigned int* cur_evenum_rawcprhdr,
61 unsigned int prev_copper_ctr,
unsigned int* cur_copper_ctr,
62 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
73 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
74 if ((
unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
75 sprintf(err_buf,
"CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
76 n, prev_evenum, *cur_evenum_rawcprhdr,
77 __FILE__, __PRETTY_FUNCTION__, __LINE__);
92 "[FATAL] %s ch=%d : ERROR_EVENT : checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
96 __FILE__, __PRETTY_FUNCTION__, __LINE__);
102 printf(
"[DEBUG] %s\n", err_buf);
103 printf(
"[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
105 printf(
"Print out variables to reduce unused-variables-warnings : %u %u\n", prev_copper_ctr, *cur_copper_ctr);
119 "[FATAL] %s ch=%d : ERROR_EVENT : No magic word # in COPPER header (block %d). Exiting...: eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
123 __FILE__, __PRETTY_FUNCTION__, __LINE__);
124 printf(
"[DEBUG] %s\n", err_buf);
132 sprintf(err_buf,
"[FATAL] This function is not supported (block %d). Exiting...\n%s %s %d\n",
133 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
134 printf(
"[DEBUG] %s\n", err_buf);
139 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
143 sprintf(err_buf,
"[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
144 __FILE__, __PRETTY_FUNCTION__, __LINE__);
145 printf(
"Print out variables to reduce unused-variables-warnings : %u %u %u %u\n",
146 m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no);
147 printf(
"[DEBUG] %s\n", err_buf);
155 sprintf(err_buf,
"[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
156 __FILE__, __PRETTY_FUNCTION__, __LINE__);
157 printf(
"Print out variables to reduce unused-variables-warnings : %p %d\n", finesse_buf, finesse_nwords);
158 printf(
"[DEBUG] %s\n", err_buf);
169 if (finesse_nwords <= 0) {
174 "[FATAL] %s ch=%d : ERROR_EVENT : The specified finesse(%c) seems to be empty(nwords = %d). Cannot calculate CRC16. Exiting...: eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
175 hostname, finesse_num,
176 65 + finesse_num, finesse_nwords,
178 __FILE__, __PRETTY_FUNCTION__, __LINE__);
179 printf(
"%s", err_buf); fflush(stdout);
186 unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, &(copper_buf[
tmp_header.POS_TTCTIME_TRGTYPE ]), 1);
187 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[
tmp_header.POS_EVE_NO ]), 1);
188 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[
tmp_header.POS_TTUTIME ]), 1);
189 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[
tmp_header.POS_EXP_RUN_NO ]), 1);
190 int* buf =
GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + POS_B2L_CTIME;
191 int pos_nwords = finesse_nwords - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER +
192 SIZE_B2LHSLB_TRAILER);
193 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
199 finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
202 printf(
"#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n",
GetEveNo(n), n, finesse_num,
207 if ((
unsigned short)(*buf & 0xFFFF) != temp_crc16) {
210 int copper_nwords = copper_buf[
tmp_header.POS_NWORDS ];
220 if ((
GetNodeID(n) & DETECTOR_MASK) == ARICH_ID) {
222 "[WARNING] %s ch=%d : ARICH : POST B2link event CRC16 error with B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x : This error is ignored and the error event will be recorded in .sroot file acording to request from ARICH group: slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
223 hostname, finesse_num,
226 __FILE__, __PRETTY_FUNCTION__, __LINE__);
227 printf(
"%s", err_buf); fflush(stdout);
231 "[FATAL] %s ch=%d : ERROR_EVENT : POST B2link event CRC16 error with B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x : slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
232 hostname, finesse_num,
235 __FILE__, __PRETTY_FUNCTION__, __LINE__);
236 printf(
"%s", err_buf); fflush(stdout);
253 "[FATAL] %s ch=%d : ERROR_EVENT : POST B2link event CRC16 error without B2link Packet CRC error. data(%x) calc(%x) fns nwords %d type 0x%.8x: slot%c eve 0x%x exp %d run %d sub %d\n%s %s %d\n",
254 hostname, finesse_num,
257 __FILE__, __PRETTY_FUNCTION__, __LINE__);
258 printf(
"%s", err_buf); fflush(stdout);
266 ^= copper_buf[
tmp_header.POS_TRUNC_MASK_DATATYPE ];
269 ^= copper_buf[
tmp_header.POS_TRUNC_MASK_DATATYPE ];
286 sprintf(err_buf,
"[FATAL] This function is not supported. (%u) Exiting...: \n%s %s %d\n",
288 __FILE__, __PRETTY_FUNCTION__, __LINE__);
289 printf(
"[DEBUG] %s\n", err_buf);
296 int*
const(&detector_buf_ch)[MAX_PCIE40_CH],
297 int const(&nwords_ch)[MAX_PCIE40_CH],
300 int* packed_buf = NULL;
306 for (
int i = 0; i < MAX_PCIE40_CH; i++) {
307 if (detector_buf_ch[ i ] == NULL || nwords_ch[ i ] <= 0)
continue;
308 length_nwords += nwords_ch[ i ];
309 length_nwords +=
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
313 packed_buf =
new int[ length_nwords ];
314 memset(packed_buf, 0,
sizeof(
int) * length_nwords);
321 packed_buf[
tmp_header.POS_NWORDS ] = length_nwords;
322 packed_buf[
tmp_header.POS_VERSION_HDRNWORDS ] =
329 packed_buf[
tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.
tt_ctime & 0x7FFFFFF) << 4;
336 for (
int i = 1; i < MAX_PCIE40_CH; i++) {
338 if (nwords_ch[ ch - 1 ] == 0) {
339 packed_buf[
tmp_header.POS_CH_POS_TABLE + ch ] = packed_buf[
tmp_header.POS_CH_POS_TABLE + (ch - 1) ];
341 packed_buf[
tmp_header.POS_CH_POS_TABLE + ch ] = packed_buf[
tmp_header.POS_CH_POS_TABLE + (ch - 1) ] +
342 nwords_ch[ ch - 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
348 for (
int i = 0; i < MAX_PCIE40_CH; i++) {
349 if (detector_buf_ch[ i ] == NULL || nwords_ch[ i ] <= 0)
continue;
352 packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.
eve_num);
353 poswords_to += SIZE_B2LHSLB_HEADER;
356 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.
b2l_ctime & 0x7FFFFFF) << 4;
357 poswords_to += SIZE_B2LFEE_HEADER;
360 memcpy(packed_buf + poswords_to, detector_buf_ch[ i ], nwords_ch[ i ]*
sizeof(
int));
361 poswords_to += nwords_ch[ i ];
364 unsigned int crc16 = 0;
365 packed_buf[ poswords_to + POS_B2LFEE_ERRCNT_CRC16 ] =
366 ((0xffff & rawcpr_info.
eve_num) << 16) | (crc16 &
368 poswords_to += SIZE_B2LFEE_TRAILER;
371 packed_buf[ poswords_to + POS_B2LHSLB_TRL_MAGIC ] = 0xff550000;
372 poswords_to += SIZE_B2LHSLB_TRAILER;
380 *packed_buf_nwords = poswords_to;
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_latest()
Default constructor.
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
struct to contain header information used by RawCOPPERFormat::Packer()
unsigned int b2l_ctime
32bit unitx time at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user ...
unsigned int eve_num
Run # and subrun # ( 22bit )
unsigned int tt_ctime
Node ID (32bit)
unsigned int tt_utime
27bit clock ticks at trigger timing distributed by FTSW. For details, see Nakao-san's belle2link user...
unsigned int node_id
Event Number (32bit)
unsigned int run_subrun_num
Experiment number (10bit)
unsigned int exp_num
Experiment number (10bit)
unsigned int GetEveNo(int n) OVERRIDE_CPP17
get subrun #(8bit)
int GetHdrNwords()
get contents of header
int GetTrlNwords()
Set magic word.
unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17
get Experimental # from header
int * GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to a FINESSE buffer.
int GetExpNo(int n) OVERRIDE_CPP17
get Experimental # from header
unsigned int GetChksum()
Set # of trailer words.
void SetBuffer(int *bufin)
return buffer
int GetRunNo(int n) OVERRIDE_CPP17
Exp# (10bit) run# (14bit) restart # (8bit)
unsigned int GetNodeID(int n) OVERRIDE_CPP17
get node-ID from data
int * GetRawTrlBufPtr(int n) OVERRIDE_CPP17
get buffer pointer of rawcopper trailer
int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17
Get the size of a finesse buffer.
int GetSubRunNo(int n) OVERRIDE_CPP17
get run # (14bit)
Abstract base class for different kinds of events.