Belle II Software  release-05-01-25
file2rb.cc
1 //+
2 // File : file2rb.cc
3 // Description : Get an event from a SeqRoot file and place it in Rbuf
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/SeqFile.h"
15 #include "framework/pcore/RingBuffer.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 filename neof\n");
27  exit(-1);
28  }
29 
30  SeqFile* file = new SeqFile(argv[2], "r");
31  if (file->status() <= 0) {
32  perror("file open");
33  exit(-1);
34  }
35 
36  // RingBuffer* rbuf = new RingBuffer(argv[1], RBUFSIZE);
37  RingBuffer* rbuf = new RingBuffer(argv[1]);
38  rbuf->dump_db();
39  char* evbuf = new char[MAXEVTSIZE];
40 
41  // Skip the first record (StreamerInfo)
42  int is = file->read(evbuf, MAXEVTSIZE);
43  if (is <= 0) exit(-1);
44 
45  for (;;) {
46  int is = file->read(evbuf, MAXEVTSIZE);
47  if (is <= 0) break;
48  if (is > MAXEVTSIZE) {
49  printf("Event size too large : %d\n", is);
50  continue;
51  }
52 
53  // Put the message in ring buffer
54  int irb = 0;
55  for (;;) {
56  irb = rbuf->insq((int*)evbuf, (is - 1) / 4 + 1);
57  if (irb >= 0) break;
58  // usleep(100);
59  usleep(20);
60  }
61  }
62 }
63 
64 
65 
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::dump_db
void dump_db()
Print some info on the RingBufInfo structure.
Definition: RingBuffer.cc:185
Belle2::RingBuffer::insq
int insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:192
Belle2::SeqFile
A class to manage I/O for a chain of blocked files.
Definition: SeqFile.h:22