9 #include <rawdata/dataobjects/PostRawCOPPERFormat_v1.h>
21 PostRawCOPPERFormat_v1::PostRawCOPPERFormat_v1()
25 PostRawCOPPERFormat_v1::~PostRawCOPPERFormat_v1()
63 int PostRawCOPPERFormat_v1::GetDetectorNwords(
int n,
int finesse_num)
67 if (GetFINESSENwords(n, finesse_num) > 0) {
68 nwords = GetFINESSENwords(n, finesse_num)
69 - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
76 unsigned int PostRawCOPPERFormat_v1::CalcDriverChkSum(
int n)
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);
87 int PostRawCOPPERFormat_v1::GetFINESSENwords(
int n,
int finesse_num)
89 int pos_nwords_0, pos_nwords_1;
91 switch (finesse_num) {
93 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_1ST_FINESSE;
94 pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
95 nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
98 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_2ND_FINESSE;
99 pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
100 nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
103 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_3RD_FINESSE;
104 pos_nwords_1 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
105 nwords = m_buffer[ pos_nwords_1 ] - m_buffer[ pos_nwords_0 ];
108 pos_nwords_0 = GetBufferPos(n) + tmp_header.POS_OFFSET_4TH_FINESSE;
110 int nwords_1 = GetBlockNwords(n)
111 - SIZE_COPPER_DRIVER_TRAILER
112 - tmp_trailer.GetTrlNwords();
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);
139 unsigned int PostRawCOPPERFormat_v1::GetB2LFEE32bitEventNumber(
int n)
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);
151 void PostRawCOPPERFormat_v1::CheckData(
int n,
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);
217 bool PostRawCOPPERFormat_v1::CheckCOPPERMagic(
int n)
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);
227 void PostRawCOPPERFormat_v1::CheckUtimeCtimeTRGType(
int n)
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);
237 unsigned int PostRawCOPPERFormat_v1::FillTopBlockRawHeader(
unsigned int m_node_id,
unsigned int prev_eve32,
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);
250 int PostRawCOPPERFormat_v1::CheckB2LHSLBMagicWords(
int* finesse_buf,
int finesse_nwords)
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);
260 int PostRawCOPPERFormat_v1::CheckCRC16(
int n,
int finesse_num)
266 int finesse_nwords = GetFINESSENwords(n, finesse_num);
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 - (SIZE_B2LHSLB_HEADER + POS_B2L_CTIME + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER);
280 temp_crc16 = CalcCRC16LittleEndian(temp_crc16, buf, pos_nwords);
285 buf = GetFINESSEBuffer(n, finesse_num) + GetFINESSENwords(n,
286 finesse_num) - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_CRC16) + SIZE_B2LHSLB_TRAILER) ;
288 if (GetEveNo(n) % 10000 == 0) {
289 printf(
"#### PostRawCOPPER : Eve %.8x block %d finesse %d B2LCRC16 %.8x calculated CRC16 %.8x\n", GetEveNo(n), n, finesse_num,
292 if ((
unsigned short)(*buf & 0xFFFF) != temp_crc16) {
294 PrintData(m_buffer, m_nwords);
295 printf(
"POST CRC16 error %x %x %d\n", *buf , temp_crc16, GetFINESSENwords(n, finesse_num));
297 int* temp_buf = GetFINESSEBuffer(n, finesse_num);
299 for (
int k = 0; k < GetFINESSENwords(n, finesse_num); k++) {
300 printf(
"%.8x ", temp_buf[ k ]);
301 if ((k + 1) % 10 == 0) printf(
"\n%.8x : ", k);
307 "[DEBUG] [ERROR] B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PostRawCOPPERfromat class. Exiting...\n %s %s %d\n",
308 (
unsigned short)(*buf & 0xFFFF), temp_crc16, __FILE__, __PRETTY_FUNCTION__, __LINE__);
318 int* PostRawCOPPERFormat_v1::PackDetectorBuf(
int* packed_buf_nwords,
319 int* detector_buf_1st,
int nwords_1st,
320 int* detector_buf_2nd,
int nwords_2nd,
321 int* detector_buf_3rd,
int nwords_3rd,
322 int* detector_buf_4th,
int nwords_4th,
325 int* packed_buf = NULL;
328 int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
329 int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
332 int length_nwords = tmp_header.GetHdrNwords() + SIZE_COPPER_HEADER + SIZE_COPPER_TRAILER + tmp_trailer.GetTrlNwords();
334 for (
int i = 0; i < 4; i++) {
335 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
336 length_nwords += nwords[ i ];
337 length_nwords += SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER
338 + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
342 packed_buf =
new int[ length_nwords ];
343 memset(packed_buf, 0,
sizeof(
int) * length_nwords);
348 tmp_header.SetBuffer(packed_buf);
349 packed_buf[ tmp_header.POS_NWORDS ] = length_nwords;
351 packed_buf[ tmp_header.POS_VERSION_HDRNWORDS ] =
353 | ((DATA_FORMAT_VERSION << tmp_header.FORMAT_VERSION_SHIFT) & tmp_header.FORMAT_VERSION__MASK)
354 | tmp_header.RAWHEADER_NWORDS;
356 packed_buf[ tmp_header.POS_EXP_RUN_NO ] = (rawcpr_info.
exp_num << 22)
358 packed_buf[ tmp_header.POS_EVE_NO ] = rawcpr_info.
eve_num;
359 packed_buf[ tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.
tt_ctime & 0x7FFFFFF) << 4;
360 packed_buf[ tmp_header.POS_TTUTIME ] = rawcpr_info.
tt_utime;
361 packed_buf[ tmp_header.POS_NODE_ID ] = rawcpr_info.
node_id;
364 packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ] = tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
366 packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_1ST_FINESSE ];
367 if (nwords[ 0 ] > 0) {
368 packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ] +=
369 nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
372 packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_2ND_FINESSE ];
373 if (nwords[ 1 ] > 0) {
374 packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ] +=
375 nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
378 packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[ tmp_header.POS_OFFSET_3RD_FINESSE ];
379 if (nwords[ 2 ] > 0) {
380 packed_buf[ tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER +
381 SIZE_B2LHSLB_TRAILER;
383 poswords_to += tmp_header.GetHdrNwords();
386 poswords_to += SIZE_COPPER_HEADER;
389 for (
int i = 0; i < 4; i++) {
391 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
394 packed_buf[ poswords_to + POS_B2LHSLB_MAGIC ] = 0xffaa0000 | (0xffff & rawcpr_info.
eve_num);
395 poswords_to += SIZE_B2LHSLB_HEADER;
398 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.
b2l_ctime & 0x7FFFFFF) << 4;
399 poswords_to += SIZE_B2LFEE_HEADER;
402 memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*
sizeof(
int));
403 poswords_to += nwords[ i ];
406 unsigned int crc16 = 0;
407 packed_buf[ poswords_to + POS_B2LFEE_CRC16 ] = ((0xffff & rawcpr_info.
eve_num) << 16) | (crc16 & 0xffff);
408 poswords_to += SIZE_B2LFEE_TRAILER;
411 poswords_to += SIZE_B2LHSLB_TRAILER;
416 poswords_to += SIZE_COPPER_TRAILER;
419 packed_buf[ poswords_to + tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
420 poswords_to += tmp_trailer.GetTrlNwords();
422 *packed_buf_nwords = poswords_to;
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)
Abstract base class for different kinds of events.