9#include <rawdata/dataobjects/PreRawCOPPERFormat_v1.h>
76 -
tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
77 unsigned int chksum = 0;
78 for (
int i = min; i < max; i++) {
92 - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
105 "[ERROR] COPPER's magic word is invalid. Exiting... Maybe it is due to data corruption or different version of the data format.\n %s %s %d\n",
106 __FILE__, __PRETTY_FUNCTION__, __LINE__);
107 printf(
"%s", err_buf); fflush(stdout);
111 switch (finesse_num) {
126 sprintf(err_buf,
"Specifined FINESSE number( = %d ) is invalid. Exiting...\n %s %s %d\n",
127 finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
128 printf(
"%s", err_buf); fflush(stdout);
139#ifndef READ_OLD_B2LFEE_FORMAT_FILE
142 unsigned int eve_num = 0;
145 for (
int i = 0; i < 4 ; i++) {
150 if (flag != 1) eve_num = eve[ i ];
151 if (eve_num != eve[ i ]) err_flag = 1;
159 sprintf(err_buf,
"No HSLB data in COPPER data. Exiting...\n%s %s %d\n",
160 __FILE__, __PRETTY_FUNCTION__, __LINE__);
161 printf(
"%s", err_buf); fflush(stdout);
168 sprintf(err_buf,
"CORRUPTED DATA: Different event number over HSLBs : slot A 0x%x : B 0x%x :C 0x%x : D 0x%x\n%s %s %d\n",
169 eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
170 __FILE__, __PRETTY_FUNCTION__, __LINE__);
171 printf(
"[DEBUG] [ERROR] %s\n", err_buf); fflush(stdout);
181 sprintf(err_buf,
"You need comment out READ_OLD_B2LFEE_FORMAT_FILE if you are handling a new data format\n%s %s %d\n",
182 __FILE__, __PRETTY_FUNCTION__, __LINE__);
183 printf(
"%s", err_buf); fflush(stdout);
192 unsigned int prev_evenum,
unsigned int* cur_evenum_rawcprhdr,
193 unsigned int prev_copper_ctr,
unsigned int* cur_copper_ctr,
194 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
199 "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",
200 n, prev_evenum, *cur_evenum_rawcprhdr, prev_copper_ctr, *cur_copper_ctr,
201 prev_exprunsubrun_no, *cur_exprunsubrun_no,
202 __FILE__, __PRETTY_FUNCTION__, __LINE__);
203 printf(
"%s", err_buf); fflush(stdout);
373#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
374 CheckB2LFEEHeaderVersion(n);
378 unsigned int temp_utime = 0, temp_ctime_trgtype = 0;
379 unsigned int utime[4], ctime_trgtype[4];
380 memset(utime, 0,
sizeof(utime));
381 memset(ctime_trgtype, 0,
sizeof(ctime_trgtype));
383 for (
int i = 0; i < 4; i++) {
386 SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
388 SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
390 temp_ctime_trgtype = ctime_trgtype[ i ];
391 temp_utime = utime[ i ];
394 if (temp_ctime_trgtype != ctime_trgtype[ i ]
395 || temp_utime != utime[ i ]) {
403 for (
int i = 0; i < 4; i++) {
404 printf(
"[DEBUG] FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x\n",
408 sprintf(err_buf,
"CORRUPTED DATA: mismatch over FINESSEs. Exiting...\n %s %s %d\n",
409 __FILE__, __PRETTY_FUNCTION__, __LINE__);
410 printf(
"%s", err_buf); fflush(stdout);
418 unsigned int prev_exprunsubrun_no,
unsigned int* cur_exprunsubrun_no)
423 "This function for format ver.1 is not supported. (node %.8x preveve %u prevrun %u currun %u ) Exiting...\n %s %s %d\n",
424 m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no,
425 __FILE__, __PRETTY_FUNCTION__, __LINE__);
426 printf(
"%s", err_buf); fflush(stdout);
677#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
678void PreRawCOPPERFormat_v1::CheckB2LFEEHeaderVersion(
int n)
681 for (
int i = 0; i < 4; i++) {
684 if ((temp_buf[ 3 ] & 0x40000000) == 0) {
688 printf(
"[DEBUG] \033[31m");
689 printf(
"[DEBUG] ===Firmware ver. ERROR===\n ");
690 printf(
"[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
691 printf(
"[DEBUG] If you are going to take data now, Please update the firmware.\n");
692 printf(
"[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
693 printf(
"[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before svn rev. 7419\n");
694 printf(
"[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
695 printf(
"[DEBUG] Sorry for inconvenience.\n");
696 printf(
"[DEBUG] \033[0m");
699 sprintf(err_buf,
"FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
700 __FILE__, __PRETTY_FUNCTION__, __LINE__);
701 printf(
"%s", err_buf); fflush(stdout);
714 sprintf(err_buf,
"PreRawCOPPERFormat_v1 contains no FINESSE data. Exiting...\n %s %s %d\n",
715 __FILE__, __PRETTY_FUNCTION__, __LINE__);
716 printf(
"%s", err_buf); fflush(stdout);
734 rawcpr_fmt.
SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
736 int reduced_nwords = 0;
738 int num_nodes_in_sendblock = rawcpr_fmt.
GetNumNodes();
739 for (
int l = 0; l < num_nodes_in_sendblock; l++) {
740 int entry_id = l + k * num_nodes_in_sendblock;
746 int temp_delete_flag = 0, temp_num_eve = 1, temp_num_nodes = 1;
751 temp_delete_flag, temp_num_eve,
757 return reduced_nwords;
769 rawcpr_fmt.
SetBuffer(bufin, nwords, delete_flag, num_events, num_nodes);
771 int pos_nwords_to = 0;
773 int num_nodes_in_sendblock = rawcpr_fmt.
GetNumNodes();
774 for (
int l = 0; l < num_nodes_in_sendblock; l++) {
775 int entry_id = l + k * num_nodes_in_sendblock;
778 rawcpr_fmt.
CopyBlock(entry_id, buf_to + pos_nwords_to);
796 *nwords_to = pos_nwords_to;
812 for (
int j = 0; j < 4; j++) {
815 if (finesse_nwords > 0) {
822 - (
static_cast<int>(SIZE_B2LHSLB_HEADER) -
m_reduced_rawcpr.SIZE_B2LHSLB_HEADER)
823 - (
static_cast<int>(SIZE_B2LFEE_HEADER) -
m_reduced_rawcpr.SIZE_B2LFEE_HEADER)
824 - (
static_cast<int>(SIZE_B2LFEE_TRAILER) -
m_reduced_rawcpr.SIZE_B2LFEE_TRAILER)
825 - (
static_cast<int>(SIZE_B2LHSLB_TRAILER) -
m_reduced_rawcpr.SIZE_B2LHSLB_TRAILER);
847 int* buf_from = NULL;
849 int pos_nwords_to = 0;
857 copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
860 buf_to[
tmp_header.POS_VERSION_HDRNWORDS ] &= 0xFFFF7FFF;
867 int pos_nwords_finesse[ 4 ];
868 for (
int j = 0; j < 4; j++) {
869 pos_nwords_finesse[ j ] = pos_nwords_to;
877 buf_to[ pos_nwords_to ] = finesse_buf[ POS_MAGIC_B2LHSLB ];
883 + SIZE_B2LHSLB_HEADER
887 if (finesse_nwords - SIZE_B2LHSLB_HEADER - SIZE_B2LFEE_HEADER
888 - SIZE_B2LFEE_TRAILER - SIZE_B2LHSLB_TRAILER < 0) {
891 "[ERROR] Finesse buffer size is too small( %d words < %d words). May be the data are corrupted. Exiting...\n %s %s %d\n",
892 finesse_nwords,
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER,
893 __FILE__, __PRETTY_FUNCTION__, __LINE__);
894 printf(
"%s", err_buf); fflush(stdout);
900 - SIZE_B2LHSLB_HEADER
902 - SIZE_B2LFEE_TRAILER
903 - SIZE_B2LHSLB_TRAILER;
906 copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
909 buf_to[ pos_nwords_to ] =
910 finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER
911 - (SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) ];
925 copyData(buf_to, &pos_nwords_to, buf_from, copy_nwords, nwords_buf_to);
928 if (pos_nwords_to != nwords_buf_to) {
930 sprintf(err_buf,
"Buffer overflow. Exiting... %d %d\n", pos_nwords_to, nwords_buf_to);
931 printf(
"%s", err_buf); fflush(stdout);
955 sprintf(err_buf,
"Invalid data block numbers.(# of events %d, # of nodes %d) Exiting...\n",
957 printf(
"%s", err_buf); fflush(stdout);
965 int nonzero_finesse_buf = 0;
966 for (
int j = 0; j < 4; j++) {
970 nonzero_finesse_buf++;
973 if (nonzero_finesse_buf == 0) {
975 sprintf(err_buf,
"No non-zero FINESSE buffer. Exiting...\n");
976 printf(
"%s", err_buf); fflush(stdout);
1000 return pos_nwords_to;
1007 if ((finesse_buf[ POS_MAGIC_B2LHSLB ] & 0xFFFF0000) == B2LHSLB_HEADER_MAGIC &&
1008 ((finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ] & 0xFFFF0000)
1009 == B2LHSLB_TRAILER_MAGIC)) {
1014 sprintf(err_buf,
"Invalid B2LHSLB magic words 0x%x 0x%x. Exiting... :%s %s %d\n",
1015 finesse_buf[ POS_MAGIC_B2LHSLB ],
1016 finesse_buf[ finesse_nwords - SIZE_B2LHSLB_TRAILER + POS_CHKSUM_B2LHSLB ],
1017 __FILE__, __PRETTY_FUNCTION__, __LINE__);
1018 printf(
"%s", err_buf); fflush(stdout);
1032 int nwords =
GetFINESSENwords(n, finesse_num) - (
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_TRAILER +
1033 SIZE_B2LHSLB_TRAILER);
1034 unsigned short temp_crc16 = CalcCRC16LittleEndian(0xffff, buf, nwords);
1040 - ((SIZE_B2LFEE_TRAILER - POS_CHKSUM_B2LFEE) + SIZE_B2LHSLB_TRAILER) ;
1044 if ((
unsigned short)(*buf & 0xFFFF) != temp_crc16) {
1045 printf(
"PRE CRC16 error : B2LCRC16 %x Calculated CRC16 %x : Nwords of FINESSE buf %d\n",
1049 printf(
"%.8x ", temp_buf[ k ]);
1050 if ((k + 1) % 10 == 0) {
1059 "[DEBUG] [ERROR] B2LCRC16 (%.4x) differs from one ( %.4x) calculated by PreRawCOPPERfromat class. Exiting...\n %s %s %d\n",
1060 (
unsigned short)(*buf & 0xFFFF), temp_crc16,
1061 __FILE__, __PRETTY_FUNCTION__, __LINE__);
1062 printf(
"%s", err_buf); fflush(stdout);
1070 int* detector_buf_1st,
int nwords_1st,
1071 int* detector_buf_2nd,
int nwords_2nd,
1072 int* detector_buf_3rd,
int nwords_3rd,
1073 int* detector_buf_4th,
int nwords_4th,
1076 int* packed_buf = NULL;
1078 int poswords_to = 0;
1079 int* detector_buf[ 4 ] = { detector_buf_1st, detector_buf_2nd, detector_buf_3rd, detector_buf_4th };
1080 const int nwords[ 4 ] = { nwords_1st, nwords_2nd, nwords_3rd, nwords_4th };
1085 for (
int i = 0; i < 4; i++) {
1086 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
1087 length_nwords += nwords[ i ];
1088 length_nwords +=
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER
1089 + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
1093 packed_buf =
new int[ length_nwords ];
1094 memset(packed_buf, 0,
sizeof(
int) * length_nwords);
1101 packed_buf[
tmp_header.POS_NWORDS ] = length_nwords;
1102 packed_buf[
tmp_header.POS_VERSION_HDRNWORDS ] = 0x7f7f8000
1109 packed_buf[
tmp_header.POS_TTCTIME_TRGTYPE ] = (rawcpr_info.
tt_ctime & 0x7FFFFFF) << 4;
1117 packed_buf[
tmp_header.POS_OFFSET_1ST_FINESSE ] =
static_cast<int>(
tmp_header.RAWHEADER_NWORDS) + SIZE_COPPER_HEADER;
1119 packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_1ST_FINESSE ];
1120 if (nwords[ 0 ] > 0) {
1121 packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ] +=
1122 nwords[ 0 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
1125 packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_2ND_FINESSE ];
1126 if (nwords[ 1 ] > 0) {
1127 packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ] +=
1128 nwords[ 1 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
1131 packed_buf[
tmp_header.POS_OFFSET_4TH_FINESSE ] = packed_buf[
tmp_header.POS_OFFSET_3RD_FINESSE ];
1132 if (nwords[ 2 ] > 0) {
1133 packed_buf[
tmp_header.POS_OFFSET_4TH_FINESSE ] += nwords[ 2 ] + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER +
1134 SIZE_B2LHSLB_TRAILER;
1139 packed_buf[ poswords_to + POS_MAGIC_COPPER_1 ] = COPPER_MAGIC_DRIVER_HEADER;
1140 packed_buf[ poswords_to + POS_MAGIC_COPPER_2 ] = COPPER_MAGIC_FPGA_HEADER;
1141 packed_buf[ poswords_to + POS_EVE_NUM_COPPER ] = rawcpr_info.
eve_num;
1143 int size_b2l_hdrtrl =
static_cast<int>(SIZE_B2LHSLB_HEADER) + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER + SIZE_B2LHSLB_TRAILER;
1144 if (nwords[ 0 ] != 0) packed_buf[ poswords_to + POS_CH_A_DATA_LENGTH ] = nwords[ 0 ] + size_b2l_hdrtrl;
1145 if (nwords[ 1 ] != 0) packed_buf[ poswords_to + POS_CH_B_DATA_LENGTH ] = nwords[ 1 ] + size_b2l_hdrtrl;
1146 if (nwords[ 2 ] != 0) packed_buf[ poswords_to + POS_CH_C_DATA_LENGTH ] = nwords[ 2 ] + size_b2l_hdrtrl;
1147 if (nwords[ 3 ] != 0) packed_buf[ poswords_to + POS_CH_D_DATA_LENGTH ] = nwords[ 3 ] + size_b2l_hdrtrl;
1149 packed_buf[ poswords_to + POS_DATA_LENGTH ] =
1150 packed_buf[ poswords_to + POS_CH_A_DATA_LENGTH ] +
1151 packed_buf[ poswords_to + POS_CH_B_DATA_LENGTH ] +
1152 packed_buf[ poswords_to + POS_CH_C_DATA_LENGTH ] +
1153 packed_buf[ poswords_to + POS_CH_D_DATA_LENGTH ] +
1154 (
static_cast<int>(SIZE_COPPER_HEADER) - SIZE_COPPER_DRIVER_HEADER) +
1155 (
static_cast<int>(SIZE_COPPER_TRAILER) - SIZE_COPPER_DRIVER_TRAILER);
1157 poswords_to += SIZE_COPPER_HEADER;
1160 for (
int i = 0; i < 4; i++) {
1162 if (detector_buf[ i ] == NULL || nwords[ i ] <= 0)
continue;
1165 packed_buf[ poswords_to + POS_MAGIC_B2LHSLB ] = 0xffaa0000 | (0xffff & rawcpr_info.
eve_num);
1166 poswords_to += SIZE_B2LHSLB_HEADER;
1167 int* crc16_start = &(packed_buf[ poswords_to ]);
1171 packed_buf[ poswords_to + POS_TT_CTIME_TYPE ] = (rawcpr_info.
tt_ctime & 0x7FFFFFF) << 4;
1172 packed_buf[ poswords_to + POS_TT_TAG ] = rawcpr_info.
eve_num;
1173 packed_buf[ poswords_to + POS_TT_UTIME ] = rawcpr_info.
tt_utime;
1174 packed_buf[ poswords_to + POS_EXP_RUN ] = (rawcpr_info.
exp_num << 22) | (rawcpr_info.
run_subrun_num &
1176 packed_buf[ poswords_to + POS_B2L_CTIME ] = (rawcpr_info.
b2l_ctime & 0x7FFFFFF) << 4;
1177 poswords_to += SIZE_B2LFEE_HEADER;
1180 memcpy(packed_buf + poswords_to, detector_buf[ i ], nwords[ i ]*
sizeof(
int));
1181 poswords_to += nwords[ i ];
1184 unsigned short crc16 = CalcCRC16LittleEndian(0xffff, crc16_start, nwords[ i ] + SIZE_B2LFEE_HEADER);
1185 packed_buf[ poswords_to + POS_CHKSUM_B2LFEE ] = ((0xffff & rawcpr_info.
eve_num) << 16) | (crc16 & 0xffff);
1186 poswords_to += SIZE_B2LFEE_TRAILER;
1189 packed_buf[ poswords_to + POS_CHKSUM_B2LHSLB ] = 0xff550000;
1190 poswords_to += SIZE_B2LHSLB_TRAILER;
1195 packed_buf[ poswords_to + POS_MAGIC_COPPER_3 ] = COPPER_MAGIC_FPGA_TRAILER;
1196 packed_buf[ poswords_to + POS_MAGIC_COPPER_4 ] = COPPER_MAGIC_DRIVER_TRAILER;
1197 unsigned int chksum = 0;
1198 for (
int i =
tmp_header.
GetHdrNwords(); i < poswords_to + (static_cast<int>(SIZE_COPPER_TRAILER) - SIZE_COPPER_DRIVER_TRAILER);
1200 chksum ^= packed_buf[ i ];
1202 packed_buf[ poswords_to + POS_CHKSUM_COPPER ] = chksum;
1203 poswords_to += SIZE_COPPER_TRAILER;
1207 for (
int i = 0; i < poswords_to; i++) {
1208 chksum ^= packed_buf[ i ];
1210 packed_buf[ poswords_to +
tmp_trailer.POS_CHKSUM ] = chksum;
1215 *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)
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
int GetHdrNwords()
get contents of header
int GetTrlNwords()
Set magic word.
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Abstract base class for different kinds of events.