Belle II Software development
rawfile2rb.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 <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <fcntl.h>
13
14#include "framework/pcore/RingBuffer.h"
15
16using namespace Belle2;
17using namespace std;
18
19#define MAXBUF 400000000
20
21int main(int argc, char** argv)
22{
23 if (argc < 3) {
24 printf("rawfile2rb : rbufname filename neof\n");
25 exit(-1);
26 }
27
28 int fd = open(argv[2], O_RDONLY);
29 if (fd < 0) {
30 perror("fopen");
31 exit(-1);
32 }
33 int neof = atoi(argv[3]);
34
35 RingBuffer* rbuf = new RingBuffer(argv[1]);
36 rbuf->dump_db();
37
38 char* buf = new char[MAXBUF];
39
40 int nrec = 0;
41
42retry:
43 for (;;) {
44 int sstat = read(fd, buf, sizeof(int));
45 if (sstat <= 0) break;
46 int* recsize = (int*)buf;
47 int rstat = read(fd, buf + sizeof(int), (*recsize - 1) * 4);
48 if (rstat <= 0) break;
49 if (nrec % 1000 == 0) {
50 printf("record %d: size = %d\n", nrec, *recsize);
51 }
52
53 // Put the message in ring buffer
54 for (;;) {
55 int irb = rbuf->insq((int*)buf, *recsize);
56 if (irb >= 0) break;
57 // usleep(100);
58 usleep(20);
59 }
60 nrec++;
61 }
62 if (neof < 0) {
63 lseek(fd, 0, SEEK_SET);
64 goto retry;
65 }
66 close(fd);
67}
68
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
Abstract base class for different kinds of events.
STL namespace.