Belle II Software  release-08-01-10
TRGCDCTRGPackerTB.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 test TRGPacker on CDCFE
11 //-----------------------------------------------------------------------------
12 
13 #define TRG_SHORT_NAMES
14 
15 #include <cstdlib>
16 #include <iostream>
17 #include <fstream>
18 #include <string>
19 #include <map>
20 #include <string.h>
21 #include "trg/trg/Utilities.h"
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 #define DEBUG_LEVEL 1
27 #define NAME "TRGCDCTRGPackerTB"
28 #define VERSION "version 0.00"
29 #define ENV_PATH "BELLE2_LOCAL_DIR"
30 #define N_FRONT 500
31 #define NOT_CONNECTED 99999
32 
33 int
34 main(int argc, char* argv[])
35 {
36 
37  cout << NAME << " ... " << VERSION << endl;
38  const string tab = " ";
39 
40  //...Check arguments...
41  if (argc < 2) {
42  cout << NAME << " !!! two arguments necessary" << endl
43  << tab << " 1 : input data file" << endl;
44  return -1;
45  }
46 
47  //...Date...
48  // string ts0 = TRGUtil::dateStringF();
49  // string ts1 = TRGUtil::dateString();
50 
51  //...Get a path to data...
52 // const string path = getenv(ENV_PATH);
53 // const string inname = path + "/data/trg/" + argv[1];
54 // const string outname = path + "/data/trg/" + argv[1] + ".out";
55  const string inname = argv[1];
56  const string outname = string(argv[1]) + ".out";
57  cout << tab << "input data : " << inname << endl;
58  cout << tab << "output data : " << outname << endl;
59 
60  //...Open configuration data...
61  ifstream infile(inname.c_str(), ios::in);
62  if (infile.fail()) {
63  cout << NAME << " !!! can not open file" << endl
64  << " " << inname << endl;
65  return -2;
66  }
67 
68  //...Read data
69  char b[800];
70  unsigned lines = 0;
71  multimap<unsigned, unsigned> signals;
72  while (! infile.eof()) {
73  infile.getline(b, 800);
74  string l(b);
75 
76  if (l.size() == 0)
77  continue;
78 
79  bool skip = false;
80  unsigned id = 999;
81  unsigned pos = 999;
82  for (unsigned i = 0; i < 2; i++) {
83  string car = TRGUtil::carstring(l);
84  l = TRGUtil::cdrstring(l);
85 
86  if (car[0] == '#') {
87  skip = true;
88  break;
89  }
90 
91  if (i == 0) {
92  id = atoi(car.c_str());
93  } else if (i == 1) {
94  pos = atoi(car.c_str());
95  }
96  }
97 
98  if (skip)
99  continue;
100 
101  //...Store signal...
102  signals.insert(pair<unsigned, unsigned>(id, pos));
103 
104  if (DEBUG_LEVEL)
105  cout << lines
106  << " : " << id
107  << " " << pos << endl;
108 
109  ++lines;
110  }
111  infile.close();
112 
113  //...Make signal bit map...
114  unsigned bm[48];
115  memset(bm, 0, sizeof(unsigned) * 48);
116  for (map<unsigned, unsigned>::iterator i = signals.begin();
117  i != signals.end();
118  ++i) {
119 
120  bm[i->first] |= (1 << i->second);
121 
122  if (DEBUG_LEVEL)
123  cout << i->first << " -> " << i->second << endl;
124  }
125 
126  //...Open output data...
127  ofstream outfile(outname.c_str(), ios::out);
128  if (outfile.fail()) {
129  cout << NAME << " !!! can not open file" << endl
130  << " " << outname << endl;
131  return -2;
132  }
133 
134  //...Make an output...
135  outfile << "Input signal bit map" << endl;
136  for (unsigned i = 0; i < 48; i++) {
137  outfile.width(2);
138  outfile << i << " : ";
139  outfile.width(6);
140  outfile << bm[i] << " : ";
141  for (unsigned j = 0; j < 32; j++) {
142  if (j && ((j % 4) == 0))
143  outfile << " ";
144  unsigned x = ((bm[i] >> (31 - j)) & 1);
145  if (x)
146  outfile << 1;
147  else
148  outfile << ".";
149  }
150  outfile << endl;
151  }
152 
153  //...Simulate TRGPacker (hit pattern in 16ns x2)...
154  outfile << "Hit pattern in 16ns" << endl;
155  outfile << " "
156  << "7654321_987654321_987654321_987654321_9876543210" << endl;
157  unsigned long long hitptn[2];
158  memset(hitptn, 0, sizeof(unsigned long long) * 2);
159  for (unsigned i = 0; i < 2; i++) {
160  for (unsigned j = 0; j < 48; j++) {
161  bool hit = (bm[j] >> (i * 16)) & 0xffff;
162  if (hit)
163  hitptn[i] |= ((unsigned long long) 1 << j);
164 // cout << "j,bm[j]=" << j << "," << bm[j] << "," << hit << ","
165 // << hitptn[i] << endl;
166 
167  }
168  outfile << i << " : ";
169  outfile.width(12);
170  outfile << hex << hitptn[i] << " : ";
171  for (unsigned k = 0; k < 48; k++) {
172  unsigned x = ((hitptn[i] >> (47 - k)) & 1);
173  if (x)
174  outfile << 1;
175  else
176  outfile << ".";
177  }
178  outfile << endl;
179  }
180 
181  //...Simulate TRGPacker (fine timing in 16ns x2)...
182  outfile << "Fine timing of central cells in 16ns" << endl;
183  unsigned fineTiming[2][48];
184  memset(fineTiming, 0, sizeof(unsigned) * 2 * 48);
185  for (unsigned i = 0; i < 2; i++) {
186  outfile << i << " : ";
187  for (unsigned j = 0; j < 48; j++) {
188  unsigned timing = (bm[j] >> (i * 16)) & 0xffff;
189  fineTiming[i][j] = timing;
190  outfile.width(4);
191  outfile << hex << fineTiming[i][j];
192  if ((j % 8) == 7)
193  outfile << endl << " ";
194  else
195  outfile << " ";
196 
197  }
198  outfile << endl;
199  }
200 
201 
202 
203 
204  //...Termination...
205  cout << NAME << " ... terminated" << endl;
206 }
Abstract base class for different kinds of events.
int main(int argc, char **argv)
Run all tests.
Definition: test_main.cc:91