Belle II Software  release-08-01-10
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, const 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  while (! infile.eof()) {
53  infile.getline(b, 800);
54  string l(b);
55 
56  //...Emptty...
57  if (l.size() == 0)
58  continue;
59 
60  //...Comment line...
61  if (l[0] == ';')
62  continue;
63 
64  //...Memory init config line...
65  if (l.find("memory") != string::npos)
66  continue;
67 
68  //...Clock counter...
69  bitset<5> cc(l.substr(0, 5));
70  cout << "--- " << cc.to_ulong();
71 
72  //...Reserved...
73  if (l.substr(5, 11) != "00000000000")
74  cout << " something wrong with reserved bits ";
75 
76  //...Clock counter in real data...
77  bitset<9> rcc(l.substr(11 + 5, 9));
78  cout << " " << rcc.to_ulong();
79 
80  //...Hit map...
81  bitset<80> hm(l.substr(5 + 16 * 11, 16 * 5));
82  if (hm.none()) {
83  cout << endl << "-" << endl;
84  } else {
85  cout << " : " << hm.count() << " hit(s)" << endl;
86  for (unsigned j = 0; j < 5; j++) {
87  unsigned left = 256 + 5 - (4 - j) * 16;
88  if (j % 2) cout << " ";
89  for (unsigned i = 0; i < 16; i++) {
90  cout << l[left - (16 - i)] << " ";
91  }
92  cout << endl;
93  }
94  }
95  }
96 
97  //...Termination...
98  cout << NAME << " ... terminated" << endl;
99 }
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91