Belle II Software development
DesSerCOPPER Class Reference

A class definition of an input module for Sequential ROOT I/O. More...

#include <DesSerCOPPER.h>

Inheritance diagram for DesSerCOPPER:
DesSer

Public Member Functions

 DesSerCOPPER (const 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 DataAcquisition () override
 Module functions to be called from event process.
 
int * readOneEventFromCOPPERFIFO (const int entry, int *delete_flag, int *m_size_word)
 Read one event from COPPER.
 
void openCOPPER ()
 open COPPER
 
void initializeCOPPER ()
 Module functions to be called from main process.
 
int readFD (int fd, char *buf, int data_size_byte, int delete_flag)
 receive data
 
void initialize (bool close_listen=true)
 
int * getPreAllocBuf ()
 Getbuffer.
 
int * getNewBuffer (int nwords, int *delete_flag)
 Getbuffer.
 
void recordTime (int event, double *array)
 store time info.
 
unsigned int calcSimpleChecksum (int *buf, int nwords)
 calculate checksum
 
void clearNumUsedBuf ()
 
void RateMonitor (unsigned int nevt)
 monitor rate
 
int * shmGet (int fd, int size_words)
 Get shared memory.
 
void initializeNode ()
 Module functions to be called from main process.
 
void beginRun ()
 Module functions to be called from event process.
 
void endRun ()
 
void terminate ()
 
int sendByWriteV (RawDataBlockFormat *rawdblk)
 
void Accept (bool close_listen=true)
 
void fillSendHeaderTrailer (SendHeader *hdr, SendTrailer *trl, RawDataBlockFormat *rawdblk)
 
int Send (int socket, char *buf, int size_bytes)
 send buffer
 

Static Public Member Functions

static void printData (const int *buf, int nwords)
 dump error data
 
static double getTimeSec ()
 store time info.
 
static unsigned int calcXORChecksum (const int *buf, int nwords)
 calculate checksum
 
static void shmOpen (char *path_cfg, char *path_sta)
 open shared memory
 

Public Attributes

int m_cpr_fd = 0
 file descripter for COPPER
 
int m_use_slot = 0
 bit flag of FINESSE slots to use
 
int m_finesse_bit_flag
 bit flag of FINESSE slots to use
 
int max_nevt = 0
 
double max_seconds = 0.0
 time to stop a run
 
int m_compressionLevel = 0
 Compression Level.
 
int n_basf2evt = 0
 No. of sent events.
 
int m_prev_nevt = 0
 No. of prev sent events.
 
std::string m_dump_fname
 dump filename
 
FILE * m_fp_dump = nullptr
 dump file descripter
 
int * m_buffer = nullptr
 buffer
 
int * m_bufary [NUM_PREALLOC_BUF] = {}
 buffer
 
timeval m_t0
 
double m_recvd_totbytes = 0.0
 
double m_recvd_prev_totbytes = 0.0
 
double m_sent_totbytes = 0.0
 
double m_sent_prev_totbytes = 0.0
 
int m_ncycle = 0
 
double cur_time = 0.0
 for time monitoring
 
double m_start_time = 0.0
 
double m_prev_time = 0.0
 
int prev_event = 0
 
int m_num_usedbuf = 0
 
std::string m_nodename
 Node Name for SLC.
 
int m_nodeid = 0
 Node ID for SLC.
 
RunInfoBuffer m_status
 Run info buffer.
 
unsigned int m_exprunsubrun_no
 run no.
 
unsigned int m_prev_exprunsubrun_no
 run no.
 
int m_exp_no = 0
 exp no.
 
int m_data_type = 0
 data type
 
int m_trunc_mask = 0
 trunc mask
 
int m_shmflag = 0
 Use shared memory.
 
int m_shmfd_cfg = 0
 file descripter for shm
 
int m_shmfd_sta = 0
 file descripter for shm
 
int monitor_numeve = 0
 buffer for shared memory
 
int m_start_flag = 0
 start flag
 
CprErrorMessage print_err
 wrapper for B2LOG system
 
PreRawCOPPERFormat_v2 m_pre_rawcpr
 report status to SLC
 
int * m_cfg_buf = nullptr
 buffer for shared memory
 
int * m_cfg_sta = nullptr
 buffer for shared memory
 
int m_run_pause = 0
 flag to show that run-controller pauses a run
 
int m_run_error = 0
 flag to show that there is some errors with which DAQ cannot continue.
 

Protected Types

enum  {
  COPPER = 1 ,
  ROPC = 2
}
 

Protected Attributes

int m_num_connections
 check data contents
 
std::vector< std::string > m_hostname_from
 Reciever basf2 Socket.
 
std::vector< int > m_port_from
 port # to connect data sources
 
std::vector< int > m_socket_recv
 
int event_diff = 0
 
unsigned int m_prev_copper_ctr = 0
 
unsigned int m_prev_evenum = 0
 
int m_socket_send = 0
 Reciever Socket.
 
std::string m_hostname_local
 Destination Host.
 
int m_port_to = 0
 Destination port.
 
std::string p_method
 EvtSocket.
 
int p_method_val = 0
 
RawHeader_v2 tmp_header
 which format is used
 

Detailed Description

A class definition of an input module for Sequential ROOT I/O.

Definition at line 27 of file DesSerCOPPER.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protectedinherited

Definition at line 269 of file DesSer.h.

269 {
270 COPPER = 1,
271 ROPC = 2
272 };

Constructor & Destructor Documentation

◆ DesSerCOPPER()

DesSerCOPPER ( const 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.

Definition at line 24 of file DesSerCOPPER.cc.

26{
27 m_finesse_bit_flag = finesse_bitflag;
28
29 for (int i = 0 ; i < m_num_connections; i++) {
30 // m_hostname_from.push_back( "localhost");
31 m_hostname_from.push_back(host_recv);
32 // m_port_from.push_back(30000);
33 m_port_from.push_back(port_recv) ;
34 m_socket_recv.push_back(-1);
35 }
36
37 // m_port_to = 31001;
38 m_port_to = port_send;
39 // m_hostname_local = "localhost";
40 m_hostname_local = host_send;
41 m_nodename = nodename;
42
43 m_shmflag = shmflag;
44
45 m_nodeid = nodeid;
46
47 // B2INFO("DeSerializerPrePC: Constructor done.");
48 printf("[DEBUG] DeSerializerPrePC: Constructor done.\n"); fflush(stdout);
49}
int m_finesse_bit_flag
bit flag of FINESSE slots to use
int m_port_to
Destination port.
Definition DesSer.h:278
std::string m_hostname_local
Destination Host.
Definition DesSer.h:275
std::string m_nodename
Node Name for SLC.
Definition DesSer.h:135
std::vector< int > m_port_from
port # to connect data sources
Definition DesSer.h:246
int m_shmflag
Use shared memory.
Definition DesSer.h:159
int m_num_connections
check data contents
Definition DesSer.h:237
int m_nodeid
Node ID for SLC.
Definition DesSer.h:138
std::vector< std::string > m_hostname_from
Reciever basf2 Socket.
Definition DesSer.h:243

◆ ~DesSerCOPPER()

~DesSerCOPPER ( )
overridevirtual

Definition at line 53 of file DesSerCOPPER.cc.

54{
55}

Member Function Documentation

◆ Accept()

void Accept ( bool close_listen = true)
inherited

Definition at line 365 of file DesSer.cc.

366{
367 //
368 // Connect to cprtb01
369 //
370 struct hostent* host;
371 host = gethostbyname(m_hostname_local.c_str());
372 if (host == NULL) {
373 char temp_buf[500];
374 sprintf(temp_buf, "[FATAL] hostname(%s) cannot be resolved(%s). Check /etc/hosts. Exiting...\n",
375 m_hostname_local.c_str(), strerror(errno));
376 print_err.PrintError(temp_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
377 exit(1);
378 }
379
380 //
381 // Bind and listen
382 //
383 int fd_listen;
384 struct sockaddr_in sock_listen;
385 sock_listen.sin_family = AF_INET;
386 sock_listen.sin_addr.s_addr = *reinterpret_cast<unsigned int*>(host->h_addr_list[0]);
387
388 socklen_t addrlen = sizeof(sock_listen);
389 sock_listen.sin_port = htons(m_port_to);
390 fd_listen = socket(PF_INET, SOCK_STREAM, 0);
391
392 int flags = 1;
393 int ret = setsockopt(fd_listen, SOL_SOCKET, SO_REUSEADDR, &flags, (socklen_t)sizeof(flags));
394 if (ret < 0) {
395 perror("Failed to set REUSEADDR");
396 }
397
398 if (bind(fd_listen, reinterpret_cast<struct sockaddr*>(&sock_listen), sizeof(struct sockaddr)) < 0) {
399 printf("[FATAL] Failed to bind. Maybe other programs have already occupied this port(%d). Exiting...\n",
400 m_port_to); fflush(stdout);
401 // Check the process occupying the port 30000.
402 FILE* fp;
403 char buf[256];
404 char cmdline[500];
405 sprintf(cmdline, "/usr/sbin/ss -ap | grep %d", m_port_to);
406 if ((fp = popen(cmdline, "r")) == NULL) {
407 printf("[WARNING] Failed to run %s\n", cmdline);
408 } else {
409 while (fgets(buf, 256, fp) != NULL) {
410 printf("[ERROR] Failed to bind. output of ss(port %d) : %s\n", m_port_to, buf); fflush(stdout);
411 }
412 pclose(fp);
413 }
414 // Error message
415 char temp_char[500];
416 sprintf(temp_char, "[FATAL] Failed to bind.(%s) Maybe other programs have already occupied this port(%d). Exiting...",
417 strerror(errno), m_port_to);
418 print_err.PrintError(temp_char, __FILE__, __PRETTY_FUNCTION__, __LINE__);
419 exit(1);
420 }
421
422 int val1 = 0;
423 setsockopt(fd_listen, IPPROTO_TCP, TCP_NODELAY, &val1, (socklen_t)sizeof(val1));
424 int backlog = 1;
425 if (listen(fd_listen, backlog) < 0) {
426 char err_buf[500];
427 sprintf(err_buf, "Failed in listen(%s). Exting...", strerror(errno));
428 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
429 exit(-1);
430 }
431
432 //
433 // Accept
434 //
435 int fd_accept;
436 struct sockaddr_in sock_accept;
437 printf("[DEBUG] Accepting... : port %d server %s\n", m_port_to, m_hostname_local.c_str());
438 fflush(stdout);
439
440 if ((fd_accept = accept(fd_listen, reinterpret_cast<struct sockaddr*>(& (sock_accept)), &addrlen)) == 0) {
441 char err_buf[500];
442 sprintf(err_buf, "[FATAL] Failed to accept(%s). Exiting...", strerror(errno));
443 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
444 exit(-1);
445 } else {
446 // B2INFO("Done.");
447 printf("[DEBUG] Done.\n"); fflush(stdout);
448
449 // set timepout option
450 struct timeval timeout;
451 timeout.tv_sec = 1;
452 timeout.tv_usec = 0;
453 ret = setsockopt(fd_accept, SOL_SOCKET, SO_SNDTIMEO, &timeout, (socklen_t)sizeof(timeout));
454 if (ret < 0) {
455 const char temp_char[100] = "[FATAL] Failed to set TIMEOUT. Exiting...";
456 print_err.PrintError(temp_char, __FILE__, __PRETTY_FUNCTION__, __LINE__);
457 exit(-1);
458 }
459 }
460
461 if (close_listen) {
462 close(fd_listen);
463 }
464
465 // int flag = 1;
466 // ret = setsockopt(fd_accept, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(flag) );
467 m_socket_send = fd_accept;
468
469 if (m_status.isAvailable()) {
470 m_status.setOutputPort(ntohs(sock_listen.sin_port));
471 m_status.setOutputAddress(sock_listen.sin_addr.s_addr);
472 // B2INFO("Accepted " << (int)ntohs(sock_listen.sin_port) << " " << (int)sock_listen.sin_addr.s_addr);
473 printf("Accepted. port %d address %d\n", (int)ntohs(sock_listen.sin_port), (int)sock_listen.sin_addr.s_addr); fflush(stdout);
474 }
475
476 return;
477
478}
RunInfoBuffer m_status
Run info buffer.
Definition DesSer.h:141
int m_socket_send
Reciever Socket.
Definition DesSer.h:267
CprErrorMessage print_err
wrapper for B2LOG system
Definition DesSer.h:184

◆ calcXORChecksum()

unsigned int calcXORChecksum ( const int * buf,
int nwords )
staticinherited

calculate checksum

Definition at line 497 of file DesSer.cc.

498{
499 unsigned int checksum = 0;
500 for (int i = 0; i < nwords; i++) {
501 checksum = checksum ^ buf[ i ];
502 }
503 return checksum;
504}

◆ clearNumUsedBuf()

void clearNumUsedBuf ( )
inlineinherited

Definition at line 121 of file DesSer.h.

122 {
123 m_num_usedbuf = 0;
124 return ;
125 }

◆ DataAcquisition()

void DataAcquisition ( )
overridevirtual

Module functions to be called from event process.

Implements DesSer.

Definition at line 57 of file DesSerCOPPER.cc.

58{
59 // For data check
60 // B2INFO("initializing...");
61 printf("[DEBUG] initializing...\n"); fflush(stdout);
62 initialize(false);
63
64
65 // B2INFO("Done.");
66 printf("[DEBUG] Done.\n"); fflush(stdout);
67
68 unsigned int m_prev_ftsweve32 = 0xffffffff;
69
70 if (m_start_flag == 0) {
71 //
72 // Connect to eb0: This should be here because we want Serializer first to accept connection from eb1tx
73 //
75 // Connect();
76
77 if (m_status.isAvailable()) {
78 // B2INFO("DeSerializerPrePC: Waiting for Start...\n");
79 printf("[DEBUG] DeSerializerPrePC: Waiting for Start...\n"); fflush(stdout);
80 m_status.reportRunning();
81 }
82 m_start_time = getTimeSec();
83 n_basf2evt = 0;
84 }
85
86 //
87 // Main loop
88 //
89 while (1) {
90 //
91 // Stand-by loop
92 //
93#ifdef NONSTOP
94 if (m_run_pause > 0 || m_run_error > 0) {
95 waitResume();
96 }
97#endif
98
99 clearNumUsedBuf();
100 // RawDataBlock raw_datablk[ NUM_EVT_PER_BASF2LOOP_PC ];
101 RawDataBlockFormat raw_datablk[ NUM_EVT_PER_BASF2LOOP_PC ];
102
103
104 //
105 // Recv loop
106 //
107 for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
108 //
109 // Receive data from COPPER
110 //
111 //int delete_flag_from =
112 //0; // Delete flag for temp_rawdatablk.It can be set to 1 by setRecvdBuffer if the buffer size is larger than that of pre-allocated buffer.
113 //int delete_flag_to =
114 //0; // Delete flag for raw_datablk[i]. It can be set to 1 by getNewBuffer if the buffer size is larger than that of pre-allocated buffer.
115 RawDataBlockFormat temp_rawdatablk;
116 try {
117
118 int delete_flag = 0, m_size_word = 0;
119
120 if (m_start_flag == 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);
123 }
124 int* temp_buf;
125
126 temp_buf = readOneEventFromCOPPERFIFO(j, &delete_flag, &m_size_word);
127 m_status.copyEventHeader(temp_buf);
128 if (m_start_flag == 0) {
129 printf("[DEBUG] DeSerializerCOPPER: Done. the size of the 1st event is %d words\n", m_size_word); fflush(stdout);
130 }
131 const int num_nodes = 1;
132 const int num_events = 1;
133 PreRawCOPPERFormat_v2 temp_rawcopper;
134 temp_rawcopper.SetBuffer(temp_buf, m_size_word, 0, num_events, num_nodes);
135 // Fill header and trailer
136 try {
137 m_prev_ftsweve32 = temp_rawcopper.FillTopBlockRawHeader(m_nodeid, m_prev_ftsweve32, m_prev_exprunsubrun_no, &m_exprunsubrun_no);
139 // fillNewRawCOPPERHeader( &temp_rawcopper );
140 } catch (const string& err_str) {
141 print_err.PrintError(m_shmflag, &m_status, err_str);
142 exit(1);
143 }
144
145// if (m_dump_fname.size() > 0) {
146// dumpData((char*)temp_buf, m_size_word * sizeof(int));
147// }
148 m_recvd_totbytes += m_size_word * sizeof(int);
149
150 // temp_rawdblk = raw_dblkarray.appendNew();
151 // temp_rawdatablk->SetBuffer(temp_buf, m_size_word, delete_flag, num_events, num_nodes);
152 raw_datablk[ j ].SetBuffer(temp_buf, m_size_word, delete_flag, num_events, num_nodes);
153
154 } catch (const string& err_str) {
155 printf("Error was detected\n"); fflush(stdout);
156 break;
157 }
158 }
159
160#ifdef NONSTOP
161 // Goto Stand-by loop when run is paused or stopped by error
162 if (m_run_pause != 0 || m_run_error != 0) continue;
163#endif
164
165
167 // From Serializer.cc
169 if (m_start_flag == 0) {
170 m_start_time = getTimeSec();
171 n_basf2evt = 0;
172 }
173
174 //
175 // Send data
176 //
177 for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
178 if (m_start_flag == 0) {
179 // B2INFO("SerializerPC: Sending the 1st packet...");
180 printf("[DEBUG] SerializerPC: Sending the 1st packet...\n"); fflush(stdout);
181 }
182 try {
183 m_sent_totbytes += sendByWriteV(&(raw_datablk[ j ]));
184 } catch (const string& err_str) {
185#ifdef NONSTOP
186 break;
187#endif
188 print_err.PrintError(const_cast<char*>(err_str.c_str()), __FILE__, __PRETTY_FUNCTION__, __LINE__);
189 exit(1);
190 }
191 if (m_start_flag == 0) {
192 // B2INFO("Done. ");
193 printf("[DEBUG] Done.\n"); fflush(stdout);
194 m_start_flag = 1;
195 }
196 }
197
198#ifdef NONSTOP
199 // Goto Stand-by loop when run is paused or stopped by error
200 if (m_run_pause != 0 || m_run_error != 0) continue;
201#endif
202
203 //
204 // Monitor
205 //
206 if (max_nevt >= 0 || max_seconds >= 0.) {
207#ifdef AIUEO
208 if (n_basf2evt % 10000 == 0) {
209// if ((n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC >= max_nevt && max_nevt > 0)
210// || (getTimeSec() - m_start_time > max_seconds && max_seconds > 0.)) {
211 printf("[DEBUG] RunStop was detected. ( Setting: Max event # %d MaxTime %lf ) Processed Event %d Elapsed Time %lf[s]\n",
212 max_nevt, max_seconds, n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC, getTimeSec() - m_start_time);
213 }
214#endif
215 }
216
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",
221 n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC,
222 (n_basf2evt - m_prev_nevt)*NUM_EVT_PER_BASF2LOOP_PC / interval / 1.e3,
223 (m_recvd_totbytes - m_recvd_prev_totbytes) / interval / 1.e6,
224 (m_sent_totbytes - m_sent_prev_totbytes) / interval / 1.e6,
225 total_time,
226 interval);
227 fflush(stdout);
228
229 m_prev_time = cur_time;
230 m_recvd_prev_totbytes = m_recvd_totbytes;
231 m_sent_prev_totbytes = m_sent_totbytes;
234 }
235
236 n_basf2evt++;
237
238 if (m_status.isAvailable()) {
239 m_status.setOutputNBytes(m_sent_totbytes);
240 m_status.setOutputCount(n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC);
241 }
242
243 }
244
245 return;
246}
int * readOneEventFromCOPPERFIFO(const int entry, int *delete_flag, int *m_size_word)
Read one event from COPPER.
void initializeCOPPER()
Module functions to be called from main process.
unsigned int m_prev_exprunsubrun_no
run no.
Definition DesSer.h:147
int m_start_flag
start flag
Definition DesSer.h:181
int n_basf2evt
No. of sent events.
Definition DesSer.h:70
int m_run_pause
flag to show that run-controller pauses a run
Definition DesSer.h:227
int m_run_error
flag to show that there is some errors with which DAQ cannot continue.
Definition DesSer.h:230
double cur_time
for time monitoring
Definition DesSer.h:102
int m_prev_nevt
No. of prev sent events.
Definition DesSer.h:73
unsigned int m_exprunsubrun_no
run no.
Definition DesSer.h:144
double max_seconds
time to stop a run
Definition DesSer.h:64
static double getTimeSec()
store time info.
Definition DesSer.cc:480
unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
virtual void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes)
set buffer ( delete_flag : m_buffer is freed( = 0 )/ not freed( = 1 ) in Destructor )

