Belle II Software  release-06-02-00
MergerViewer.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 //-----------------------------------------------------------------------------
10 // Description : A program to view Merger COE data files
11 //-----------------------------------------------------------------------------
12 
13 #define TRG_SHORT_NAMES
14 
15 #include <iostream>
16 #include <fstream>
17 #include <string>
18 #include <bitset>
19 #include "trg/trg/Utilities.h"
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 #define DEBUG_LEVEL 0
25 #define NAME "MergerViewer"
26 #define VERSION "version 0.00"
27 
28 int
29 main(int argc, char* argv[])
30 {
31 
32  cout << NAME << " ... " << VERSION << endl;
33  const string tab = " ";
34 
35  //...Check arguments...
36  if (argc != 2) {
37  cout << NAME << " !!! arguments not good" << endl;
38  cout << tab << " 1 : Merger COE data file" << endl;
39  return -1;
40  }
41 
42  //...Open COE data file...
43  string inname = argv[1];
44  ifstream infile(inname.c_str(), ios::in);
45  if (infile.fail()) {
46  cout << NAME << " !!! can not open file" << endl
47  << " " << inname << endl;
48  return -2;
49  }
50 
51  char b[800];
52  unsigned line = 0;
53  while (! infile.eof()) {
54  infile.getline(b, 800);
55  string l(b);
56 
57  //...Emptty...
58  if (l.size() == 0)
59  continue;
60 
61  //...Comment line...
62  if (l[0] == ';')
63  continue;
64 
65  //...Memory init config line...
66  if (l.find("memory") != string::npos)
67  continue;
68 
69  //...Clock counter...
70  bitset<5> cc(l.substr(0, 5));
71  cout << "--- " << cc.to_ulong();
72 
73  //...Reserved...
74  if (l.substr(5, 11) != "00000000000")
75  cout << " something wrong with reserved bits ";
76 
77  //...Clock counter in real data...
78  bitset<9> rcc(l.substr(11 + 5, 9));
79  cout << " " << rcc.to_ulong();
80 
81  //...Hit map...
82  bitset<80> hm(l.substr(5 + 16 * 11, 16 * 5));
83  if (hm.none()) {
84  cout << endl << "-" << endl;
85  } else {
86  cout << " : " << hm.count() << " hit(s)" << endl;
87  for (unsigned j = 0; j < 5; j++) {
88  unsigned left = 256 + 5 - (4 - j) * 16;
89  if (j % 2) cout << " ";
90  for (unsigned i = 0; i < 16; i++) {
91  cout << l[left - (16 - i)] << " ";
92  }
93  cout << endl;
94  }
95  }
96 
97  ++line;
98  }
99 
100  //...Termination...
101  cout << NAME << " ... terminated" << endl;
102 }
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:75