9#include <daq/rawdata/modules/copper.h>
10#include <daq/rawdata/modules/DeSerializerCOPPER.h>
11#include <rawdata/dataobjects/PreRawCOPPERFormat_latest.h>
30int g_run_resuming = 0;
53 B2INFO(
"DeSerializerCOPPER: Constructor done.");
60DeSerializerCOPPERModule::~DeSerializerCOPPERModule()
66 B2INFO(
"DeSerializerCOPPER: initialize() started.");
68 for (
int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
76 for (
int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
81 m_eventMetaDataPtr.registerInDataStore();
85 raw_dblkarray.registerInDataStore();
90 memset(time_array0, 0,
sizeof(time_array0));
91 memset(time_array1, 0,
sizeof(time_array1));
92 memset(time_array2, 0,
sizeof(time_array2));
93 memset(time_array3, 0,
sizeof(time_array3));
94 memset(time_array4, 0,
sizeof(time_array4));
95 memset(time_array5, 0,
sizeof(time_array5));
107 printf(
"nodename = %s\n",
m_nodename.c_str());
117 B2INFO(
"DeSerializerCOPPER: initialize() done.");
153 char err_buf[100] =
"[FATAL] Slot is not specified. Exiting...";
159 for (slot = 0; slot < 4; slot++) {
160 if (
m_use_slot & (1 << slot)) printf(
" %c",
'A' + slot);
169 B2INFO(
"Opening COPPER...");
181int* DeSerializerCOPPERModule::readOneEventFromCOPPERFIFO(
const int ,
int* ,
int* )
185 sprintf(err_buf,
"[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
186 __FILE__, __PRETTY_FUNCTION__, __LINE__);
187 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
205 if (errno == EINTR) {
207 }
else if (errno == EAGAIN || errno == EWOULDBLOCK) {
211 sprintf(err_buf,
"[FATAL] EAGAIN return in the middle of an event( COPPER driver should't do this.). Exting...");
219 callCheckRunPause(err_str);
225 sprintf(err_buf,
"[FATAL] Failed to read data from COPPER. Exiting...");
230 recvd_byte += read_size;
252 temp_buf =
new int[ *m_size_word ];
253 memcpy(temp_buf,
m_bufary[ entry ], recvd_byte);
265 sprintf(err_buf,
"[FATAL] CORRUPTED DATA: Read less bytes(%d) than expected(%d:%d). Exiting...\n",
274 sprintf(err_buf,
"[FATAL] CORRUPTED DATA: Read more than data size. Exiting...: %d %d %d %d %d\n",
284 *m_size_word = 256 + entry;
291 temp_buf[ 0 ] = *m_size_word;
302 unsigned int checksum = 0;
303 for (
int i = 0; i <
m_bufary[entry][0]; i++) {
304 if (i != 2) checksum +=
m_bufary[entry][i];
315void DeSerializerCOPPERModule::openCOPPER()
325 if ((
m_cpr_fd = open(
"/dev/copper/copper", O_RDONLY)) == -1) {
327 sprintf(err_buf,
"[FATAL] Failed to open /dev/copper/copper. Exiting... ");
334 ioctl(
m_cpr_fd, CPRIOSET_LEF_WA_FF, &set_regval);
335 ioctl(
m_cpr_fd, CPRIOSET_LEF_WB_FF, &set_regval);
336 ioctl(
m_cpr_fd, CPRIOSET_LEF_WC_FF, &set_regval);
337 ioctl(
m_cpr_fd, CPRIOSET_LEF_WD_FF, &set_regval);
342 ioctl(
m_cpr_fd, CPRIOSET_LEF_WA_AF, &v,
sizeof(v));
343 ioctl(
m_cpr_fd, CPRIOSET_LEF_WB_AF, &v,
sizeof(v));
344 ioctl(
m_cpr_fd, CPRIOSET_LEF_WC_AF, &v,
sizeof(v));
345 ioctl(
m_cpr_fd, CPRIOSET_LEF_WD_AF, &v,
sizeof(v));
348 B2INFO(
"DeSerializerCOPPER: openCOPPER() done.");
360 if ((read_size = read(fd, (
char*)buf + n, data_size_byte - n)) < 0) {
361 if (errno == EINTR) {
363 }
else if (errno == EAGAIN || errno == EWOULDBLOCK) {
366 sprintf(err_buf,
"[FATAL] Return due to EAGAIN in the middle of an event( COPPER driver would't do this.). Exting...");
374 callCheckRunPause(err_str);
375 }
catch (
const string& err_str) {
378 B2WARNING(
"Delete buffer before going to Run-pause state");
388 printf(
"[ERROR] Failed to read data from COPPER. %s %s %d",
389 __FILE__, __PRETTY_FUNCTION__, __LINE__);
390 string err_str =
"RUN_ERROR";
394 sprintf(err_buf,
"[FATAL] Failed to read data from COPPER. %s %s %d",
395 __FILE__, __PRETTY_FUNCTION__, __LINE__);
401 if (n == data_size_byte)
break;
408void DeSerializerCOPPERModule::resumeRun()
412 printf(
"###########(DesCpr) Resume from PAUSE ###############\n");
423void DeSerializerCOPPERModule::waitResume()
426 if (g_run_pause == 0 && g_run_error == 1) {
430 printf(
"###########(DesCpr) Error stop. Waiting for RUNPAUSE ###############\n");
434 if (checkRunPause())
break;
443 if (checkRunRecovery()) {
451 printf(
"###########(DesCpr) Resume detected ###############\n");
459 printf(
"###########(DesCpr) Waiting for RESUME ###############\n");
475 if (g_run_pause > 0 || g_run_error > 0) {
477 m_eventMetaDataPtr.create();
486 B2INFO(
"DeSerializerCOPPER: Waiting for Start...\n");
493 B2INFO(
"Opening COPPER...");
502 for (
int j = 0; j < NUM_EVT_PER_BASF2LOOP_COPPER; j++) {
506 B2INFO(
"DeSerializerCOPPER: Reading the 1st event from COPPER FIFO...");
511 temp_buf = readOneEventFromCOPPERFIFO(j, &delete_flag, &m_size_word);
513 }
catch (
const string& err_str) {
516 if (err_str ==
"RUN_PAUSE" || err_str ==
"RUN_ERROR") {
518 m_eventMetaDataPtr.create();
527 B2INFO(
"DeSerializerCOPPER: Done. the size of the 1st event is " << m_size_word <<
"words");
531 const int num_nodes = 1;
532 const int num_events = 1;
534 temp_rawdblk->
SetBuffer(temp_buf, m_size_word, delete_flag, num_events, num_nodes);
538 temp_rawcopper.
SetBuffer(temp_buf, m_size_word, 0, num_events, num_nodes);
545 }
catch (
const string& err_str) {
551 dumpData((
char*)temp_buf, m_size_word *
sizeof(
int));
553 m_totbytes += m_size_word *
sizeof(int);
560 m_eventMetaDataPtr.create();
561 m_eventMetaDataPtr->setExperiment(0);
562 m_eventMetaDataPtr->setRun(0);
571 printf(
"[DEBUG] RunPause was detected. ( Setting: Max event # %d MaxTime %lf ) Processed Event %d Elapsed Time %lf[s]\n",
573 m_eventMetaDataPtr->setEndOfData();
587 g_status.setInputNBytes(m_totbytes);
int m_finesse_bit_flag
bit flag for available FINESSE slot
unsigned int m_prev_ftsweve32
Event # from data.
void initialize() override
Module functions to be called from main process.
virtual int readFD(int fd, char *buf, int data_size_byte, int delete_flag)
receive data
void event() override
Module functions to be called from event process.
int m_use_slot
bit flag for available FINESSE slot
const PreRawCOPPERFormat_latest m_pre_rawcpr
Handle to data from HSLBs.
DeSerializerCOPPERModule()
Constructor / Destructor.
int m_cpr_fd
COPPER file descripter.
virtual void initializeCOPPER()
Module functions to be called from main process.
A class definition of an input module for Sequential ROOT I/O.
void RateMonitor(unsigned int nevt, int subrun=-1, int run=-1)
monitor rate
unsigned int m_prev_exprunsubrun_no
run no.
std::string m_nodename
Node name.
int m_start_flag
start flag
int BUF_SIZE_WORD
size of buffer for one event (word)
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
virtual void dumpData(char *buf, int size)
dump binary data
double cur_time
for time monitoring
std::string m_dump_fname
dump filename
int m_shmflag
Use shared memory.
int * m_bufary[NUM_PREALLOC_BUF]
buffer
unsigned int m_exprunsubrun_no
run no.
virtual void openOutputFile()
Module functions to be called from event process.
double max_seconds
time to stop a run
int m_nodeid
Node(PC or COPPER) ID.
double getTimeSec()
store time info.
void setDescription(const std::string &description)
Sets the description of the module.
The RawDataBlock class Base class for rawdata handling.
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 )
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.
Abstract base class for different kinds of events.