Belle II Software development
DesSer.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/DesSer.h>
9
10#include <netdb.h>
11#include <netinet/tcp.h>
12
13#include <sys/mman.h>
14#include <sys/socket.h>
15#include <sys/uio.h>
16#include <unistd.h>
17
18#include <csignal>
19
20#include <csignal>
21
22//#define DEBUG
23using namespace std;
24using namespace Belle2;
25
26//----------------------------------------------------------------
27// Implementation
28//----------------------------------------------------------------
29
31{
32
34
35 m_exprunsubrun_no = 0; // will obtain info from data
36
37 m_prev_exprunsubrun_no = 0xFFFFFFFF;
38
39#ifdef NONSTOP
40 m_run_pause = 0;
41
42 m_run_error = 0;
43#endif
44
45 // B2INFO("DeSerializerPrePC: Constructor done.");
46 printf("[DEBUG] DesSer: Constructor done.\n"); fflush(stdout);
47}
48
49
50
51DesSer::~DesSer()
52{
53
54}
55
56
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}
75
76
77int* DesSer::getNewBuffer(int nwords, int* delete_flag)
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}
100
101void DesSer::initialize(bool close_listen)
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}
164
165
167// From Serializer.cc
169
170//void DesSer::fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlock* rawdblk)
171void DesSer::fillSendHeaderTrailer(SendHeader* hdr, SendTrailer* trl, RawDataBlockFormat* rawdblk)
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}
224
225
226//int DesSer::sendByWriteV(RawDataBlock* rawdblk)
227int DesSer::sendByWriteV(RawDataBlockFormat* rawdblk)
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}
327
328
329int DesSer::Send(int socket, char* buf, int size_bytes)
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}
364
365void DesSer::Accept(bool close_listen)
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}
479
481{
482 struct timeval t;
483 gettimeofday(&t, NULL);
484 return (t.tv_sec + t.tv_usec * 1.e-6);
485}
486
487
488void DesSer::recordTime(int event, double* array)
489{
490 if (event >= 50000 && event < 50500) {
491 array[ event - 50000 ] = getTimeSec() - m_start_time;
492 }
493 return;
494}
495
496
497unsigned int DesSer::calcXORChecksum(const int* buf, int nwords)
498{
499 unsigned int checksum = 0;
500 for (int i = 0; i < nwords; i++) {
501 checksum = checksum ^ buf[ i ];
502 }
503 return checksum;
504}
505
506
507void DesSer::printData(const int* buf, int nwords)
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}
518
519
520#ifdef NONSTOP
521void DesSer::openRunPauseNshm()
522{
523 char path_shm[100] = "/cpr_pause_resume";
524 int fd = shm_open(path_shm, O_RDONLY, 0666);
525 if (fd < 0) {
526 printf("[DEBUG] %s\n", path_shm);
527 perror("[ERROR] shm_open2");
528 exit(1);
529 }
530 m_ptr = (int*)mmap(NULL, sizeof(int), PROT_READ, MAP_SHARED, fd, 0);
531 return;
532}
533
534int DesSer::checkRunPause()
535{
536#ifdef NONSTOP_SLC
537 if (m_status.getState() == m_status.PAUSING) {
538#else
539 if (*m_ptr) {
540#endif
541 return 1;
542 } else {
543 return 0;
544 }
545}
546
547int DesSer::checkRunRecovery()
548{
549#ifdef NONSTOP_SLC
550 if (m_status.getState() == m_status.RESUMING) {
551#else
552 if (*m_ptr) {
553#endif
554 return 0;
555 } else {
556 return 1;
557 }
558}
559
560void DesSer::resumeRun()
561{
562#ifdef NONSTOP_DEBUG
563 printf("\033[34m");
564 printf("###########(Ser) the 1st event sicne the resume ###############\n");
565 fflush(stdout);
566 printf("\033[0m");
567#endif
568 m_run_error = 0;
569 m_run_pause = 0;
570 return;
571}
572
573
574void DesSer::pauseRun()
575{
576 m_run_pause = 1;
577#ifdef NONSTOP_DEBUG
578 printf("###########(Ser) Pause the run ###############\n");
579 fflush(stdout);
580#endif
581 return;
582}
583
584
585
586
587void DesSer::callCheckRunPause(const string& err_str)
588{
589#ifdef NONSTOP_DEBUG
590 printf("\033[34m");
591 printf("###########(DesSer) TIMEOUT. ###############\n");
592 fflush(stdout);
593 printf("\033[0m");
594#endif
595 if (checkRunPause()) {
596#ifdef NONSTOP_DEBUG
597 printf("\033[31m");
598 printf("###########(DesSer) Pause is detected. ###############\n");
599 fflush(stdout);
600 printf("\033[0m");
601#endif
602 m_run_pause = 1;
603 throw (err_str);
604 }
605 return;
606}
607
608
609int DesSer::CheckConnection(int socket)
610{
611 // Modify Yamagata-san's eb/iseof.cc
612
613
614 int ret;
615 char buffer[100000];
616 int eagain_cnt = 0;
617 int tot_ret = 0;
618 printf("CC1\n"); fflush(stdout);
619 ret = send(socket, buffer, 0, MSG_DONTWAIT);
620 printf("CC2\n"); fflush(stdout);
621 switch (ret) {
622 case 0:
623 break;
624 case -1:
625 if (errno == EAGAIN) {
626 printf("EAGAIN %d cnt %d recvd %d\n", socket, eagain_cnt, tot_ret); fflush(stdout);
627 /* not EOF, no data in queue */
628 if (eagain_cnt > 100) {
629 return 0;
630 }
631 usleep(10000);
632 eagain_cnt++;
633 } else {
634 printf("ERROR %d errno %d err %s\n", socket, errno, strerror(errno)); fflush(stdout);
635 close(socket);
636 return -1;
637 }
638 default:
639 printf("Return value %d of send is strange. Exting...\n", ret);
640 fflush(stdout);
641 exit(1);
642 }
643
644 while (true) {
645
646 //
647 // Extract data in the socket buffer of a peer
648 //
649 // ret = recv( socket, buffer, sizeof(buffer), MSG_PEEK|MSG_DONTWAIT );
650 ret = recv(socket, buffer, sizeof(buffer), MSG_DONTWAIT);
651 switch (ret) {
652 case 0: /* EOF */
653 printf("EOF %d\n", socket); fflush(stdout);
654 close(socket);
655 return -1;
656 case -1:
657 if (errno == EAGAIN) {
658 printf("EAGAIN %d cnt %d recvd %d\n", socket, eagain_cnt, tot_ret); fflush(stdout);
659 /* not EOF, no data in queue */
660 if (eagain_cnt > 100) {
661 return 0;
662 }
663 usleep(10000);
664 eagain_cnt++;
665 } else {
666 printf("ERROR %d errno %d err %s\n", socket, errno, strerror(errno)); fflush(stdout);
667 close(socket);
668 return -1;
669 }
670 break;
671 default:
672 tot_ret += ret;
673 printf("Flushing data in socket buffer : sockid = %d %d bytes tot %d bytes\n", socket, ret, tot_ret); fflush(stdout);
674 }
675 }
676}
677
678
679#endif
680
681void DesSer::shmOpen(char*, char*)
682//(char* path_cfg, char* path_sta)
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}
718
719
720
static void shmOpen(char *path_cfg, char *path_sta)
open shared memory
Definition DesSer.cc:681
static void printData(const int *buf, int nwords)
dump error data
Definition DesSer.cc:507
int m_port_to
Destination port.
Definition DesSer.h:278
RunInfoBuffer m_status
Run info buffer.
Definition DesSer.h:141
std::string m_hostname_local
Destination Host.
Definition DesSer.h:275
unsigned int m_prev_exprunsubrun_no
run no.
Definition DesSer.h:147
std::string m_nodename
Node Name for SLC.
Definition DesSer.h:135
int * getPreAllocBuf()
Getbuffer.
Definition DesSer.cc:57
int m_start_flag
start flag
Definition DesSer.h:181
RawHeader_v2 tmp_header
which format is used
Definition DesSer.h:323
int * m_buffer
buffer
Definition DesSer.h:82
DesSer()
Constructor / Destructor.
Definition DesSer.cc:30
int n_basf2evt
No. of sent events.
Definition DesSer.h:70
int m_socket_send
Reciever Socket.
Definition DesSer.h:267
CprErrorMessage print_err
wrapper for B2LOG system
Definition DesSer.h:184
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
int * getNewBuffer(int nwords, int *delete_flag)
Getbuffer.
Definition DesSer.cc:77
int m_shmflag
Use shared memory.
Definition DesSer.h:159
static unsigned int calcXORChecksum(const int *buf, int nwords)
calculate checksum
Definition DesSer.cc:497
void recordTime(int event, double *array)
store time info.
Definition DesSer.cc:488
int m_num_usedbuf
Definition DesSer.h:132
int m_num_connections
check data contents
Definition DesSer.h:237
int m_compressionLevel
Compression Level.
Definition DesSer.h:67
int * m_bufary[NUM_PREALLOC_BUF]
buffer
Definition DesSer.h:85
unsigned int m_exprunsubrun_no
run no.
Definition DesSer.h:144
int m_nodeid
Node ID for SLC.
Definition DesSer.h:138
int Send(int socket, char *buf, int size_bytes)
send buffer
Definition DesSer.cc:329
static double getTimeSec()
store time info.
Definition DesSer.cc:480
The RawDataBlockFormat class Format information for rawdata handling.
virtual int CheckFTSWID(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 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
int * GetBuffer(void)
Get Header contents.
Definition SendHeader.cc:32
Abstract base class for different kinds of events.
STL namespace.