◆ fillSendHeaderTrailer()

void fillSendHeaderTrailer ( SendHeader * hdr,
SendTrailer * trl,
RawDataBlockFormat * rawdblk )
inherited

Definition at line 171 of file DesSer.cc.

172{
173
174 int total_send_nwords =
175 hdr->GetHdrNwords() +
176 rawdblk->TotalBufNwords() +
177 // rawhdr.GetNwords() +
178 trl->GetTrlNwords();
179
180 hdr->SetNwords(total_send_nwords);
181 hdr->SetNumEventsinPacket(rawdblk->GetNumEvents());
182 hdr->SetNumNodesinPacket(rawdblk->GetNumNodes());
183
184 //
185 // For bug check
186 //
187 if (rawdblk->GetNumEntries() == 1) {
188 if (total_send_nwords != (rawdblk->GetBuffer(0))[ 0 ] + 8) {
189 char err_buf[500];
190 sprintf(err_buf, "Length error. total length %d rawdblk length %d. Exting...\n",
191 total_send_nwords, (rawdblk->GetBuffer(0))[ 0 ]);
192 printData(rawdblk->GetBuffer(0), rawdblk->TotalBufNwords());
193 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
194 sleep(1234567);
195 exit(-1);
196 }
197 }
198
199
200 for (int i = 0; i < rawdblk->GetNumEntries(); i++) {
201
202 //copy event # from a tonp COPPER block
203 if (!(rawdblk->CheckFTSWID(i)) && !(rawdblk->CheckTLUID(i))) {
204 tmp_header.SetBuffer(rawdblk->GetBuffer(i));
205 hdr->SetEventNumber(tmp_header.GetEveNo());
206 hdr->SetNodeID(tmp_header.GetNodeID());
207 hdr->SetExpRunWord(tmp_header.GetExpRunSubrun());
208 break;
209 }
210
211 //Error if you cannot find any COPPER block
212 if (i == (rawdblk->GetNumEntries() - 1)) {
213 printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", i, rawdblk->GetNumEntries(), rawdblk->TotalBufNwords());
214 printData(rawdblk->GetBuffer(0), rawdblk->TotalBufNwords());
215
216 const char err_buf[500] = "[FATAL] CORRUPTED DATA: No COPPER blocks in RawDataBlock. Exiting...";
217 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
218 sleep(1234567);
219 exit(-1);
220 }
221 }
222 return;
223}
static void printData(const int *buf, int nwords)
dump error data
Definition DesSer.cc:507
RawHeader_v2 tmp_header
which format is used
Definition DesSer.h:323
virtual int CheckFTSWID(int n)
get FTSW ID to check whether this data block is FTSW data or not
virtual int GetNumEntries()
get # of data blocks = (# of nodes)*(# of events)
virtual int TotalBufNwords()
Get total length of m_buffer.
virtual int GetNumNodes()
get # of data sources(e.g. # of COPPER boards) in m_buffer
virtual int * GetBuffer(int n)
get nth buffer pointer
virtual int GetNumEvents()
get # of events in m_buffer
virtual int CheckTLUID(int n)
get FTSW ID to check whether this data block is FTSW data or not
void SetNumEventsinPacket(int num_events)
set contents of Header
Definition SendHeader.cc:61
static int GetHdrNwords()
get contents of Header
void SetNwords(int total_data_nwords)
initialize Header
Definition SendHeader.cc:51

