Belle II Software  release-05-01-25
readrb.cc
1 //+
2 // File : readrb.cc
3 // Description : Continuously read a RingBuffer
4 //
5 // Author : Ryosuke Itoh, IPNS, KEK
6 // Date : 28 - Apr - 2012
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 
20 using namespace Belle2;
21 using namespace std;
22 
23 int 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 
Belle2::EvtMessage::type
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:115
Belle2::EvtMessage
Class to manage streamed object.
Definition: EvtMessage.h:60
Belle2::RingBuffer
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:36
main
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:77
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RingBuffer::remq
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:311