Belle II Software  release-08-01-10
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 #include <vector>
10 
11 #include <stdio.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 #define MAXEVT 100000
20 
21 using namespace Belle2;
22 using namespace std;
23 
24 int main(int argc, char** argv)
25 {
26  if (argc < 3) {
27  printf("file2rb : rbufname filename nevt\n");
28  exit(-1);
29  }
30 
31  SeqFile* file = new SeqFile(argv[2], "r");
32  if (file->status() <= 0) {
33  perror("file open");
34  exit(-1);
35  }
36 
37  int nevt = atoi(argv[3]);
38 
39  // RingBuffer* rbuf = new RingBuffer(argv[1], RBUFSIZE);
40  RingBuffer* rbuf = new RingBuffer(argv[1]);
41  rbuf->dump_db();
42 
43  // Skip the first record (StreamerInfo)
44  char* dumbuf = new char[MAXEVTSIZE];
45  int is = file->read(dumbuf, MAXEVTSIZE);
46  if (is <= 0) exit(-1);
47  delete[] dumbuf;
48 
49  vector<char*> evbuf(MAXEVT);
50  // Create event buffers
51  for (int i = 0; i < nevt; i++) {
52  evbuf[i] = new char[MAXEVTSIZE];
53  while (true) {
54  int isN = file->read(evbuf[i], MAXEVTSIZE);
55  if (isN <= 0) {
56  perror("read file");
57  exit(-1);
58  }
59  printf("eventsize = %d\n", isN);
60  if (isN > MAXEVTSIZE) {
61  printf("Event size too large : %d\n", isN);
62  exit(-1);
63  }
64  if (isN > 190000) break;
65  }
66  }
67 
68  int totevt = 0;
69  for (;;) {
70  int bufno = std::rand() % nevt;
71 
72  // Put the message in ring buffer
73  for (;;) {
74  int 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: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