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