Belle II Software development
readrb.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 <string>
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <unistd.h>
13
14#include "framework/pcore/RingBuffer.h"
15#include "framework/pcore/EvtMessage.h"
16
17#define RBUFSIZE 100000000
18#define MAXEVTSIZE 400000000
19
20using namespace Belle2;
21using namespace std;
22
23int main(int argc, char** argv)
24{
25 if (argc < 3) {
26 printf("file2rb : rbufname sleeptime(us)\n");
27 exit(-1);
28 }
29
30 RingBuffer* rbuf = new RingBuffer(argv[1]);
31 char* evbuf = new char[MAXEVTSIZE];
32
33 int sltime = atoi(argv[2]);
34
35 int nevt = 0;
36 for (;;) {
37 // Get a record from ringbuf
38 int size;
39 while ((size = rbuf->remq((int*)evbuf)) == 0) {
40 // printf ( "Rx : evtbuf is not available yet....\n" );
41 // usleep(100);
42 usleep(20);
43 }
44 if (size < 0) exit(-1);
45 EvtMessage* msg = new EvtMessage(evbuf);
46 if (msg->type() == MSG_TERMINATE) {
47 printf("EoF found. Exitting.....\n");
48 }
49 nevt++;
50 if (nevt % 1000 == 0) printf("readrb : event = %d (size=%d)\n", nevt, *((int*)evbuf));
51 usleep(sltime);
52 }
53}
54
55
56
57
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.