Belle II Software  release-06-02-00
mfile2rb.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 <unistd.h>
12 
13 #include "framework/pcore/SeqFile.h"
14 #include "framework/pcore/RingBuffer.h"
15 
16 #define RBUFSIZE 100000000
17 #define MAXEVTSIZE 400000000
18 #define MAXEVT 100000
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 nevt\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  int nevt = atoi(argv[3]);
37 
38  // RingBuffer* rbuf = new RingBuffer(argv[1], RBUFSIZE);
39  RingBuffer* rbuf = new RingBuffer(argv[1]);
40  rbuf->dump_db();
41 
42  // Skip the first record (StreamerInfo)
43  char* dumbuf = new char[MAXEVTSIZE];
44  int is = file->read(dumbuf, MAXEVTSIZE);
45  if (is <= 0) exit(-1);
46  delete dumbuf;
47 
48  char* evbuf[MAXEVT];
49  // Create event buffers
50  for (int i = 0; i < nevt; i++) {
51  evbuf[i] = new char[MAXEVTSIZE];
52  while (true) {
53  int is = file->read(evbuf[i], MAXEVTSIZE);
54  if (is <= 0) {
55  perror("read file");
56  exit(-1);
57  }
58  printf("eventsize = %d\n", is);
59  if (is > MAXEVTSIZE) {
60  printf("Event size too large : %d\n", is);
61  exit(-1);
62  }
63  if (is > 190000) break;
64  }
65  }
66 
67  int totevt = 0;
68  for (;;) {
69  int bufno = std::rand() % nevt;
70 
71  // Put the message in ring buffer
72  int irb = 0;
73  for (;;) {
74  irb = rbuf->insq((int*)evbuf[bufno], (is - 1) / 4 + 1);
75  if (irb >= 0) break;
76  // usleep(100);
77  usleep(20);
78  }
79  totevt++;
80  if (totevt % 1000 == 0)
81  printf("mfile2rb : event = %d (bufno = %d)\n", totevt, bufno);
82  }
83 }
84 
85 
86 
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:180
int insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:187
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:75