Belle II Software  release-06-00-14
rb2file.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 #include "framework/pcore/EvtMessage.h"
17 
18 #define RBUFSIZE 100000000
19 #define MAXEVTSIZE 400000000
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 neof\n");
28  exit(-1);
29  }
30 
31  SeqFile* file = new SeqFile(argv[2], "w");
32  if (file->status() <= 0) {
33  perror("file open");
34  exit(-1);
35  }
36  // RingBuffer* rbuf = new RingBuffer(argv[1], RBUFSIZE);
37  RingBuffer* rbuf = new RingBuffer(argv[1]);
38  char* evbuf = new char[MAXEVTSIZE];
39 
40  int eof = 0;
41  for (;;) {
42  // Get a record from ringbuf
43  int size;
44  while ((size = rbuf->remq((int*)evbuf)) == 0) {
45  // printf ( "Rx : evtbuf is not available yet....\n" );
46  // usleep(100);
47  usleep(20);
48  }
49  EvtMessage* msg = new EvtMessage(evbuf);
50  if (msg->type() == MSG_TERMINATE) {
51  printf("EoF found. Exitting.....\n");
52  eof = 1;
53  }
54 
55  // Put the record in a file
56  int wstat = file->write(evbuf);
57  if (wstat <= 0) {
58  perror("write");
59  exit(-99);
60  }
61  delete msg;
62  }
63 }
64 
65 
66 
67 
Class to manage streamed object.
Definition: EvtMessage.h:59
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:308
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