◆ getNewBuffer()

int * getNewBuffer ( int nwords,
int * delete_flag )
inherited

Getbuffer.

Definition at line 77 of file DesSer.cc.

78{
79
80 int* temp_buf = NULL;
81 // Prepare buffer
82 if (nwords > BUF_SIZE_WORD) {
83 *delete_flag = 1;
84 temp_buf = new int[ nwords ];
85 } else {
86 if ((temp_buf = getPreAllocBuf()) == 0x0) {
87 char err_buf[500];
88 sprintf(err_buf, "Null pointer from GetPreALlocBuf(). Exting...\n");
89 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
90 sleep(1234567);
91 exit(1);
92 } else {
93 *delete_flag = 0;
94 }
95 }
96
97 return temp_buf;
98
99}
int * getPreAllocBuf()
Getbuffer.
Definition DesSer.cc:57

◆ getPreAllocBuf()

int * getPreAllocBuf ( )
inherited

Getbuffer.

Definition at line 57 of file DesSer.cc.

58{
59 int* tempbuf = 0;
60 if (m_num_usedbuf < NUM_PREALLOC_BUF) {
61 tempbuf = m_bufary[ m_num_usedbuf ];
63 } else {
64 char err_buf[500];
65 sprintf(err_buf,
66 "No pre-allocated buffers are left. %d > %d. Not enough buffers are allocated or "
67 "memory leak or forget to call ClearNumUsedBuf every event loop. Exting...",
68 m_num_usedbuf, NUM_PREALLOC_BUF);
69 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
70 sleep(1234567);
71 exit(1);
72 }
73 return tempbuf;
74}
int m_num_usedbuf
Definition DesSer.h:132
int * m_bufary[NUM_PREALLOC_BUF]
buffer
Definition DesSer.h:85

