9 #include <daq/rawdata/modules/DeSerializerFILE.h>
10 #include <rawdata/dataobjects/PreRawCOPPERFormat_latest.h>
11 #include <rawdata/dataobjects/RawFTSW.h>
31 setDescription(
"Encode DataStore into RingBuffer");
35 addParam(
"inputFileName", m_fname_in,
"Input binary filename",
string(
""));
36 addParam(
"inputRepetitionTimes", m_repetition_max,
37 "Input repetition times to read the input file", 0);
40 B2INFO(
"DeSerializerFILE: Constructor done.");
45 DeSerializerFILEModule::~DeSerializerFILEModule()
49 void DeSerializerFILEModule::fileOpen()
51 m_fp_in = fopen(m_fname_in.c_str(),
"r");
54 sprintf(err_buf,
"[FATAL] Cannot open an input file(%s): %s : Exiting...\n",
55 strerror(errno), m_fname_in.c_str());
56 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
62 void DeSerializerFILEModule::initialize()
64 B2INFO(
"DeSerializerFILE: initialize() started.");
68 m_eventMetaDataPtr.registerInDataStore();
70 memset(time_array0, 0,
sizeof(time_array0));
71 memset(time_array1, 0,
sizeof(time_array1));
72 memset(time_array2, 0,
sizeof(time_array2));
73 memset(time_array3, 0,
sizeof(time_array3));
74 memset(time_array4, 0,
sizeof(time_array4));
75 memset(time_array5, 0,
sizeof(time_array5));
78 m_rawDataBlock.registerInDataStore();
79 m_rawCOPPER.registerInDataStore();
80 m_rawSVD.registerInDataStore();
81 m_rawCDC.registerInDataStore();
82 m_rawTOP.registerInDataStore();
83 m_rawARICH.registerInDataStore();
84 m_rawECL.registerInDataStore();
85 m_rawKLM.registerInDataStore();
90 B2INFO(
"DeSerializerFILE: initialize() done.");
95 int* DeSerializerFILEModule::readOneDataBlock(
int* ,
int* ,
int* )
99 sprintf(err_buf,
"[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
100 __FILE__, __PRETTY_FUNCTION__, __LINE__);
101 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
110 int temp_size_word = 0;
112 int bytes_to_read =
sizeof(int);
117 if ((read_size = fread((
char*)(&temp_size_word), 1, bytes_to_read, m_fp_in)) != bytes_to_read) {
119 if (m_repetition_max > m_repetition_cnt) {
129 sprintf(err_buf,
"[FATAL] Failed to read header(%s).", strerror(errno));
130 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
135 recvd_byte += read_size;
137 int start_word = 0, stop_word = 0;
142 *data_type = RAW_DATABLOCK;
143 *size_word = temp_size_word;
145 stop_word = *size_word;
146 temp_buf = readfromFILE(m_fp_in, *size_word, start_word, stop_word);
147 if (temp_size_word == 0x7fff0008) {
149 *data_type = COPPER_DATABLOCK;
153 pos_data_length = PreRawCOPPERFormat_latest::POS_DATA_LENGTH;
156 stop_word = pos_data_length;
157 int* length_buf = readfromFILE(m_fp_in, pos_data_length, start_word, stop_word);
160 *size_word = length_buf[ pos_data_length - 1 ] +
161 PreRawCOPPERFormat_latest::SIZE_COPPER_DRIVER_HEADER + PreRawCOPPERFormat_latest::SIZE_COPPER_DRIVER_TRAILER
162 + m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS + m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS;
163 start_word = 1 + pos_data_length + m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS;
164 stop_word = *size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS;
166 temp_buf = readfromFILE(m_fp_in, *size_word, start_word, stop_word);
169 temp_buf[ m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS ] = 0x7fff0008;
170 memcpy((temp_buf + m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS + 1),
171 length_buf,
sizeof(
int) * pos_data_length);
175 *data_type = RAW_DATABLOCK;
176 *size_word = temp_size_word;
178 stop_word = *size_word;
179 temp_buf = readfromFILE(m_fp_in, *size_word, start_word, stop_word);
187 int* DeSerializerFILEModule::readfromFILE(FILE* fp_in,
const int size_word,
const int start_word,
const int stop_word)
193 temp_buf =
new int[ size_word ];
195 memset(temp_buf, 0, size_word *
sizeof(
int));
196 temp_buf[ 0 ] = size_word;
197 int recvd_byte = start_word *
sizeof(int);
198 int bytes_to_read = stop_word *
sizeof(int);
201 if ((read_size = fread((
char*)temp_buf + recvd_byte, 1, bytes_to_read - recvd_byte, fp_in)) < 0) {
207 sprintf(err_buf,
"[FATAL] Failed to read header. Exiting...");
208 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
211 recvd_byte += read_size;
213 if (bytes_to_read != recvd_byte) {
215 sprintf(err_buf,
"[FATAL] Read less bytes(%d) than expected(%d). Exiting...\n",
216 recvd_byte, bytes_to_read);
217 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
225 void DeSerializerFILEModule::event()
228 if (m_start_flag == 0) {
233 if (m_start_flag == 0) {
234 B2INFO(
"DeSerializerFILE: event() started.");
235 m_start_time = getTimeSec();
246 unsigned int prev_eve_num = 0;
259 if (m_prev_buf_flag == 1) {
260 temp_buf = m_prev_buf;
261 size_word = temp_buf[ 0 ];
265 temp_buf = readOneDataBlock(&delete_flag, &size_word, &data_type);
268 if (temp_buf == 0x0) {
269 printf(
"[DEBUG] End of file\n");
274 if (data_type == COPPER_DATABLOCK) {
280 temp_rawcopper.
SetBuffer(temp_buf, size_word, 0, num_events, num_nodes);
283 printf(
"[FATAL] Sorry. This version does not support fillNewCOPPERheader()");
289 unsigned int temp_cur_evenum = 0, temp_cur_copper_ctr = 0;
293 m_dummy_evenum - 2, &temp_cur_evenum,
294 m_dummy_evenum - 2, &temp_cur_copper_ctr,
295 m_prev_exprunsubrun_no, &m_exprunsubrun_no);
297 }
catch (
string err_str) {
298 print_err.PrintError(m_shmflag, &g_status, err_str);
301 m_prev_run_no = m_run_no;
314 temp_rawdblk.
SetBuffer(temp_buf, size_word, 0, num_nodes, num_events);
317 unsigned int eve_num;
322 temp_raw_ftsw.
SetBuffer(temp_buf, size_word, 0, num_nodes, num_events);
323 eve_num = temp_raw_ftsw.
GetEveNo(block_num);
326 temp_raw_copper.
SetBuffer(temp_buf, size_word, 0, num_nodes, num_events);
327 eve_num = temp_raw_copper.
GetEveNo(block_num);
331 if (eve_num != prev_eve_num && first_flag != 0) {
333 m_prev_buf = temp_buf;
336 prev_eve_num = eve_num;
340 (ary.
appendNew())->SetBuffer(temp_buf, size_word, 1, num_nodes, num_events);
351 (ary.
appendNew())->SetBuffer(temp_buf, size_word, 1, 1, 1);
372 m_totbytes += size_word *
sizeof(int);
378 m_eventMetaDataPtr.
create();
379 m_eventMetaDataPtr->setExperiment(0);
380 m_eventMetaDataPtr->setRun(0);
381 m_eventMetaDataPtr->setEvent(prev_eve_num);
383 m_eventMetaDataPtr->setEndOfData();
386 if (n_basf2evt % 100 == 0) {
387 printf(
"[DEBUG] Processing Evt # %d...\n", prev_eve_num);
A class definition of an input module for Sequential ROOT I/O.
A class definition of an input module for Sequential ROOT I/O.
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
The RawDataBlock class Base class for rawdata handling.
virtual int CheckFTSWID(int n)
get FTSW ID to check whether this data block is FTSW data or not
virtual void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes)
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
unsigned int GetEveNo(int n)
Get event #.
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
bool create(bool replace=false)
Creating StoreArrays is unnecessary, only used internally.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
unsigned int GetEveNo(int n)
get subrun #(8bit)
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)
check data contents
Abstract base class for different kinds of events.