9#include <rawdata/dataobjects/PostRawCOPPERFormat_v2.h>
33 - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
42 sprintf(err_buf,
"[FATAL] This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
43 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
44 printf(
"[DEBUG] %s\n", err_buf);
52 int pos_nwords_0, pos_nwords_1;
54 switch (finesse_num) {
74 - SIZE_COPPER_DRIVER_TRAILER
76 nwords = nwords_1 -
m_buffer[ pos_nwords_0 ];
81 sprintf(err_buf,
"[FATAL] Invalid finesse # : %s %s %d\n",
82 __FILE__, __PRETTY_FUNCTION__, __LINE__);
83 printf(
"[DEBUG] %s\n", err_buf);
87 if (nwords < 0 || nwords > 1e6) {
91 sprintf(err_buf,
"[FATAL] %s ch=%d : ERROR_EVENT : # of words is strange. %d : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
92 hostname, finesse_num,
95 __FILE__, __PRETTY_FUNCTION__, __LINE__);
96 printf(
"[DEBUG] %s\n", err_buf);
113 "[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",
117 __FILE__, __PRETTY_FUNCTION__, __LINE__);
118 printf(
"[DEBUG] %s\n", err_buf);
126 unsigned int prev_evenum,
unsigned int* cur_evenum_rawcprhdr,
127 unsigned int prev_copper_ctr,
unsigned int* cur_copper_ctr,
128 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
136 *cur_evenum_rawcprhdr =
GetEveNo(n);
139 if (prev_exprunsubrun_no == *cur_exprunsubrun_no) {
140 if ((
unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
141 sprintf(err_buf,
"CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
142 n, prev_evenum, *cur_evenum_rawcprhdr,
143 __FILE__, __PRETTY_FUNCTION__, __LINE__);
158 "[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",
162 __FILE__, __PRETTY_FUNCTION__, __LINE__);
168 printf(
"[DEBUG] %s\n", err_buf);
169 printf(
"[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
171 printf(
"Print out variables to reduce unused-variables-warnings : %u %u\n", prev_copper_ctr, *cur_copper_ctr);
185 "[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",
189 __FILE__, __PRETTY_FUNCTION__, __LINE__);
190 printf(
"[DEBUG] %s\n", err_buf);
198 sprintf(err_buf,
"[FATAL] This function is not supported (block %d). Exiting...\n%s %s %d\n",
199 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
200 printf(
"[DEBUG] %s\n", err_buf);
205 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
209 sprintf(err_buf,
"[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
210 __FILE__, __PRETTY_FUNCTION__, __LINE__);
211 printf(
"Print out variables to reduce unused-variables-warnings : %u %u %u %u\n",
212 m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no);
213 printf(
"[DEBUG] %s\n", err_buf);
221 sprintf(err_buf,
"[FATAL] This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
222 __FILE__, __PRETTY_FUNCTION__, __LINE__);
223 printf(
"Print out variables to reduce unused-variables-warnings : %p %d\n", finesse_buf, finesse_nwords);
224 printf(
"[DEBUG] %s\n", err_buf);
235 if (finesse_nwords <= 0) {
240 "[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",
241 hostname, finesse_num,
242 65 + finesse_num, finesse_nwords,
244 __FILE__, __PRETTY_FUNCTION__, __LINE__);
245 printf(
"%s", err_buf); fflush(stdout);
252 unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, &(copper_buf[
tmp_header.POS_TTCTIME_TRGTYPE ]), 1);
253 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[
tmp_header.POS_EVE_NO ]), 1);
254 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[
tmp_header.POS_TTUTIME ]), 1);
255 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(copper_buf[
tmp_header.POS_EXP_RUN_NO ]), 1);
256 int* buf =
GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + POS_B2L_CTIME;
257 int pos_nwords = finesse_nwords - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER +
258 SIZE_B2LHSLB_TRAILER);
259 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
265 finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
268 printf(
"#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n",
GetEveNo(n), n, finesse_num,
273 if ((
unsigned short)(*buf & 0xFFFF) != temp_crc16) {
276 int copper_nwords = copper_buf[
tmp_header.POS_NWORDS ];
287 if ((
GetNodeID(n) & DETECTOR_MASK) == ARICH_ID) {
289 "[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",
290 hostname, finesse_num,
293 __FILE__, __PRETTY_FUNCTION__, __LINE__);
294 printf(
"%s", err_buf); fflush(stdout);
298 "[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",
299 hostname, finesse_num,
302 __FILE__, __PRETTY_FUNCTION__, __LINE__);
303 printf(
"%s", err_buf); fflush(stdout);
320 "[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",
321 hostname, finesse_num,
324 __FILE__, __PRETTY_FUNCTION__, __LINE__);
325 printf(
"%s", err_buf); fflush(stdout);
333 ^= copper_buf[
tmp_header.POS_TRUNC_MASK_DATATYPE ];
336 ^= copper_buf[
tmp_header.POS_TRUNC_MASK_DATATYPE ];
346 int* detector_buf_1st,
int nwords_1st,
347 int* detector_buf_2nd,
int nwords_2nd,
348 int* detector_buf_3rd,
int nwords_3rd,
349 int* detector_buf_4th,
int nwords_4th,
352 int* packed_buf = NULL;
355 int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
356 const int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
361 for (
int i = 0; i < 4; i++) {
362 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
363 length_nwords += nwords[ i ];
364 length_nwords +=
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER
365 + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
369 packed_buf =
new int[ length_nwords ];
370 memset(packed_buf, 0,
sizeof(
int) * length_nwords);
377 packed_buf[
tmp_header.POS_NWORDS ] = length_nwords;
378 packed_buf[
tmp_header.POS_VERSION_HDRNWORDS ] =
385 packed_buf[
tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.
tt_ctime & 0x7FFFFFF) << 4;
390 packed_buf[
tmp_header.POS_OFFSET_1ST_FINESSE ] =
static_cast<int>(
tmp_header.RAWHEADER_NWORDS) + SIZE_COPPER_HEADER;
392 packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_1ST_FINESSE ];
393 if (nwords[ 0 ] > 0) {
394 packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ] +=
395 nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
398 packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ];
399 if (nwords[ 1 ] > 0) {
400 packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ] +=
401 nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
404 packed_buf[
tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ];
405 if (nwords[ 2 ] > 0) {
406 packed_buf[
tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER +
407 SIZE_B2LHSLB_TRAILER;
412 poswords_to += SIZE_COPPER_HEADER;
415 for (
int i = 0; i < 4; i++) {
417 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
420 packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.
eve_num);
421 poswords_to += SIZE_B2LHSLB_HEADER;
424 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.
b2l_ctime & 0x7FFFFFF) << 4;
425 poswords_to += SIZE_B2LFEE_HEADER;
428 memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*
sizeof(
int));
429 poswords_to += nwords[ i ];
432 unsigned int crc16 = 0;
433 packed_buf[ poswords_to + POS_B2LFEE_ERRCNT_CRC16 ] = crc16 &
435 poswords_to += SIZE_B2LFEE_TRAILER;
438 poswords_to += SIZE_B2LHSLB_TRAILER;
443 poswords_to += SIZE_COPPER_TRAILER;
449 *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_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
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 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 GetSubRunNo(int n) OVERRIDE_CPP17
get run # (14bit)
Abstract base class for different kinds of events.