Belle II Software  release-08-01-10
file2rb.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/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 isN = file->read(evbuf, MAXEVTSIZE);
47  if (isN <= 0) break;
48  if (isN > MAXEVTSIZE) {
49  printf("Event size too large : %d\n", isN);
50  continue;
51  }
52 
53  // Put the message in ring buffer
54  for (;;) {
55  int irb = rbuf->insq((int*)evbuf, (isN - 1) / 4 + 1);
56  if (irb >= 0) break;
57  // usleep(100);
58  usleep(20);
59  }
60  }
61 }
62 
63 
64 
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
void dump_db()
Print some info on the RingBufInfo structure.
Definition: RingBuffer.cc:182
int insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:189
A class to manage I/O for a chain of blocked files.
Definition: SeqFile.h:22
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91