Belle II Software  release-08-01-10
rb2rb.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 <string>
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 100000000
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 : inrbufname outrbufname\n");
28  exit(-1);
29  }
30 
31  // RingBuffer* rbufin = new RingBuffer(argv[1], RBUFSIZE);
32  RingBuffer* rbufin = new RingBuffer(argv[1]);
33  // RingBuffer* rbufout = new RingBuffer(argv[2], RBUFSIZE);
34  RingBuffer* rbufout = new RingBuffer(argv[2]);
35  char* evbuf = new char[MAXEVTSIZE];
36 
37  int eof = 0;
38  while (eof == 0) {
39  // Get a record from ringbuf
40  int bsize;
41  while ((bsize = rbufin->remq((int*)evbuf)) == 0) {
42  // printf ( "Rx : evtbuf is not available yet....\n" );
43  // usleep(100);
44  usleep(20);
45  }
46  EvtMessage* msg = new EvtMessage(evbuf);
47  if (msg->type() == MSG_TERMINATE) {
48  printf("EoF found. Exitting.....\n");
49  eof = 1;
50  }
51 
52  // Put the message in ring buffer
53  for (;;) {
54  int irb = rbufout->insq((int*)evbuf, bsize);
55  if (irb >= 0) break;
56  // usleep(100);
57  usleep(20);
58  }
59  }
60 }
61 
62 
63 
64 
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
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:308
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91