Belle II Software  release-06-01-15
dump_roi.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 <arpa/inet.h>
10 
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include <sys/time.h>
15 
16 enum { OFFSET_LENGTH = 0, OFFSET_HEADER = 1, OFFSET_TRIGNR = 2, OFFSET_RUNNR = 3, OFFSET_ROIS = 4};
17 enum {
18  EXP_MASK = 0xFFC00000,
19  EXP_SHIFT = 22,
20  RUNNO_MASK = 0x003FFF00,
21  RUNNO_SHIFT = 8,
22  SUBRUNNO_MASK = 0x000000FF
23 };
24 
25 
26 using namespace std;
27 
28 char* timestamp()
29 {
30  struct timeval tb;
31  struct tm* tp;
32  static char buf[256];
33  // struct tm result;
34  gettimeofday(&tb, NULL);
35  tp = localtime(&tb.tv_sec);
36  sprintf(buf, "%02d:%02d:%02d.%03d ",
37  tp->tm_hour, tp->tm_min, tp->tm_sec, (int)(tb.tv_usec / 1000));
38  // printf ( " buf = %s\n", buf );
39  return buf;
40 }
41 
42 
43 
44 int main(int argc, char** argv)
45 {
46  unsigned int buf[400000];
47  int infn = fileno(stdin);
48  printf("infn = %d\n", infn);
49 
50  int nrec = 0;
51  for (;;) {
52  int is = read(infn, &buf[0], 4);
53  int nw = ntohl(buf[0]);
54  if (is <= 0) break;
55  is = read(infn, &buf[1], (nw - 1) * 4);
56  // printf ( "nw = %d\n", nw );
57  // if ( abs(nw)> 1000 ) continue;
58  // for ( int j=0;j<8; j++ ) {
59  // printf ( "%8.8x ", buf[j] );
60  // }
61  // printf ( "\n" );
62  // printf ( "nw = %d, 1st = %d, 2nd = %d, 3rd = %d\n",
63  // ntohl(buf[5]), ntohl(buf[6]), ntohl(buf[7]), ntohl(buf[8]) );
64  int exp = (ntohl(buf[ OFFSET_RUNNR ]) & EXP_MASK) >> EXP_SHIFT;
65  int run = (ntohl(buf[ OFFSET_RUNNR ]) & RUNNO_MASK) >> RUNNO_SHIFT;
66  int evt = ntohl(buf[ OFFSET_TRIGNR ]);
67  // int rois = ntohl(buf[ OFFSET_ROIS] );
68 
69  printf("%s Nrec: %d ; Nw: %d ; Exp: %d, Run: %d, Evt: %d\n",
70  timestamp(), nrec, nw, exp, run, evt);
71  nrec++;
72 
73  }
74 
75 }
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75