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