9#include <rawdata/dataobjects/PostRawCOPPERFormat_v1.h>
69 - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
79 sprintf(err_buf,
"This function is not supported.(block %d) Exiting...: \n%s %s %d\n",
80 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
81 printf(
"%s", err_buf); fflush(stdout);
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);
142 sprintf(err_buf,
"No event # in B2LFEE header. (block %d) Exiting...\n%s %s %d\n",
143 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
144 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);
220 sprintf(err_buf,
"No magic word # in COPPER header (block %d). Exiting...\n%s %s %d\n",
221 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
222 printf(
"%s", err_buf); fflush(stdout);
230 sprintf(err_buf,
"This function is not supported (block %d). Exiting...\n%s %s %d\n",
231 n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
232 printf(
"%s", err_buf); fflush(stdout);
238 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
241 sprintf(err_buf,
"This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
242 __FILE__, __PRETTY_FUNCTION__, __LINE__);
243 printf(
"Print out variables to reduce unused-variables-warnings : %u %u %u %u\n",
244 m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no);
245 printf(
"%s", err_buf); fflush(stdout);
253 sprintf(err_buf,
"This function should be called by PrePostRawCOPPERFormat_***. Exiting...\n %s %s %d\n",
254 __FILE__, __PRETTY_FUNCTION__, __LINE__);
255 printf(
"Print out variables to reduce unused-variables-warnings : %p %d\n", finesse_buf, finesse_nwords);
256 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 };
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 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_v1()
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
PostRawCOPPERFormat_v1()
Default constructor.
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.
Abstract base class for different kinds of events.