Belle II Software development
dump_sendheader.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 <unistd.h>
11#include <stdlib.h>
12#include <time.h>
13#include <sys/time.h>
14#include <vector>
15
16enum {
17 POS_NWORDS = 0,
18 POS_HDR_NWORDS = 1,
19 POS_NUM_EVE_NUM_NODES = 2,
20 POS_EXP_RUN_NUM = 3,
21 POS_EVE_NUM = 4,
22 POS_NODE_ID = 5
23};
24
25
26using namespace std;
27
28char* 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
44int main()
45{
46 vector<unsigned int> buf(4000000);
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 int nw = buf[0];
55 if (is <= 0) break;
56 printf("nw = %d (%8.8x)\n", nw, nw);
57 is = read(infn, &buf[1], (nw - 1) * 4);
58 if (is <= 0) {
59 perror("Error to read input");
60 exit(-1);
61 }
62 printf("buf[0] =%8.8x, buf[1] = %8.8x, buf[nw-1] = %8.8x\n",
63 buf[0], buf[1], buf[nw - 1]);
64 // if ( abs(nw)> 1000 ) continue;
65 // for ( int j=0;j<8; j++ ) {
66 // printf ( "%8.8x ", buf[j] );
67 // }
68 // printf ( "\n" );
69 // printf ( "nw = %d, 1st = %d, 2nd = %d, 3rd = %d\n",
70 // ntohl(buf[5]), ntohl(buf[6]), ntohl(buf[7]), ntohl(buf[8]) );
71 // int exp = (ntohl(buf[ OFFSET_RUNNR ]) & EXP_MASK) >> EXP_SHIFT;
72 // int run = (ntohl(buf[ OFFSET_RUNNR ]) & RUNNO_MASK) >> RUNNO_SHIFT;
73 // int evt = ntohl(buf[ OFFSET_TRIGNR ]);
74 // int rois = ntohl(buf[ OFFSET_ROIS] );
75
76 // printf("%s Nrec: %d ; Nw: %d ; Exp: %d, Run: %d, Evt: %d\n",
77 // timestamp(), nrec, nw, exp, run, evt );
78 nrec++;
79
80 }
81
82}
STL namespace.