9#include <daq/rawdata/modules/copper.h>
10#include <daq/rawdata/DesSerCOPPER.h>
25 const std::string& nodename,
int nodeid,
int finesse_bitflag)
34 m_socket_recv.push_back(-1);
48 printf(
"[DEBUG] DeSerializerPrePC: Constructor done.\n"); fflush(stdout);
53DesSerCOPPER::~DesSerCOPPER()
61 printf(
"[DEBUG] initializing...\n"); fflush(stdout);
66 printf(
"[DEBUG] Done.\n"); fflush(stdout);
68 unsigned int m_prev_ftsweve32 = 0xffffffff;
79 printf(
"[DEBUG] DeSerializerPrePC: Waiting for Start...\n"); fflush(stdout);
107 for (
int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
118 int delete_flag = 0, m_size_word = 0;
121 printf(
"[DEBUG] DeSerializerCOPPER: Reading the 1st event from COPPER FIFO... run %.8x eve %.8x\n",
m_prev_exprunsubrun_no,
122 m_prev_ftsweve32); fflush(stdout);
129 printf(
"[DEBUG] DeSerializerCOPPER: Done. the size of the 1st event is %d words\n", m_size_word); fflush(stdout);
131 const int num_nodes = 1;
132 const int num_events = 1;
134 temp_rawcopper.
SetBuffer(temp_buf, m_size_word, 0, num_events, num_nodes);
140 }
catch (
const string& err_str) {
148 m_recvd_totbytes += m_size_word *
sizeof(int);
152 raw_datablk[ j ].
SetBuffer(temp_buf, m_size_word, delete_flag, num_events, num_nodes);
154 }
catch (
const string& err_str) {
155 printf(
"Error was detected\n"); fflush(stdout);
177 for (
int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
180 printf(
"[DEBUG] SerializerPC: Sending the 1st packet...\n"); fflush(stdout);
183 m_sent_totbytes += sendByWriteV(&(raw_datablk[ j ]));
184 }
catch (
const string& err_str) {
188 print_err.PrintError((
char*)err_str.c_str(), __FILE__, __PRETTY_FUNCTION__, __LINE__);
193 printf(
"[DEBUG] Done.\n"); fflush(stdout);
211 printf(
"[DEBUG] RunStop was detected. ( Setting: Max event # %d MaxTime %lf ) Processed Event %d Elapsed Time %lf[s]\n",
217 if ((
n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC) % 100000 == 0) {
218 double interval =
cur_time - m_prev_time;
219 double total_time =
cur_time - m_start_time;
220 printf(
"[DEBUG] Event %12d Rate %6.2lf[kHz] Recvd %6.2lf[MB/s] sent %6.2lf[MB/s] RunTime %8.2lf[s] interval %8.4lf[s]\n",
223 (m_recvd_totbytes - m_recvd_prev_totbytes) / interval / 1.e6,
224 (m_sent_totbytes - m_sent_prev_totbytes) / interval / 1.e6,
230 m_recvd_prev_totbytes = m_recvd_totbytes;
231 m_sent_prev_totbytes = m_sent_totbytes;
239 m_status.setOutputNBytes(m_sent_totbytes);
253void DesSerCOPPER::waitResume()
257 if (checkRunPause())
break;
260 printf(
"###########(DesSerCOPPER) Waiting for Runstop() ###############\n");
275 printf(
"###########(Ser) Waiting for Resume ###############\n");
279 if (checkRunRecovery()) {
288 printf(
"Done!\n"); fflush(stdout);
291 printf(
"Trying Accept1\n"); fflush(stdout);
293 printf(
"Trying Accept2\n"); fflush(stdout);
302void DesSerCOPPER::resumeRun()
307 printf(
"###########(Ser) the 1st event sicne the resume ###############\n");
328 temp_buf[0] = BUF_SIZE_WORD ;
339 if ((read_size = read(
m_cpr_fd, (
char*)
m_bufary[entry] + recvd_byte,
sizeof(
int) * BUF_SIZE_WORD - recvd_byte)) < 0) {
340 if (errno == EINTR) {
342 }
else if (errno == EAGAIN || errno == EWOULDBLOCK) {
346 sprintf(err_buf,
"[FATAL] EAGAIN return in the middle of an event( COPPER driver should't do this.). Exting...");
354 callCheckRunPause(err_str);
360 sprintf(err_buf,
"[FATAL] Failed to read data from COPPER. Exiting...");
365 recvd_byte += read_size;
385 if (*m_size_word > BUF_SIZE_WORD) {
387 temp_buf =
new int[ *m_size_word ];
388 memcpy(temp_buf,
m_bufary[ entry ], recvd_byte);
400 sprintf(err_buf,
"[FATAL] CORRUPTED DATA: Read less bytes(%d) than expected(%lu:%d). Exiting...\n",
409 sprintf(err_buf,
"[FATAL] CORRUPTED DATA: Read more than data size. Exiting...: %d %lu %lu %d %d\n",
419 *m_size_word = 256 + entry;
426 temp_buf[ 0 ] = *m_size_word;
437 unsigned int checksum = 0;
438 for (
int i = 0; i <
m_bufary[entry][0]; i++) {
439 if (i != 2) checksum +=
m_bufary[entry][i];
478 char err_buf[100] =
"[FATAL] Slot is not specified. Exiting...";
484 for (slot = 0; slot < 4; slot++) {
485 if (
m_use_slot & (1 << slot)) printf(
" %c",
'A' + slot);
495 printf(
"[DEBUG] Opening COPPER...\n"); fflush(stdout);
498 printf(
"[DEBUG] Done.\n"); fflush(stdout);
513 if ((
m_cpr_fd = open(
"/dev/copper/copper", O_RDONLY)) == -1) {
515 sprintf(err_buf,
"[FATAL] Failed to open /dev/copper/copper. Exiting... ");
522 ioctl(
m_cpr_fd, CPRIOSET_LEF_WA_FF, &set_regval);
523 ioctl(
m_cpr_fd, CPRIOSET_LEF_WB_FF, &set_regval);
524 ioctl(
m_cpr_fd, CPRIOSET_LEF_WC_FF, &set_regval);
525 ioctl(
m_cpr_fd, CPRIOSET_LEF_WD_FF, &set_regval);
530 ioctl(
m_cpr_fd, CPRIOSET_LEF_WA_AF, &v,
sizeof(v));
531 ioctl(
m_cpr_fd, CPRIOSET_LEF_WB_AF, &v,
sizeof(v));
532 ioctl(
m_cpr_fd, CPRIOSET_LEF_WC_AF, &v,
sizeof(v));
533 ioctl(
m_cpr_fd, CPRIOSET_LEF_WD_AF, &v,
sizeof(v));
537 printf(
"[DEBUG] DeSerializerCOPPER: openCOPPER() done.\n"); fflush(stdout);
549 if ((read_size = read(fd, (
char*)buf + n, data_size_byte - n)) < 0) {
550 if (errno == EINTR) {
552 }
else if (errno == EAGAIN || errno == EWOULDBLOCK) {
555 sprintf(err_buf,
"[FATAL] Return due to EAGAIN in the middle of an event( COPPER driver would't do this.). Exting...");
563 callCheckRunPause(err_str);
564 }
catch (
const string& err_string) {
568 printf(
"[WARNING] Delete buffer before going to Run-pause state\n"); fflush(stdout);
579 printf(
"[ERROR] Failed to read data from COPPER. %s %s %d",
580 __FILE__, __PRETTY_FUNCTION__, __LINE__);
581 string err_str =
"RUN_ERROR";
585 sprintf(err_buf,
"[FATAL] Failed to read data from COPPER. %s %s %d",
586 __FILE__, __PRETTY_FUNCTION__, __LINE__);
592 if (n == data_size_byte)
break;
int m_finesse_bit_flag
bit flag of FINESSE slots to use
int readFD(int fd, char *buf, int data_size_byte, int delete_flag)
receive data
void DataAcquisition() override
Module functions to be called from event process.
int m_use_slot
bit flag of FINESSE slots to use
void openCOPPER()
open COPPER
int * readOneEventFromCOPPERFIFO(const int entry, int *delete_flag, int *m_size_word)
Read one event from COPPER.
int m_cpr_fd
file descripter for COPPER
DesSerCOPPER(std::string host_recv, int port_recv, const std::string &host_send, int port_send, int shmflag, const std::string &nodename, int nodeid, int finesse_bitflag)
Constructor / Destructor.
void initializeCOPPER()
Module functions to be called from main process.
int m_port_to
Destination port.
RunInfoBuffer m_status
Run info buffer.
std::string m_hostname_local
Destination Host.
unsigned int m_prev_exprunsubrun_no
run no.
std::string m_nodename
Node Name for SLC.
int m_start_flag
start flag
std::vector< int > m_port_from
port # to connect data sources
int n_basf2evt
No. of sent events.
int m_socket_send
Reciever Socket.
PreRawCOPPERFormat_v2 m_pre_rawcpr
report status to SLC
CprErrorMessage print_err
wrapper for B2LOG system
int m_run_pause
flag to show that run-controller pauses a run
int m_run_error
flag to show that there is some errors with which DAQ cannot continue.
double cur_time
for time monitoring
int m_shmflag
Use shared memory.
int m_prev_nevt
No. of prev sent events.
int m_num_connections
check data contents
int * m_bufary[NUM_PREALLOC_BUF]
buffer
unsigned int m_exprunsubrun_no
run no.
double max_seconds
time to stop a run
int m_nodeid
Node ID for SLC.
double getTimeSec()
store time info.
std::vector< std::string > m_hostname_from
Reciever basf2 Socket.
Abstract base class for different kinds of events.