Belle II Software development
Serializer.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include <daq/rawdata/modules/DAQConsts.h>
9#include <daq/rawdata/modules/Serializer.h>
10#include <daq/rawdata/modules/DeSerializer.h>
11
12#include <netinet/tcp.h>
13
14#include <sys/uio.h>
15
16#include <csignal>
17#include <fcntl.h>
18
19using namespace std;
20using namespace Belle2;
21
22//#define DEBUG
23
24//-----------------------------------------------------------------
25// Register the Module
26//-----------------------------------------------------------------
27REG_MODULE(Serializer);
28
29//-----------------------------------------------------------------
30// Implementation
31//-----------------------------------------------------------------
32
33
34
36{
37 //Set module properties
38 setDescription("Encode DataStore into RingBuffer");
39 addParam("DestPort", m_port_to, "Destination port", BASE_PORT_ROPC_COPPER);
40 addParam("LocalHostName", m_hostname_local, "local host", string(""));
41#ifdef DUMMY
42 addParam("EventDataBufferWords", BUF_SIZE_WORD, "DataBuffer words per event", 4800);
43#endif
44 addParam("use Shared Memory", m_shmflag, "m_shmflag", 0);
45
46 m_start_flag = 0;
47 n_basf2evt = -1;
49
50 //Parameter definition
51 B2INFO("Tx: Constructor done.");
52
53}
54
55
56
57SerializerModule::~SerializerModule()
58{
59}
60
62{
63 signal(SIGPIPE, SIG_IGN);
64
65#ifdef DUMMY
66 m_buffer = new int[ BUF_SIZE_WORD ];
67#endif
68
69
70 if (m_shmflag != 0) {
71 char temp_char1[100] = "/cpr_config";
72 char temp_char2[100] = "/cpr_status";
73 shmOpen(temp_char1, temp_char2);
74 // Status format : status_flag
77 m_cfg_sta[ 0 ] = 1; // Status bit is 1 : ready before accept()
78 }
79
80 // Create Message Handler
81 memset(time_array0, 0, sizeof(time_array0));
82 memset(time_array1, 0, sizeof(time_array1));
83 memset(time_array2, 0, sizeof(time_array2));
84
85 RunInfoBuffer& status(DeSerializerModule::getStatus());
86 if (status.isAvailable()) {
87 status.setOutputNBytes(0);
88 status.setOutputCount(0);
89 }
90
91 Accept();
92
93#ifdef NONSTOP
94 openRunPauseNshm();
95#endif
96
97 B2INFO("Tx initialized.");
98}
99
100
101
103{
104 B2INFO("beginRun called.");
105}
106
107
108
109
111{
112 //fill Run data
113 B2INFO("endRun done.");
114}
115
116
118{
119 B2INFO("terminate called");
120}
121
122
123
124//
125// User defined functions
126//
127
128
129
130int* SerializerModule::shmGet(int fd, int size_words)
131{
132 int offset = 0;
133 return (int*)mmap(NULL, size_words * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset);
134}
135
136void SerializerModule::shmOpen(char* path_cfg, char* path_sta)
137{
138 errno = 0;
139 m_shmfd_cfg = shm_open(path_cfg, O_RDWR, 0666);
140 if (m_shmfd_cfg < 0) {
141 char err_buf[500];
142 sprintf(err_buf, "[FATAL] Failed to shm_open (%s). Exiting... : path %s\n",
143 strerror(errno), path_cfg);
144 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
145 sleep(1234567);
146 exit(1);
147 }
148
149 m_shmfd_sta = shm_open(path_sta, O_RDWR, 0666);
150 if (m_shmfd_sta < 0) {
151 char err_buf[500];
152 sprintf(err_buf, "[FATAL] Failed to shm_open (%s). Exiting... : path %s\n",
153 strerror(errno), path_sta);
154 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
155 sleep(1234567);
156 exit(1);
157 }
158
159 int size = 4 * sizeof(int);
160 ftruncate(m_shmfd_cfg, size);
161 ftruncate(m_shmfd_sta, size);
162}
163
164
165
166void SerializerModule::fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl,
167 RawDataBlock* rawdblk)
168{
169
170 int total_send_nwords =
171 hdr->GetHdrNwords() +
172 rawdblk->TotalBufNwords() +
173 // rawhdr.GetNwords() +
174 trl->GetTrlNwords();
175
176 hdr->SetNwords(total_send_nwords);
177 hdr->SetNumEventsinPacket(rawdblk->GetNumEvents());
178 hdr->SetNumNodesinPacket(rawdblk->GetNumNodes());
179
180 //
181 // For bug check
182 //
183 if (rawdblk->GetNumEntries() == 1) {
184 if (total_send_nwords != (rawdblk->GetBuffer(0))[ 0 ] + 8) {
185 char err_buf[500];
186 sprintf(err_buf, "[FATAL] Length error. total length %d rawdblk length %d. Exting...\n",
187 total_send_nwords, (rawdblk->GetBuffer(0))[ 0 ]);
188 printData(rawdblk->GetBuffer(0), rawdblk->TotalBufNwords());
189 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
190 sleep(1234567);
191 exit(-1);
192 }
193 }
194
195
196 for (int i = 0; i < rawdblk->GetNumEntries(); i++) {
197
198 //copy event # from a tonp COPPER block
199 if (!(rawdblk->CheckFTSWID(i)) && !(rawdblk->CheckTLUID(i))) {
200 tmp_header.SetBuffer(rawdblk->GetBuffer(i));
201 hdr->SetEventNumber(tmp_header.GetEveNo());
202 hdr->SetNodeID(tmp_header.GetNodeID());
203 hdr->SetExpRunWord(tmp_header.GetExpRunSubrun());
204 break;
205 }
206
207 //Error if you cannot find any COPPER block
208 if (i == (rawdblk->GetNumEntries() - 1)) {
209 printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", i, rawdblk->GetNumEntries(), rawdblk->TotalBufNwords());
210 printData(rawdblk->GetBuffer(0), rawdblk->TotalBufNwords());
211
212 const char err_buf[500] = "[FATAL] CORRUPTED DATA: No COPPER blocks in RawDataBlock. Exiting...";
213 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
214 sleep(1234567);
215 exit(-1);
216 }
217 }
218 return;
219}
220
221
222int SerializerModule::sendByWriteV(RawDataBlock* rawdblk)
223{
224 SendHeader send_header;
225 SendTrailer send_trailer;
226 fillSendHeaderTrailer(&send_header, &send_trailer, rawdblk);
227
228 enum {
229 NUM_BUFFER = 3
230 };
231 struct iovec iov[ NUM_BUFFER ];
232
233 // check Body data size
234 int rawcopper_nwords = rawdblk->TotalBufNwords();
235
236 //Fill iov info.
237 iov[0].iov_base = reinterpret_cast<char*>(send_header.GetBuffer());
238 iov[0].iov_len = sizeof(int) * send_header.GetHdrNwords();
239
240 iov[1].iov_base = reinterpret_cast<char*>(rawdblk->GetWholeBuffer());
241 iov[1].iov_len = sizeof(int) * rawcopper_nwords;
242
243 iov[2].iov_base = reinterpret_cast<char*>(send_trailer.GetBuffer());
244 iov[2].iov_len = sizeof(int) * send_trailer.GetTrlNwords();
245
246
247 // Send Multiple buffers
248 int n = 0;
249
250 while (true) {
251 if ((n = writev(m_socket, iov, NUM_BUFFER)) < 0) {
252 if (errno == EINTR) {
253 continue;
254 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
255
256#ifdef NONSTOP
257 // check run-pause request
258 string err_str;
259 callCheckRunPause(err_str);
260#endif
261 continue;
262 } else {
263 char err_buf[500];
264 sprintf(err_buf, "[WARNING] WRITEVa error.(%s) : sent %d bytes, header %lu bytes body %lu trailer %lu : %s %s %d\n",
265 strerror(errno), n, iov[0].iov_len, iov[1].iov_len, iov[2].iov_len,
266 __FILE__, __PRETTY_FUNCTION__, __LINE__);
267#ifdef NONSTOP
268 g_run_error = 1;
269 B2ERROR(err_buf);
270 string err_str = "RUN_ERROR";
271 throw (err_str); // Go to DeSerializer** and wait for run-resume.
272#else
273 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
274 exit(1);
275#endif
276 }
277 }
278 break;
279 }
280
281#ifdef DEBUG
282 printf("[DEBUG] *******BODY**********\n");
283 printf("[DEBUG] \n%.8d : ", 0);
284 printData((int*)(iov[1].iov_base), iov[1].iov_len);
285#endif
286
287
288 int total_send_bytes = sizeof(int) * send_header.GetTotalNwords();
289
290
291 //
292 // Retry sending
293 //
294 if (n != total_send_bytes) {
295 B2WARNING("Serializer: Sent byte(" << n << "bytes) is not same as the event size (" << total_send_bytes << "bytes). Retryring...");
296 double retry_start = getTimeSec();
297
298 // Send Header
299 if (n < (int)(iov[ 0 ].iov_len)) {
300 n += Send(m_socket, static_cast<char*>(iov[ 0 ].iov_base) + n, iov[ 0 ].iov_len - n);
301 }
302
303 if (n < (int)(iov[ 0 ].iov_len + iov[ 1 ].iov_len)) {
304 n += Send(m_socket, static_cast<char*>(iov[ 1 ].iov_base) + (n - iov[ 0 ].iov_len), iov[ 1 ].iov_len - (n - iov[ 0 ].iov_len));
305 }
306
307 if (n < (int)(iov[ 0 ].iov_len + iov[ 1 ].iov_len + iov[ 2 ].iov_len)) {
308 // cppcheck-suppress unreadVariable ; the tail send is best effort
309 n += Send(m_socket, static_cast<char*>(iov[ 2 ].iov_base) + (n - iov[ 0 ].iov_len - iov[ 1 ].iov_len),
310 iov[ 2 ].iov_len - (n - iov[ 0 ].iov_len - iov[ 1 ].iov_len));
311 }
312
313 double retry_end = getTimeSec();
314 B2WARNING("Resending ends. It takes " << retry_end - retry_start << "(s)");
315 }
316
317 return total_send_bytes;
318
319}
320
321
322
323int SerializerModule::Send(int socket, char* buf, int size_bytes)
324{
325 int sent_bytes = 0;
326 while (true) {
327 int ret = 0;
328 if ((ret = send(socket, buf + sent_bytes, size_bytes - sent_bytes, MSG_NOSIGNAL)) < 0) {
329 if (errno == EINTR) {
330 continue;
331 } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
332#ifdef NONSTOP
333 string err_str;
334 callCheckRunPause(err_str);
335#endif
336 continue;
337 } else {
338 char err_buf[500];
339 sprintf(err_buf, "[ERROR] Send Error. (%s) : %s %s %d", strerror(errno), __FILE__, __PRETTY_FUNCTION__, __LINE__);
340#ifdef NONSTOP
341 g_run_error = 1;
342 B2ERROR(err_buf);
343 string err_str = "RUN_ERROR";
344 throw (err_str);
345#else
346 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
347 exit(1);
348#endif
349 }
350 }
351 sent_bytes += ret;
352 if (sent_bytes == size_bytes) break;
353 }
354 return sent_bytes;
355}
356
357void SerializerModule::Accept()
358{
359
360 //
361 // Connect to cprtb01
362 //
363
364 struct hostent* host;
365 host = gethostbyname(m_hostname_local.c_str());
366 if (host == NULL) {
367 char temp_buf[500];
368 sprintf(temp_buf, "[FATAL] hostname(%s) cannot be resolved(%s). Check /etc/hosts. Exiting...\n",
369 m_hostname_local.c_str(), strerror(errno));
370 print_err.PrintError(temp_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
371 sleep(1234567);
372 exit(1);
373 }
374
375
376
377
378 //
379 // Bind and listen
380 //
381 int fd_listen;
382 struct sockaddr_in sock_listen;
383 sock_listen.sin_family = AF_INET;
384 sock_listen.sin_addr.s_addr = *reinterpret_cast<unsigned int*>(host->h_addr_list[0]);
385
386 socklen_t addrlen = sizeof(sock_listen);
387 sock_listen.sin_port = htons(m_port_to);
388 fd_listen = socket(PF_INET, SOCK_STREAM, 0);
389
390 int flags = 1;
391 int ret = setsockopt(fd_listen, SOL_SOCKET, SO_REUSEADDR, &flags, (socklen_t)sizeof(flags));
392 if (ret < 0) {
393 perror("Failed to set REUSEADDR");
394 }
395
396 if (bind(fd_listen, reinterpret_cast<struct sockaddr*>(&sock_listen), sizeof(struct sockaddr)) < 0) {
397 char temp_char[500];
398 sprintf(temp_char, "[FATAL] Failed to bind.(%s) Maybe other programs have already occupied this port(%d). Exiting...",
399 strerror(errno), m_port_to);
400 print_err.PrintError(temp_char, __FILE__, __PRETTY_FUNCTION__, __LINE__);
401 exit(1);
402 }
403
404 int val1 = 0;
405 setsockopt(fd_listen, IPPROTO_TCP, TCP_NODELAY, &val1, (socklen_t)sizeof(val1));
406 int backlog = 1;
407 if (listen(fd_listen, backlog) < 0) {
408 char err_buf[500];
409 sprintf(err_buf, "[FATAL] Failed in listen(%s). Exting...", strerror(errno));
410 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
411 exit(-1);
412 }
413
414 //
415 // Accept
416 //
417 int fd_accept;
418 struct sockaddr_in sock_accept;
419 // printf( "[DEBUG] Accepting... : port %d server %s\n", m_port_to, m_hostname_local.c_str());
420 // fflush(stderr);
421 // B2INFO("Accepting... : port " << m_port_to << " server " << m_hostname_local.c_str() );
422 B2INFO("Accepting...");
423 if ((fd_accept = accept(fd_listen, reinterpret_cast<struct sockaddr*>(& (sock_accept)), &addrlen)) == 0) {
424 char err_buf[500];
425 sprintf(err_buf, "[FATAL] Failed to accept(%s). Exiting...", strerror(errno));
426 print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
427 exit(-1);
428 } else {
429 // B2INFO("Connection is established: port " << htons(sock_accept.sin_port) << " address " << sock_accept.sin_addr.s_addr );
430 B2INFO("Done.");
431
432 // set timepout option
433 struct timeval timeout;
434 timeout.tv_sec = 1;
435 timeout.tv_usec = 0;
436 ret = setsockopt(fd_accept, SOL_SOCKET, SO_SNDTIMEO, &timeout, (socklen_t)sizeof(timeout));
437 if (ret < 0) {
438 const char temp_char[100] = "[FATAL] Failed to set TIMEOUT. Exiting...";
439 print_err.PrintError(temp_char, __FILE__, __PRETTY_FUNCTION__, __LINE__);
440 exit(-1);
441 }
442 }
443 close(fd_listen);
444
445 // int flag = 1;
446 // ret = setsockopt(fd_accept, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(flag) );
447 m_socket = fd_accept;
448 RunInfoBuffer& status(DeSerializerModule::getStatus());
449 if (status.isAvailable()) {
450 //status.setOutputPort(ntohs(sock_accept.sin_port));
451 //status.setOutputAddress(sock_accept.sin_addr.s_addr);
452 status.setOutputPort(ntohs(sock_listen.sin_port));
453 status.setOutputAddress(sock_listen.sin_addr.s_addr);
454 printf("%d %x\n", (int)ntohs(sock_listen.sin_port), (int)sock_listen.sin_addr.s_addr);
455 }
456
457 return;
458
459}
460
462{
463 struct timeval t;
464 gettimeofday(&t, NULL);
465 return (t.tv_sec + t.tv_usec * 1.e-6);
466}
467
468
469void SerializerModule::recordTime(int event, double* array)
470{
471 if (event >= 50000 && event < 50500) {
472 array[ event - 50000 ] = getTimeSec() - m_start_time;
473 }
474 return;
475}
476
477
478unsigned int SerializerModule::calcXORChecksum(const int* buf, int nwords)
479{
480 unsigned int checksum = 0;
481 for (int i = 0; i < nwords; i++) {
482 checksum = checksum ^ buf[ i ];
483 }
484 return checksum;
485}
486
487
488void SerializerModule::printData(const int* buf, int nwords)
489{
490 printf("[DEBUG]");
491 for (int i = 0; i < nwords; i++) {
492 printf("%.8x ", buf[ i ]);
493 if (i % 10 == 9) printf("\n[DEBUG]");
494 }
495 printf("\n[DEBUG]");
496 printf("\n");
497 return;
498}
499
500
501#ifdef NONSTOP
502void SerializerModule::openRunPauseNshm()
503{
504 char path_shm[100] = "/cpr_pause_resume";
505 int fd = shm_open(path_shm, O_RDONLY, 0666);
506 if (fd < 0) {
507 printf("[DEBUG] %s\n", path_shm);
508 perror("[FATAL] Failed to open shm_open");
509 exit(1);
510 }
511 m_ptr = (int*)mmap(NULL, sizeof(int), PROT_READ, MAP_SHARED, fd, 0);
512 return;
513}
514
515int SerializerModule::checkRunPause()
516{
517
518#ifdef NONSTOP_SLC
519 const RunInfoBuffer& status(DeSerializerModule::getStatus());
520 if (status.getState() == status.PAUSING) {
521#else
522 if (*m_ptr) {
523#endif
524 return 1;
525 } else {
526 return 0;
527 }
528}
529
530void SerializerModule::resumeRun()
531{
532 if (CheckConnection(m_socket) < 0) Accept();
533 g_run_resuming = 0; // run_resuming phase is over.
534 return;
535}
536
537
539{
540 // Modify Yamagata-san's eb/iseof.cc
541 int ret;
542 char buffer[1000];
543 while (true) {
544 //
545 // Extract data in the socket buffer of a peer
546 //
547 // ret = recv( socket, buffer, sizeof(buffer), MSG_PEEK|MSG_DONTWAIT );
548 ret = recv(socket, buffer, sizeof(buffer), MSG_DONTWAIT);
549 switch (ret) {
550 case 0: /* EOF */
551 printf("EOF %d\n", socket); fflush(stdout);
552 close(socket);
553 return -1;
554 case -1:
555 if (errno == EAGAIN) {
556 printf("EAGAIN %d\n", socket); fflush(stdout);
557 /* not EOF, no data in queue */
558 return 0;
559 } else {
560 printf("ERROR %d errno %d err %s\n", socket, errno, strerror(errno)); fflush(stdout);
561 close(socket);
562 return -1;
563 }
564 break;
565 default:
566 printf("Flushing data in socket buffer (%d bytes) : sockid = %d\n", ret, socket); fflush(stdout);
567 }
568 }
569}
570
571void SerializerModule::callCheckRunPause(string& err_str)
572{
573#ifdef NONSTOP_DEBUG
574 printf("\033[34m");
575 printf("###########(Ser) TIMEOUT during send() ###############\n");
576 fflush(stdout);
577 printf("\033[0m");
578#endif
579 if (checkRunPause()) {
580#ifdef NONSTOP_DEBUG
581 printf("\033[31m");
582 printf("###########(Ser) Stop is detected after return from send ###############\n");
583 fflush(stdout);
584 printf("\033[0m");
585#endif
586 err_str = "RUN_PAUSE";
587 g_run_pause = 1;
588 throw (err_str);
589 }
590 return;
591}
592
593#endif
594
595
597{
598
599#ifdef NONSTOP
600 if (g_run_pause == 1) {
601#ifdef NONSTOP_DEBUG
602 printf("\033[31m");
603 printf("###########(Ser) Go back to Deseializer() ###############\n");
604 fflush(stdout);
605 printf("\033[0m");
606#endif
607 return; // Nothing to do here
608 } else if (g_run_resuming == 1) {
609#ifdef NONSTOP_DEBUG
610 printf("\033[31m");
611 printf("###########(Ser) Run resuming...() ###############\n");
612 fflush(stdout);
613 printf("\033[0m");
614#endif
615 resumeRun();
616 return;
617 }
618#endif
619
620 if (m_start_flag == 0) {
621 m_start_time = getTimeSec();
622 n_basf2evt = 0;
623 }
624
625#ifdef TIME_MONITOR
626 recordTime(n_basf2evt, time_array0);
627#endif
628
629 // StoreArray<RawCOPPER> rawcprarray;
630 StoreArray<RawDataBlock> raw_dblkarray;
631
632
633 for (int j = 0; j < raw_dblkarray.getEntries(); j++) {
634 //
635 // Send data
636 //
637 if (m_start_flag == 0) {
638 B2INFO("SerializerPC: Sending the 1st packet...");
639 }
640
641 try {
642 m_totbytes += sendByWriteV(raw_dblkarray[ j ]);
643 // } catch (string err_str) {
644 } catch (const string& err_str) {
645
646#ifdef NONSTOP
647 if (err_str == "RUN_PAUSE" || err_str == "RUN_ERROR") {
648 return; // Go to DeSerializer***() to wait for run-resume.
649 }
650#endif
651 print_err.PrintError(const_cast<char*>((err_str.c_str())), __FILE__, __PRETTY_FUNCTION__, __LINE__);
652 exit(1);
653 }
654 if (m_start_flag == 0) {
655 B2INFO("Done. ");
656 m_start_flag = 1;
657 }
658 }
659
660
661 //
662 // Print current status
663 //
664 if (n_basf2evt % 1000 == 0) {
665 // double cur_time = getTimeSec();
666 // double total_time = cur_time - m_start_time;
667 // double interval = cur_time - m_prev_time;
668 // if (n_basf2evt != 0) {
669 // double multieve = (1. / interval);
670 // if (multieve > 2.) multieve = 2.;
671 // }
672 // time_t timer;
673 // struct tm* t_st;
674 // time(&timer);
675 // t_st = localtime(&timer);
676 // printf( "[DEBUG] Event %d TotSent %.1lf [MB] ElapsedTime %.1lf [s] RcvdRate %.2lf [MB/s] %s",
677 // n_basf2evt, m_totbytes / 1.e6, total_time, (m_totbytes - m_prev_totbytes) / interval / 1.e6, asctime(t_st));
678 // fflush(stderr);
679 // m_prev_time = cur_time;
680 // m_prev_totbytes = m_totbytes;
681 // m_prev_nevt = n_basf2evt;
682 }
683 n_basf2evt++;
684 RunInfoBuffer& status(DeSerializerModule::getStatus());
685 if (status.isAvailable()) {
686 status.setOutputNBytes(m_totbytes);
687 status.addOutputCount(raw_dblkarray.getEntries());
688 }
689
690}
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
The RawDataBlock class Base class for rawdata handling.
virtual int * GetBuffer(int n)
get nth buffer pointer
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 GetNumNodes()
get # of data sources(e.g. # of COPPER boards) in m_buffer
virtual int CheckTLUID(int n)
get FTSW ID to check whether this data block is FTSW data or not
virtual int * GetWholeBuffer()
get pointer to buffer(m_buffer)
virtual int GetNumEvents()
get # of events in m_buffer
virtual int TotalBufNwords()
Get total length of m_buffer.
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
int * GetBuffer(void)
Get Header contents.
Definition SendHeader.cc:32
void shmOpen(char *path_cfg, char *path_sta)
open shared memory
int CheckConnection(int socket)
Check socket status.
static void printData(const int *buf, int nwords)
print data contents
unsigned long long m_totbytes
sent data size
Definition Serializer.h:152
int m_port_to
Destination port.
Definition Serializer.h:118
std::string m_hostname_local
Destination Host.
Definition Serializer.h:115
SerializerModule()
Constructor / Destructor.
Definition Serializer.cc:35
void initialize() override
Module functions to be called from main process.
Definition Serializer.cc:61
static int * shmGet(int fd, int size_words)
Get shared memory.
void event() override
This method is the core of the module.
int m_start_flag
start flag
Definition Serializer.h:155
int BUF_SIZE_WORD
size of buffer for one event (word)
Definition Serializer.h:102
int m_shmfd_cfg
file descripter for shm
Definition Serializer.h:82
int * m_cfg_buf
buffer for shared memory
Definition Serializer.h:88
void endRun() override
This method is called if the current run ends.
void terminate() override
This method is called at the end of the event processing.
int n_basf2evt
No. of sent events.
Definition Serializer.h:108
CprErrorMessage print_err
error message program
Definition Serializer.h:149
int m_shmfd_sta
file descripter for shm
Definition Serializer.h:85
void beginRun() override
Module functions to be called from event process.
int m_shmflag
Use shared memory.
Definition Serializer.h:64
static unsigned int calcXORChecksum(const int *buf, int nwords)
calculate checksum
void recordTime(int event, double *array)
store time info.
int * m_cfg_sta
buffer for shared memory
Definition Serializer.h:91
int m_compressionLevel
Compression parameter.
Definition Serializer.h:105
int Send(int socket, char *buf, int size_bytes)
send buffer
static double getTimeSec()
store time info.
RawHeader_latest tmp_header
which format is used
Definition Serializer.h:176
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition StoreArray.h:216
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:650
Abstract base class for different kinds of events.
STL namespace.