Belle II Software  release-08-01-10
mrb2rb.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 
21 using namespace Belle2;
22 using namespace std;
23 
24 int main(int argc, char** argv)
25 {
26  if (argc < 3) {
27  printf("file2rb : inrbufname1 inrbufname2 .... outrbufname\n");
28  exit(-1);
29  }
30 
31  int nin = argc - 2;
32 
33  vector<RingBuffer*> rbufin;
34  for (int i = 0; i < nin; i++) {
35  // rbufin.push_back(new RingBuffer(argv[i + 1]));
36  printf("mrb2rb : allocating %s with size=%d (KBytes)\n", argv[i + 1], RBUFSIZE * 4 / 1000);
37  rbufin.push_back(new RingBuffer(argv[i + 1], RBUFSIZE));
38  }
39  RingBuffer* rbufout = new RingBuffer(argv[argc - 1]);
40  // printf ( "mrb2rb : allocating %s with size=%d (KBytes)\n", argv[argc-1], RBUFSIZE*4/1000 );
41  // RingBuffer* rbufout = new RingBuffer(argv[argc - 1], RBUFSIZE);
42  char* evbuf = new char[MAXEVTSIZE];
43 
44  int inptr = 0;
45  for (;;) {
46  // Get a record from ringbuf
47  int bsize;
48  while ((bsize = rbufin[inptr]->remq((int*)evbuf)) == 0) {
49  // printf ( "Rx : evtbuf is not available yet....\n" );
50  // usleep(100);
51  usleep(20);
52  }
53  EvtMessage* msg = new EvtMessage(evbuf);
54  if (msg->type() == MSG_TERMINATE) {
55  printf("EoF found. Exitting.....\n");
56  break;
57  }
58  // Put the message in ring buffer
59  for (;;) {
60  int irb = rbufout->insq((int*)evbuf, bsize);
61  if (irb >= 0) break;
62  // usleep(100);
63  usleep(20);
64  }
65  inptr++;
66  if (inptr >= nin) inptr = 0;
67  delete msg;
68  }
69 }
70 
71 
72 
73 
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 insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:189
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91