Belle II Software development
TRGCDCConfig.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 generate CDC trigger configuration data
11//-----------------------------------------------------------------------------
12
13#define TRG_SHORT_NAMES
14
15#include <cstdlib>
16#include <iostream>
17#include <fstream>
18#include <string>
19#include <vector>
20#include "trg/trg/Utilities.h"
21
22using namespace std;
23using namespace Belle2;
24
25#define DEBUG_LEVEL 0
26#define NAME "TRGCDCConfig"
27#define VERSION "version 0.01"
28#define ENV_PATH "BELLE2_LOCAL_DIR"
29#define N_FRONT 500
30#define NOT_CONNECTED 99999
31
32int
33main(int argc, const char* argv[])
34{
35
36 cout << NAME << " ... " << VERSION << endl;
37 const string tab = " ";
38
39 //...Check arguments...
40 if (argc < 3) {
41 cout << NAME << " !!! two arguments necessary" << endl
42 << tab << " 1 : CDCWireConfig data file" << endl
43 << tab << " 2 : Version for new config file" << endl;
44 return -1;
45 }
46
47 //...Date...
48 string ts0 = TRGUtil::dateStringF();
49 string ts1 = TRGUtil::dateString();
50
51 //...2nd argument...
52 const string version = argv[2];
53
54 //...1st argument...
55 const string outname = "TRGCDCConfig_" + version + "_" + ts0 + ".dat";
56
57 //...Get path to data...
58 const char* envPath = getenv(ENV_PATH);
59 const string path = (envPath != nullptr ? envPath : "");
60 const string inname = path + "/data/trg/" + argv[1];
61 cout << tab << "CDC Wire Config : " << inname << endl;
62 cout << tab << "CDC Trigger Config : " << outname << endl;
63
64 //...Open configuration data...
65 ifstream infile(inname.c_str(), ios::in);
66 if (infile.fail()) {
67 cout << NAME << " !!! can not open file" << endl
68 << " " << inname << endl;
69 return -2;
70 }
71
72 //...Get CDC geometry...
73// TRGCDC & cdc = * TRGCDC::getTRGCDC();
74// cdc.dump("geometry");
75// return 0;
76
77 //...Read configuration data
78 string cdcVersion = "";
79 char b[800];
80 unsigned lines = 0;
81 unsigned id[100];
82 string type[100];
83 unsigned sid[100];
84 unsigned nw[100];
85 unsigned lid[100];
86 unsigned asid[100];
87 unsigned assid[100];
88 while (! infile.eof()) {
89 infile.getline(b, 800);
90 string l(b);
91
92 bool skip = false;
93 for (unsigned i = 0; i < 7; i++) {
94 string car = TRGUtil::carstring(l);
95 l = TRGUtil::cdrstring(l);
96
97 if (car[0] == '#') {
98 skip = true;
99 break;
100 } else if (car == "CDC") {
101 cdcVersion = string(b);
102 skip = true;
103 break;
104 }
105
106 if (i == 0) {
107 id[lines] = atoi(car.c_str());
108 } else if (i == 1) {
109 type[lines] = car;
110 } else if (i == 2) {
111 sid[lines] = atoi(car.c_str());
112 } else if (i == 3) {
113 nw[lines] = atoi(car.c_str());
114 } else if (i == 4) {
115 lid[lines] = atoi(car.c_str());
116 } else if (i == 5) {
117 asid[lines] = atoi(car.c_str());
118 } else if (i == 6) {
119 assid[lines] = atoi(car.c_str());
120 }
121 }
122
123 if (skip)
124 continue;
125
126 if (DEBUG_LEVEL)
127 cout << lines
128 << " " << id[lines]
129 << " " << type[lines]
130 << " " << sid[lines]
131 << " " << nw[lines]
132 << " " << lid[lines]
133 << " " << asid[lines]
134 << " " << assid[lines]
135 << endl;
136
137 ++lines;
138 }
139 infile.close();
140
141 //...Open configuration data...
142 ofstream outfile(outname.c_str(), ios::out);
143 if (outfile.fail()) {
144 cout << NAME << " !!! can not open file" << endl
145 << " " << outname << endl;
146 return -2;
147 }
148
149 //...Front-end...
150 unsigned fidBase = 0;
151 vector<unsigned> front[N_FRONT];
152
153 //...Merger...
154 unsigned midBase = 0;
155 vector<unsigned> merge[N_FRONT];
156
157 //...Wire by wire connection table...
158 outfile << "# Generated by " << NAME << " " << VERSION << endl;
159 outfile << "# " << ts1 << endl;
160 outfile << "#" << endl;
161 outfile << cdcVersion << endl;
162 outfile << "CDC Trigger Config Version " << version << endl;
163 outfile << "#" << endl;
164 outfile << "# note : id is id of a board. Therefore tsf id is same as "
165 << "super layer id" << endl;
166 outfile << "# note : id 99999 means no connection" << endl;
167 outfile << "#" << endl;
168 outfile << "# wire id | layer id | front id | merge id | tsf id" << endl;
169 unsigned nWires = 0;
170 for (unsigned i = 0; i < lines; i++) {
171
172 //...# of front-end...
173 const unsigned nFront = nw[i] / 16;
174
175 //...# of merger...
176 unsigned nMerge = nFront / 4;
177 if (nFront % 4)
178 ++nMerge;
179
180// cout << "nMerge = " << nMerge << endl;
181
182 //...Wire loop...
183 for (unsigned j = 0; j < nw[i]; j++) {
184
185 //...Wire ID...
186 const unsigned wid = nWires + j;
187
188 //...Front-end...
189 const unsigned fid = j / 16 + fidBase;
190 front[fid].push_back(wid);
191
192 //...Merger...
193 unsigned mid = j / 64 + midBase;
194 if (fid < 10)
195 mid = NOT_CONNECTED;
196 else
197 merge[mid].push_back(wid);
198
199 outfile.width(9);
200 outfile << wid;
201 outfile << " ";
202 outfile.width(8);
203 outfile << i;
204 outfile << " ";
205 outfile.width(8);
206 outfile << fid;
207 outfile << " ";
208 outfile.width(8);
209 outfile << mid;
210 outfile << " ";
211 outfile.width(6);
212 if (mid == NOT_CONNECTED)
213 outfile << NOT_CONNECTED;
214 else
215 outfile << sid[i];
216 outfile << endl;
217 }
218
219 //...Front-end...
220 if (fidBase == 0) {
221 if (front[fidBase].size() == 32)
222 fidBase += nFront;
223 } else {
224 if (front[fidBase].size() == 48)
225 fidBase += nFront;
226 }
227
228 //...Merger...
229 if (merge[midBase].size() == 384)
230 midBase += nMerge;
231
232 //...# of wires...
233 nWires += nw[i];
234
235 }
236
237 //...Implementation...
238
239
240 //...Termination...
241 cout << NAME << " ... terminated" << endl;
242}
std::vector< std::vector< double > > merge(const std::vector< std::vector< std::vector< double > > > &toMerge)
merge { vector<double> a, vector<double> b} into {a, b}
Definition tools.h:41
Abstract base class for different kinds of events.
STL namespace.