◆ getTimeSec()

double getTimeSec ( )
staticinherited

store time info.

Definition at line 480 of file DesSer.cc.

481{
482 struct timeval t;
483 gettimeofday(&t, NULL);
484 return (t.tv_sec + t.tv_usec * 1.e-6);
485}

◆ initialize()

void initialize ( bool close_listen = true)
inherited

Definition at line 101 of file DesSer.cc.

102{
103 printf("[DEBUG] DesSer: initialize() started.\n"); fflush(stdout);
104 signal(SIGPIPE, SIG_IGN);
105
106 //
107 // initialize Rx part from DeSerializer**.cc
108 //
109
110 // allocate buffer
111 for (int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
112 m_bufary[i] = new int[ BUF_SIZE_WORD ];
113 }
114 m_buffer = new int[ BUF_SIZE_WORD ];
115
116 // initialize buffer
117 for (int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
118 memset(m_bufary[i], 0, BUF_SIZE_WORD * sizeof(int));
119 }
120
121 // Open message handler
122 clearNumUsedBuf();
123 // Shared memory
124 if (m_shmflag > 0) {
125 if (m_nodename.size() == 0 || m_nodeid < 0) {
126 m_shmflag = 0;
127 } else {
129 m_status.reportReady();
130 }
131 }
132
133 event_diff = 0;
134
135 m_prev_copper_ctr = 0xFFFFFFFF;
136 m_prev_evenum = 0xFFFFFFFF;
137
138
139 //
140 // initialize Rx part from DeSerializer**.cc
141 //
142 m_start_flag = 0;
143 n_basf2evt = -1;
145
146#ifdef DUMMY
147 m_buffer = new int[ BUF_SIZE_WORD ];
148#endif
149 Accept(close_listen);
150#ifdef NONSTOP
151 openRunPauseNshm();
152#endif
153
154
155 // For monitor
156 if (m_status.isAvailable()) {
157 m_status.setOutputNBytes(0);
158 m_status.setOutputCount(0);
159 }
160 // B2INFO("DesSer: initialize() was done.");
161 printf("[DEBUG] DesSer: initialize() was done.\n"); fflush(stdout);
162
163}
int * m_buffer
buffer
Definition DesSer.h:82
int m_compressionLevel
Compression Level.
Definition DesSer.h:67

