Belle II Software  release-08-01-10
readraw.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 using namespace std;
15 
16 #define MAXBUF 4096000
17 
18 int main(int argc, char** argv)
19 {
20  if (argc < 2) {
21  perror("#argc");
22  return 1;
23  }
24 
25  int fd = open(argv[1], O_RDONLY);
26  if (fd < 0) {
27  perror("fopen");
28  exit(-1);
29  }
30  char* buf = new char[MAXBUF];
31 
32  int nrec = 0;
33  for (;;) {
34  int sizebuf;
35  int sstat = read(fd, &sizebuf, sizeof(int));
36  if (sstat <= 0) break;
37  int stat = read(fd, buf, (sizebuf - 1) * 4);
38  if (stat <= 0) break;
39  printf("record %d: size = %d\n", nrec, sizebuf);
40  nrec++;
41  }
42 
43  close(fd);
44 }
45 
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91