Belle II Software development
rb2mrb.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
9#include <vector>
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14
15#include "framework/pcore/RingBuffer.h"
16#include "framework/pcore/EvtMessage.h"
17
18#define RBUFSIZE 10000000
19#define MAXEVTSIZE 400000000
20
21using namespace Belle2;
22using namespace std;
23
24int main(int argc, char** argv)
25{
26 if (argc < 3) {
27 printf("file2rb : inrbufname outrbufname1 outbufname2 .....\n");
28 exit(-1);
29 }
30
31 printf("rb2mrb : allocating %s with size=%d (KBytes)\n", argv[1], RBUFSIZE * 4 / 1000);
32 RingBuffer* rbufin = new RingBuffer(argv[1], RBUFSIZE);
33 // RingBuffer* rbufin = new RingBuffer(argv[1]);
34 // RingBuffer* rbufout = new RingBuffer(argv[2], RBUFSIZE);
35
36 int nout = argc - 2;
37
38 vector<RingBuffer*> rbufout;
39 for (int i = 0; i < nout; i++) {
40 // rbufout.push_back(new RingBuffer(argv[i + 2]));
41 printf("rb2mrb : allocating %s with size=%d (KBytes)\n", argv[i + 2], RBUFSIZE * 4 / 1000);
42 rbufout.push_back(new RingBuffer(argv[i + 2], RBUFSIZE));
43 }
44
45 char* evbuf = new char[MAXEVTSIZE];
46
47 int outptr = 0;
48 int bsize;
49 for (;;) {
50 // Get a record from ringbuf
51 while ((bsize = rbufin->remq((int*)evbuf)) == 0) {
52 // printf ( "Rx : evtbuf is not available yet....\n" );
53 // usleep(100);
54 usleep(20);
55 }
56 EvtMessage* msg = new EvtMessage(evbuf);
57 if (msg->type() == MSG_TERMINATE) {
58 printf("EoF found. Exitting.....\n");
59 break;
60 }
61
62 // Put the message in ring buffer
63 for (;;) {
64 int irb = rbufout[outptr]->insq((int*)evbuf, bsize);
65 if (irb >= 0) break;
66 // usleep(100);
67 usleep(20);
68 }
69 outptr++;
70 if (outptr >= nout) outptr = 0;
71 delete msg;
72 }
73
74 // EOF
75 for (int i = 0; i < nout; i++) {
76 for (;;) {
77 int irb = rbufout[i]->insq((int*)evbuf, bsize);
78 if (irb >= 0) break;
79 // usleep(100);
80 usleep(20);
81 }
82 }
83 exit(0);
84}
85
86
87
88
Class to manage streamed object.
Definition: EvtMessage.h:59
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:308
Abstract base class for different kinds of events.
STL namespace.