◆ initializeCOPPER()

void initializeCOPPER ( )

Module functions to be called from main process.

Definition at line 450 of file DesSerCOPPER.cc.

451{
452
453#ifndef DUMMY
454 m_use_slot = 0; /* bit mask */
455 int slot_shift;
456
457 if ((m_finesse_bit_flag & 0x1) == 1) {
458 slot_shift = 0; // a:0, b:1, c:2, d:3
459 m_use_slot |= 1 << slot_shift; //
460 }
461
462 if (((m_finesse_bit_flag >> 1) & 0x1) == 1) {
463 slot_shift = 1; // a:0, b:1, c:2, d:3
464 m_use_slot |= 1 << slot_shift; //
465 }
466
467 if (((m_finesse_bit_flag >> 2) & 0x1) == 1) {
468 slot_shift = 2; // a:0, b:1, c:2, d:3
469 m_use_slot |= 1 << slot_shift; //
470 }
471
472 if (((m_finesse_bit_flag >> 3) & 0x1) == 1) {
473 slot_shift = 3; // a:0, b:1, c:2, d:3
474 m_use_slot |= 1 << slot_shift; //
475 }
476 //
477 // Present slots to use
478 //
479 if (! m_use_slot) {
480 const char err_buf[100] = "[FATAL] Slot is not specified. Exiting...";
481 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
482 exit(1);
483 } else {
484 int slot;
485 printf("[DEBUG] ");
486 for (slot = 0; slot < 4; slot++) {
487 if (m_use_slot & (1 << slot)) printf(" %c", 'A' + slot);
488 }
489 printf("\n");
490 }
491
492
493#endif
494
495#ifndef YAMADA_DUMMY
496 // B2INFO("Opening COPPER..."); fflush(stderr);
497 printf("[DEBUG] Opening COPPER...\n"); fflush(stdout);
498 openCOPPER();
499 // B2INFO("Done.\n"); fflush(stderr);
500 printf("[DEBUG] Done.\n"); fflush(stdout);
501#endif
502}
int m_use_slot
bit flag of FINESSE slots to use
void openCOPPER()
open COPPER

◆ openCOPPER()

void openCOPPER ( )

open COPPER

Definition at line 505 of file DesSerCOPPER.cc.

506{
507
508 if (m_cpr_fd != -1) {
509 close(m_cpr_fd);
510 m_cpr_fd = -1;
511 }
512 //
513 // Open a finesse device
514 //
515 if ((m_cpr_fd = open("/dev/copper/copper", O_RDONLY)) == -1) {
516 char err_buf[500];
517 sprintf(err_buf, "[FATAL] Failed to open /dev/copper/copper. Exiting... ");
518 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
519 exit(1);
520 }
521
522 int set_regval = 15; // How many events to be stored in COPPER FIFO before request for DMA
523 // int set_regval=1;
524 ioctl(m_cpr_fd, CPRIOSET_LEF_WA_FF, &set_regval);
525 ioctl(m_cpr_fd, CPRIOSET_LEF_WB_FF, &set_regval);
526 ioctl(m_cpr_fd, CPRIOSET_LEF_WC_FF, &set_regval);
527 ioctl(m_cpr_fd, CPRIOSET_LEF_WD_FF, &set_regval);
528 ioctl(m_cpr_fd, CPRIOSET_FINESSE_STA, &m_use_slot, sizeof(m_use_slot));
529
530 int v = 511 - 32;
531
532 ioctl(m_cpr_fd, CPRIOSET_LEF_WA_AF, &v, sizeof(v));
533 ioctl(m_cpr_fd, CPRIOSET_LEF_WB_AF, &v, sizeof(v));
534 ioctl(m_cpr_fd, CPRIOSET_LEF_WC_AF, &v, sizeof(v));
535 ioctl(m_cpr_fd, CPRIOSET_LEF_WD_AF, &v, sizeof(v));
536
537
538 // B2INFO("DeSerializerCOPPER: openCOPPER() done.");
539 printf("[DEBUG] DeSerializerCOPPER: openCOPPER() done.\n"); fflush(stdout);
540
541}
int m_cpr_fd
file descripter for COPPER

◆ printData()

void printData ( const int * buf,
int nwords )
staticinherited

dump error data

Definition at line 507 of file DesSer.cc.

508{
509 printf("[DEBUG]");
510 for (int i = 0; i < nwords; i++) {
511 printf("%.8x ", buf[ i ]);
512 if (i % 10 == 9) printf("\n[DEBUG]");
513 }
514 printf("\n[DEBUG]");
515 printf("\n");
516 return;
517}

◆ readFD()

int readFD ( int fd,
char * buf,
int data_size_byte,
int delete_flag )

receive data

Definition at line 545 of file DesSerCOPPER.cc.

546{
547
548 int n = 0;
549 while (1) {
550 int read_size = 0;
551 if ((read_size = read(fd, static_cast<char*>(buf) + n, data_size_byte - n)) < 0) {
552 if (errno == EINTR) {
553 continue;
554 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
555 if (n > 0) {
556 char err_buf[500];
557 sprintf(err_buf, "[FATAL] Return due to EAGAIN in the middle of an event( COPPER driver would't do this.). Exting...");
558 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
559 exit(-1);
560 }
561#ifdef NONSTOP
562 // Check run-pause request from SLC
563 string err_str;
564 try {
565 callCheckRunPause(err_str);
566 } catch (const string& err_string) {
567 if (delete_flag) {
568 // Delete allocated buffer
569 // B2WARNING("Delete buffer before going to Run-pause state");
570 printf("[WARNING] Delete buffer before going to Run-pause state\n"); fflush(stdout);
571 delete buf;
572 }
573 throw (err_string);
574 }
575#endif
576 continue;
577 } else {
578#ifdef NONSTOP
579 m_run_error = 1;
580 // B2ERROR(err_buf);
581 printf("[ERROR] Failed to read data from COPPER. %s %s %d",
582 __FILE__, __PRETTY_FUNCTION__, __LINE__);
583 string err_str = "RUN_ERROR";
584 throw (err_str);
585#endif
586 char err_buf[500];
587 sprintf(err_buf, "[FATAL] Failed to read data from COPPER. %s %s %d",
588 __FILE__, __PRETTY_FUNCTION__, __LINE__);
589 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
590 exit(-1);
591 }
592 } else {
593 n += read_size;
594 if (n == data_size_byte)break;
595 }
596 }
597 return n;
598}

