89 int pos_nwords_0, pos_nwords_1;
91 switch (finesse_num) {
111 - SIZE_COPPER_DRIVER_TRAILER
113 nwords = nwords_1 -
m_buffer[ pos_nwords_0 ];
118 sprintf(err_buf,
"Invalid finesse # : %s %s %d\n",
119 __FILE__, __PRETTY_FUNCTION__, __LINE__);
120 printf(
"%s", err_buf); fflush(stdout);
124 if (nwords < 0 || nwords > 1e6) {
126 sprintf(err_buf,
"# of words is strange. %d : %s %s %d\n", nwords,
127 __FILE__, __PRETTY_FUNCTION__, __LINE__);
128 printf(
"%s", err_buf); fflush(stdout);
152 unsigned int prev_evenum,
unsigned int* cur_evenum_rawcprhdr,
153 unsigned int prev_copper_ctr,
unsigned int* cur_copper_ctr,
154 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
159 "This function for format ver.1 is not supported. (n %d preveve %u eve %u prectr %u ctr %u prevrun %u run %u) Exiting...\n %s %s %d\n",
160 n, prev_evenum, *cur_evenum_rawcprhdr, prev_copper_ctr, *cur_copper_ctr,
161 prev_exprunsubrun_no, *cur_exprunsubrun_no,
162 __FILE__, __PRETTY_FUNCTION__, __LINE__);
163 printf(
"%s", err_buf); fflush(stdout);
267 if (finesse_nwords <= 0) {
269 sprintf(err_buf,
"The specified finesse(%d) seems to be empty(nwords = %d). Cannot calculate CRC16. Exiting...\n %s %s %d\n",
270 finesse_num, finesse_nwords, __FILE__, __PRETTY_FUNCTION__, __LINE__);
271 printf(
"%s", err_buf); fflush(stdout);
274 unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, &(
m_buffer[
tmp_header.POS_TTCTIME_TRGTYPE ]), 1);
275 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(
m_buffer[
tmp_header.POS_EVE_NO ]), 1);
276 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(
m_buffer[
tmp_header.POS_TTUTIME ]), 1);
277 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, &(
m_buffer[
tmp_header.POS_EXP_RUN_NO ]), 1);
278 int* buf =
GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + POS_B2L_CTIME;
279 int pos_nwords = finesse_nwords - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER +
280 SIZE_B2LHSLB_TRAILER);
281 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
287 finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_CRC16) + SIZE_B2LHSLB_TRAILER) ;
290 printf(
"#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n",
GetEveNo(n), n, finesse_num,
293 if ((
unsigned short)(*buf & 0xFFFF) != temp_crc16) {
296 printf(
"POST CRC16 error %x %x %d\n", *buf, temp_crc16,
GetFINESSENwords(n, finesse_num));
301 printf(
"%.8x ", temp_buf[ k ]);
302 if ((k + 1) % 10 == 0) printf(
"\n%.8x : ", k);
308 "[DEBUG] [ERROR] B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PostRawCOPPERfromat class. Exiting...\n %s %s %d\n",
309 (
unsigned short)(*buf & 0xFFFF), temp_crc16, __FILE__, __PRETTY_FUNCTION__, __LINE__);
320 int* detector_buf_1st,
int nwords_1st,
321 int* detector_buf_2nd,
int nwords_2nd,
322 int* detector_buf_3rd,
int nwords_3rd,
323 int* detector_buf_4th,
int nwords_4th,
326 int* packed_buf = NULL;
329 int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
330 const int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
333 int length_nwords =
tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER +
tmp_trailer.GetTrlNwords();
335 for (
int i = 0; i < 4; i++) {
336 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
337 length_nwords += nwords[ i ];
338 length_nwords +=
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER
339 + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
343 packed_buf =
new int[ length_nwords ];
344 memset(packed_buf, 0,
sizeof(
int) * length_nwords);
350 packed_buf[
tmp_header.POS_NWORDS ] = length_nwords;
352 packed_buf[
tmp_header.POS_VERSION_HDRNWORDS ] =
360 packed_buf[
tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.
tt_ctime & 0x7FFFFFF) << 4;
365 packed_buf[
tmp_header.POS_OFFSET_1ST_FINESSE ] =
static_cast<int>(
tmp_header.RAWHEADER_NWORDS) + SIZE_COPPER_HEADER;
367 packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_1ST_FINESSE ];
368 if (nwords[ 0 ] > 0) {
369 packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ] +=
370 nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
373 packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ];
374 if (nwords[ 1 ] > 0) {
375 packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ] +=
376 nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
379 packed_buf[
tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ];
380 if (nwords[ 2 ] > 0) {
381 packed_buf[
tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER +
382 SIZE_B2LHSLB_TRAILER;
387 poswords_to += SIZE_COPPER_HEADER;
390 for (
int i = 0; i < 4; i++) {
392 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
395 packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.
eve_num);
396 poswords_to += SIZE_B2LHSLB_HEADER;
399 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.
b2l_ctime & 0x7FFFFFF) << 4;
400 poswords_to += SIZE_B2LFEE_HEADER;
403 memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*
sizeof(
int));
404 poswords_to += nwords[ i ];
407 unsigned int crc16 = 0;
408 packed_buf[ poswords_to + POS_B2LFEE_CRC16 ] = ((0xffff & rawcpr_info.
eve_num) << 16) | (crc16 & 0xffff);
409 poswords_to += SIZE_B2LFEE_TRAILER;
412 poswords_to += SIZE_B2LHSLB_TRAILER;
417 poswords_to += SIZE_COPPER_TRAILER;
423 *packed_buf_nwords = poswords_to;
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 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