9#include <daq/rawdata/modules/DeSerializerFILE.h>
10#include <rawdata/dataobjects/PreRawCOPPERFormat_latest.h>
11#include <rawdata/dataobjects/RawFTSW.h>
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.");
45DeSerializerFILEModule::~DeSerializerFILEModule()
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__);
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));
90 B2INFO(
"DeSerializerFILE: initialize() done.");
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
166 temp_buf =
readfromFILE(m_fp_in, *size_word, start_word, stop_word);
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);
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__);
234 B2INFO(
"DeSerializerFILE: event() started.");
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 ];
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,
297 }
catch (
const string& err_str) {
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();
387 printf(
"[DEBUG] Processing Evt # %u...\n", prev_eve_num);
A class definition of an input module for Sequential ROOT I/O.
const PreRawCOPPERFormat_latest m_pre_rawcpr
Handle to data from HSLBs.
virtual int * readfromFILE(FILE *fp_in, const int size_word, const int start_word, const int stop_word)
read data from file
StoreArray< RawSVD > m_rawSVD
RawSVD.
void initialize() override
Module functions to be called from main process.
void event() override
Module functions to be called from event process.
StoreArray< RawCOPPER > m_rawCOPPER
RawCOPPER.
StoreArray< RawARICH > m_rawARICH
RawARICH.
StoreArray< RawKLM > m_rawKLM
RawKLM.
StoreArray< RawTOP > m_rawTOP
RawTOP.
DeSerializerFILEModule()
Constructor / Destructor.
StoreArray< RawDataBlock > m_rawDataBlock
RawDataBlock.
StoreArray< RawECL > m_rawECL
RawECL.
virtual int * readOneDataBlock(int *delete_flag, int *m_size_word, int *data_type)
receive data
StoreArray< RawCDC > m_rawCDC
RawCDC.
virtual void fileOpen()
open a file
unsigned int m_prev_exprunsubrun_no
run no.
int m_start_flag
start flag
static RunInfoBuffer g_status
buffer class to communicate with NSM client
int n_basf2evt
No. of sent events.
CprErrorMessage print_err
wrapper for B2LOG system
int m_shmflag
Use shared memory.
unsigned int m_exprunsubrun_no
run no.
double getTimeSec()
store time info.
void setDescription(const std::string &description)
Sets the description of the module.
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.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#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.