◆ readOneEventFromCOPPERFIFO()

int * readOneEventFromCOPPERFIFO ( const int entry,
int * delete_flag,
int * m_size_word )

Read one event from COPPER.

Definition at line 322 of file DesSerCOPPER.cc.

323{
324
325 // prepare buffer
326 *m_size_word = 0;
327 int* temp_buf = m_bufary[ entry ];
328 temp_buf[0] = BUF_SIZE_WORD ;
329 *delete_flag = 0;
330
331 //
332 // Read data from HSLB
333 //
334#ifndef DUMMY
335 int recvd_byte = (m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) * sizeof(int);
336 // Firstly, read data with an allocated buffer.
337 while (1) {
338 int read_size = 0;
339 if ((read_size = read(m_cpr_fd, reinterpret_cast<char*>(m_bufary[entry]) + recvd_byte,
340 sizeof(int) * BUF_SIZE_WORD - recvd_byte)) < 0) {
341 if (errno == EINTR) {
342 continue;
343 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
344
345 if (recvd_byte > (int)((m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) * sizeof(int))) {
346 char err_buf[500];
347 sprintf(err_buf, "[FATAL] EAGAIN return in the middle of an event( COPPER driver should't do this.). Exting...");
348 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
349 exit(-1);
350 }
351
352#ifdef NONSTOP
353 // Check run-pause request from SLC
354 string err_str;
355 callCheckRunPause(err_str);
356#endif
357 continue;
358
359 } else {
360 char err_buf[500];
361 sprintf(err_buf, "[FATAL] Failed to read data from COPPER. Exiting...");
362 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
363 exit(-1);
364 }
365 } else {
366 recvd_byte += read_size;
367 if (recvd_byte - (m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) * sizeof(int) > (int)(sizeof(int) *
368 (m_pre_rawcpr.POS_DATA_LENGTH + 1)))break;
369 }
370 }
371
372 //
373 // Calcurate data size
374 //
375 *m_size_word = m_bufary[ entry ][ static_cast<int>(m_pre_rawcpr.POS_DATA_LENGTH)
376 + static_cast<int>(m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS) ]
377 + m_pre_rawcpr.SIZE_COPPER_DRIVER_HEADER + m_pre_rawcpr.SIZE_COPPER_DRIVER_TRAILER
378 + m_pre_rawcpr.tmp_header.RAWHEADER_NWORDS +
379 m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS; // 9 words are COPPER haeder and trailer size.
380
381 //
382 // If there are data remaining to be read, continue reading
383 //
384 if ((int)((*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int)) > recvd_byte) {
385
386 // If event size is larger than BUF_SIZE_WORD, allocate a new buffer
387 if (*m_size_word > BUF_SIZE_WORD) {
388 *delete_flag = 1;
389 temp_buf = new int[ *m_size_word ];
390 memcpy(temp_buf, m_bufary[ entry ], recvd_byte);
391 recvd_byte += readFD(m_cpr_fd, reinterpret_cast<char*>(temp_buf) + recvd_byte,
392 (*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int) - recvd_byte, *delete_flag);
393 } else {
394
395 recvd_byte += readFD(m_cpr_fd, reinterpret_cast<char*>((m_bufary[ entry ])) + recvd_byte,
396 (*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int) - recvd_byte, *delete_flag);
397 }
398
399 if ((int)((*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int)) != recvd_byte) {
400 char err_buf[500];
401
402 sprintf(err_buf, "[FATAL] CORRUPTED DATA: Read less bytes(%d) than expected(%lu:%d). Exiting...\n",
403 recvd_byte,
404 *m_size_word * sizeof(int) - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS * sizeof(int),
405 m_bufary[ entry ][ m_pre_rawcpr.POS_DATA_LENGTH ]);
406 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
407 exit(-1);
408 }
409 } else if ((int)((*m_size_word - m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS) * sizeof(int)) < recvd_byte) {
410 char err_buf[500];
411 sprintf(err_buf, "[FATAL] CORRUPTED DATA: Read more than data size. Exiting...: %d %zu %lu %d %d\n",
412 recvd_byte, *m_size_word * sizeof(int), m_pre_rawcpr.tmp_trailer.RAWTRAILER_NWORDS * sizeof(int),
413 m_bufary[ entry ][ m_pre_rawcpr.POS_DATA_LENGTH ], m_pre_rawcpr.POS_DATA_LENGTH);
414 print_err.PrintError(m_shmflag, &m_status, err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
415 exit(-1);
416 }
417#else
418 //
419 // Make dummy data
420 //
421 *m_size_word = 256 + entry;
422 m_bufary[entry][0] = *m_size_word;
423#endif
424
425 //
426 // Fill Data length
427 //
428 temp_buf[ 0 ] = *m_size_word;
429
430
431#ifdef TIME_MONITOR
432 if (n_basf2evt >= 50000 && n_basf2evt < 50500) {
434 time_array2[ n_basf2evt - 50000 ] = cur_time - m_start_time;
435 }
436#endif
437
438#ifdef CHECK_SUM
439 unsigned int checksum = 0;
440 for (int i = 0; i < m_bufary[entry][0]; i++) {
441 if (i != 2) checksum += m_bufary[entry][i];
442 }
443 m_bufary[entry][2] = checksum;
444#endif
445 return temp_buf;
446}
int readFD(int fd, char *buf, int data_size_byte, int delete_flag)
receive data
PreRawCOPPERFormat_v2 m_pre_rawcpr
report status to SLC
Definition DesSer.h:191
RawTrailer_v2 tmp_trailer
trailer ( not recorded )
RawHeader_v2 tmp_header
header ( not recorded )

◆ recordTime()

void recordTime ( int event,
double * array )
inherited

store time info.

Definition at line 488 of file DesSer.cc.

489{
490 if (event >= 50000 && event < 50500) {
491 array[ event - 50000 ] = getTimeSec() - m_start_time;
492 }
493 return;
494}

◆ Send()

int Send ( int socket,
char * buf,
int size_bytes )
inherited

send buffer

Definition at line 329 of file DesSer.cc.

330{
331 int sent_bytes = 0;
332 while (true) {
333 int ret = 0;
334 if ((ret = send(socket,
335 buf + sent_bytes, size_bytes - sent_bytes, MSG_NOSIGNAL)) < 0) {
336 if (errno == EINTR) {
337 continue;
338 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
339#ifdef NONSTOP
340 string err_str;
341 callCheckRunPause(err_str);
342#endif
343 continue;
344 } else {
345 char err_buf[500];
346 sprintf(err_buf, "[WARNING] SEND ERROR.(%s)", strerror(errno));
347#ifdef NONSTOP
348 m_run_error = 1;
349 // B2ERROR(err_buf);
350 printf("%s\n", err_buf); fflush(stdout);
351 string err_str = "RUN_ERROR";
352 throw (err_str); // To exit this module, go to DeSerializer** and wait for run-resume.
353#else
354 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
355 exit(1);
356#endif
357 }
358 }
359 sent_bytes += ret;
360 if (sent_bytes == size_bytes) break;
361 }
362 return sent_bytes;
363}

◆ sendByWriteV()

int sendByWriteV ( RawDataBlockFormat * rawdblk)
inherited

Definition at line 227 of file DesSer.cc.

228{
229 SendHeader send_header;
230 SendTrailer send_trailer;
231 fillSendHeaderTrailer(&send_header, &send_trailer, rawdblk);
232
233 enum {
234 NUM_BUFFER = 3
235 };
236 struct iovec iov[ NUM_BUFFER ];
237
238 // check Body data size
239 int rawcopper_nwords = rawdblk->TotalBufNwords();
240
241 //Fill iov info.
242 iov[0].iov_base = reinterpret_cast<char*>(send_header.GetBuffer());
243 iov[0].iov_len = sizeof(int) * send_header.GetHdrNwords();
244
245 iov[1].iov_base = reinterpret_cast<char*>(rawdblk->GetWholeBuffer());
246 iov[1].iov_len = sizeof(int) * rawcopper_nwords;
247
248 iov[2].iov_base = reinterpret_cast<char*>(send_trailer.GetBuffer());
249 iov[2].iov_len = sizeof(int) * send_trailer.GetTrlNwords();
250
251 // Send Multiple buffers
252 int n = 0;
253 while (true) {
254 if ((n = writev(m_socket_send, iov, NUM_BUFFER)) < 0) {
255 if (errno == EINTR) {
256 continue;
257 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
258#ifdef NONSTOP
259 string err_str;
260 callCheckRunPause(err_str);
261#endif
262 continue;
263 } else {
264 char err_buf[500];
265 sprintf(err_buf, "[WARNING] WRITEV error.(%s) : sent %d bytes, header %lu bytes body %lu trailer %lu\n",
266 strerror(errno), n, iov[0].iov_len, iov[1].iov_len, iov[2].iov_len);
267#ifdef NONSTOP
268 m_run_error = 1;
269 // B2ERROR(err_buf);
270 printf("%s\n", err_buf); fflush(stdout);
271 string err_str = "RUN_ERROR";
272 throw (err_str); // To exit this module, go to DeSerializer** and wait for run-resume.
273#else
274 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
275 exit(1);
276#endif
277 }
278 }
279 break;
280 }
281
282#ifdef DEBUG
283 printf("[DEBUG] *******BODY**********\n");
284 printf("[DEBUG] \n%.8d : ", 0);
285 printData((int*)(iov[1].iov_base), iov[1].iov_len);
286#endif
287
288
289 int total_send_bytes = sizeof(int) * send_header.GetTotalNwords();
290
291
292 //
293 // Retry sending
294 //
295 if (n != total_send_bytes) {
296 // B2WARNING("Serializer: Sent byte(" << n << "bytes) is not same as the event size (" << total_send_bytes << "bytes). Retrying...");
297 printf("[WARNING] Serializer: Sent byte( %d bytes) is not same as the event size ( %d bytes). Retrying...\n", n,
298 total_send_bytes); // back to WARNING due to request from Konno-san on 2018/7/3
299 fflush(stdout);
300
301 double retry_start = getTimeSec();
302 // Send Header
303 if (n < (int)(iov[ 0 ].iov_len)) {
304 n += Send(m_socket_send, static_cast<char*>(iov[ 0 ].iov_base) + n, iov[ 0 ].iov_len - n);
305 }
306
307 if (n < (int)(iov[ 0 ].iov_len + iov[ 1 ].iov_len)) {
308 n += Send(m_socket_send, static_cast<char*>(iov[ 1 ].iov_base) + (n - iov[ 0 ].iov_len), iov[ 1 ].iov_len - (n - iov[ 0 ].iov_len));
309 }
310
311 if (n < (int)(iov[ 0 ].iov_len + iov[ 1 ].iov_len + iov[ 2 ].iov_len)) {
312 // cppcheck-suppress unreadVariable ; the tail send is best effort
313 n += Send(m_socket_send, static_cast<char*>(iov[ 2 ].iov_base) + (n - iov[ 0 ].iov_len - iov[ 1 ].iov_len),
314 iov[ 2 ].iov_len - (n - iov[ 0 ].iov_len - iov[ 1 ].iov_len));
315 }
316 double retry_end = getTimeSec();
317 // B2WARNING("Resending ends. It takes " << retry_end - retry_start << "(s)");
318 printf("[WARNING] Resending ends. It takes %lf (s)\n", retry_end - retry_start);
319 fflush(stdout); // back to WARNING due to request from Konno-san on 2018/7/3
320 }
321 // printf( "[DEBUG] n %d total %d\n", n, total_send_bytes);
322 // delete temp_buf;
323
324 return total_send_bytes;
325
326}
int Send(int socket, char *buf, int size_bytes)
send buffer
Definition DesSer.cc:329
virtual int * GetWholeBuffer()
get pointer to buffer(m_buffer)
int * GetBuffer(void)
Get Header contents.
Definition SendHeader.cc:32

◆ shmOpen()

void shmOpen ( char * path_cfg,
char * path_sta )
staticinherited

open shared memory

Definition at line 681 of file DesSer.cc.

683{
684 errno = 0;
685 /*m_shmfd_cfg = shm_open( "/cpr_config2", O_CREAT | O_EXCL | O_RDWR, 0666);
686 if (m_shmfd_cfg < 0) {
687 if (errno != EEXIST) {
688 perror("shm_open1");
689 exit(1);
690 }
691 m_shmfd_cfg = shm_open(path_cfg, O_RDWR, 0666);
692 if (m_shmfd_cfg < 0) {
693 printf( "[DEBUG] %s\n", path_cfg);
694 perror("[ERROR] shm_open2");
695 exit(1);
696 }
697 */
698 //}
699 /*
700 m_shmfd_sta = shm_open( "/cpr_status2", O_CREAT | O_EXCL | O_RDWR, 0666);
701 if (m_shmfd_sta < 0) {
702 if (errno != EEXIST) {
703 perror("shm_open1");
704 exit(1);
705 }
706 m_shmfd_sta = shm_open(path_sta , O_RDWR, 0666);
707 if (m_shmfd_sta < 0) {
708 printf( "[DEBUG] %s\n", path_sta);
709 perror("[ERROR] shm_open2");
710 exit(1);
711 }
712 //}
713 int size = 4 * sizeof(int);
714 ftruncate(m_shmfd_cfg, size);
715 ftruncate(m_shmfd_sta, size);
716 */
717}

Member Data Documentation

◆ cur_time

double cur_time = 0.0
inherited

for time monitoring

Definition at line 102 of file DesSer.h.

◆ event_diff

int event_diff = 0
protectedinherited

Definition at line 256 of file DesSer.h.

◆ m_bufary

int* m_bufary[NUM_PREALLOC_BUF] = {}
inherited

buffer

Definition at line 85 of file DesSer.h.

85{};

◆ m_buffer

int* m_buffer = nullptr
inherited

buffer

Definition at line 82 of file DesSer.h.

◆ m_cfg_buf

int* m_cfg_buf = nullptr
inherited

buffer for shared memory

Definition at line 221 of file DesSer.h.

◆ m_cfg_sta

int* m_cfg_sta = nullptr
inherited

buffer for shared memory

Definition at line 224 of file DesSer.h.

◆ m_compressionLevel

int m_compressionLevel = 0
inherited

Compression Level.

Definition at line 67 of file DesSer.h.

◆ m_cpr_fd

int m_cpr_fd = 0

file descripter for COPPER

Definition at line 54 of file DesSerCOPPER.h.

◆ m_data_type

int m_data_type = 0
inherited

data type

Definition at line 153 of file DesSer.h.

◆ m_dump_fname

std::string m_dump_fname
inherited

dump filename

Definition at line 76 of file DesSer.h.

◆ m_exp_no

int m_exp_no = 0
inherited

exp no.

Definition at line 150 of file DesSer.h.

◆ m_exprunsubrun_no

unsigned int m_exprunsubrun_no
inherited

run no.

Definition at line 144 of file DesSer.h.

◆ m_finesse_bit_flag

int m_finesse_bit_flag

bit flag of FINESSE slots to use

Definition at line 60 of file DesSerCOPPER.h.

◆ m_fp_dump

FILE* m_fp_dump = nullptr
inherited

dump file descripter

Definition at line 79 of file DesSer.h.

◆ m_hostname_from

std::vector<std::string> m_hostname_from
protectedinherited

Reciever basf2 Socket.

hostname of upstream Data Sources

Definition at line 243 of file DesSer.h.

◆ m_hostname_local

std::string m_hostname_local
protectedinherited

Destination Host.

Definition at line 275 of file DesSer.h.

◆ m_ncycle

int m_ncycle = 0
inherited

Definition at line 100 of file DesSer.h.

◆ m_nodeid

int m_nodeid = 0
inherited

Node ID for SLC.

Definition at line 138 of file DesSer.h.

◆ m_nodename

std::string m_nodename
inherited

Node Name for SLC.

Definition at line 135 of file DesSer.h.

◆ m_num_connections

int m_num_connections
protectedinherited

check data contents

of connections

Definition at line 237 of file DesSer.h.

◆ m_num_usedbuf

int m_num_usedbuf = 0
inherited

of already used buffers

Definition at line 132 of file DesSer.h.

◆ m_port_from

std::vector<int> m_port_from
protectedinherited

port # to connect data sources

Definition at line 246 of file DesSer.h.

◆ m_port_to

int m_port_to = 0
protectedinherited

Destination port.

Definition at line 278 of file DesSer.h.

◆ m_pre_rawcpr

PreRawCOPPERFormat_v2 m_pre_rawcpr
inherited

report status to SLC

Use ver.2 for the moment(ver.4 -> PCI40)

Definition at line 191 of file DesSer.h.

◆ m_prev_copper_ctr

unsigned int m_prev_copper_ctr = 0
protectedinherited

Definition at line 258 of file DesSer.h.

◆ m_prev_evenum

unsigned int m_prev_evenum = 0
protectedinherited

Definition at line 260 of file DesSer.h.

◆ m_prev_exprunsubrun_no

unsigned int m_prev_exprunsubrun_no
inherited

run no.

Definition at line 147 of file DesSer.h.

◆ m_prev_nevt

int m_prev_nevt = 0
inherited

No. of prev sent events.

Definition at line 73 of file DesSer.h.

◆ m_prev_time

double m_prev_time = 0.0
inherited

Definition at line 105 of file DesSer.h.

◆ m_recvd_prev_totbytes

double m_recvd_prev_totbytes = 0.0
inherited

Definition at line 97 of file DesSer.h.

◆ m_recvd_totbytes

double m_recvd_totbytes = 0.0
inherited

Definition at line 96 of file DesSer.h.

◆ m_run_error

int m_run_error = 0
inherited

flag to show that there is some errors with which DAQ cannot continue.

Definition at line 230 of file DesSer.h.

◆ m_run_pause

int m_run_pause = 0
inherited

flag to show that run-controller pauses a run

Definition at line 227 of file DesSer.h.

◆ m_sent_prev_totbytes

double m_sent_prev_totbytes = 0.0
inherited

Definition at line 99 of file DesSer.h.

◆ m_sent_totbytes

double m_sent_totbytes = 0.0
inherited

Definition at line 98 of file DesSer.h.

◆ m_shmfd_cfg

int m_shmfd_cfg = 0
inherited

file descripter for shm

Definition at line 168 of file DesSer.h.

◆ m_shmfd_sta

int m_shmfd_sta = 0
inherited

file descripter for shm

Definition at line 171 of file DesSer.h.

◆ m_shmflag

int m_shmflag = 0
inherited

Use shared memory.

Definition at line 159 of file DesSer.h.

◆ m_socket_recv

std::vector<int> m_socket_recv
protectedinherited

Definition at line 248 of file DesSer.h.

◆ m_socket_send

int m_socket_send = 0
protectedinherited

Reciever Socket.

Definition at line 267 of file DesSer.h.

◆ m_start_flag

int m_start_flag = 0
inherited

start flag

Definition at line 181 of file DesSer.h.

◆ m_start_time

double m_start_time = 0.0
inherited

Definition at line 104 of file DesSer.h.

◆ m_status

RunInfoBuffer m_status
inherited

Run info buffer.

Definition at line 141 of file DesSer.h.

◆ m_t0

timeval m_t0
inherited

Definition at line 95 of file DesSer.h.

◆ m_trunc_mask

int m_trunc_mask = 0
inherited

trunc mask

Definition at line 156 of file DesSer.h.

◆ m_use_slot

int m_use_slot = 0

bit flag of FINESSE slots to use

Definition at line 57 of file DesSerCOPPER.h.

◆ max_nevt

int max_nevt = 0
inherited

of events in a run

Definition at line 61 of file DesSer.h.

◆ max_seconds

double max_seconds = 0.0
inherited

time to stop a run

Definition at line 64 of file DesSer.h.

◆ monitor_numeve

int monitor_numeve = 0
inherited

buffer for shared memory

buffer for shared memory

Definition at line 178 of file DesSer.h.

◆ n_basf2evt

int n_basf2evt = 0
inherited

No. of sent events.

Definition at line 70 of file DesSer.h.

◆ p_method

std::string p_method
protectedinherited

EvtSocket.

How to handle data

Definition at line 284 of file DesSer.h.

◆ p_method_val

int p_method_val = 0
protectedinherited

Definition at line 285 of file DesSer.h.

◆ prev_event

int prev_event = 0
inherited

Definition at line 106 of file DesSer.h.

◆ print_err

CprErrorMessage print_err
inherited

wrapper for B2LOG system

Definition at line 184 of file DesSer.h.

◆ tmp_header

RawHeader_v2 tmp_header
protectedinherited

which format is used

Definition at line 323 of file DesSer.h.


The documentation for this class was generated from the following files: