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 string path = getenv(ENV_PATH);
59 const string inname = path + "/data/trg/" + argv[1];
60 cout << tab << "CDC Wire Config : " << inname << endl;
61 cout << tab << "CDC Trigger Config : " << outname << endl;
62
63 //...Open configuration data...
64 ifstream infile(inname.c_str(), ios::in);
65 if (infile.fail()) {
66 cout << NAME << " !!! can not open file" << endl
67 << " " << inname << endl;
68 return -2;
69 }
70
71 //...Get CDC geometry...
72// TRGCDC & cdc = * TRGCDC::getTRGCDC();
73// cdc.dump("geometry");
74// return 0;
75
76 //...Read configuration data
77 string cdcVersion = "";
78 char b[800];
79 unsigned lines = 0;
80 unsigned id[100];
81 string type[100];
82 unsigned sid[100];
83 unsigned nw[100];
84 unsigned lid[100];
85 unsigned asid[100];
86 unsigned assid[100];
87 while (! infile.eof()) {
88 infile.getline(b, 800);
89 string l(b);
90
91 bool skip = false;
92 for (unsigned i = 0; i < 7; i++) {
93 string car = TRGUtil::carstring(l);
94 l = TRGUtil::cdrstring(l);
95
96 if (car[0] == '#') {
97 skip = true;
98 break;
99 } else if (car == "CDC") {
100 cdcVersion = string(b);
101 skip = true;
102 break;
103 }
104
105 if (i == 0) {
106 id[lines] = atoi(car.c_str());
107 } else if (i == 1) {
108 type[lines] = car;
109 } else if (i == 2) {
110 sid[lines] = atoi(car.c_str());
111 } else if (i == 3) {
112 nw[lines] = atoi(car.c_str());
113 } else if (i == 4) {
114 lid[lines] = atoi(car.c_str());
115 } else if (i == 5) {
116 asid[lines] = atoi(car.c_str());
117 } else if (i == 6) {
118 assid[lines] = atoi(car.c_str());
119 }
120 }
121
122 if (skip)
123 continue;
124
125 if (DEBUG_LEVEL)
126 cout << lines
127 << " " << id[lines]
128 << " " << type[lines]
129 << " " << sid[lines]
130 << " " << nw[lines]
131 << " " << lid[lines]
132 << " " << asid[lines]
133 << " " << assid[lines]
134 << endl;
135
136 ++lines;
137 }
138 infile.close();
139
140 //...Open configuration data...
141 ofstream outfile(outname.c_str(), ios::out);
142 if (outfile.fail()) {
143 cout << NAME << " !!! can not open file" << endl
144 << " " << outname << endl;
145 return -2;
146 }
147
148 //...Front-end...
149 unsigned fidBase = 0;
150 vector<unsigned> front[N_FRONT];
151
152 //...Merger...
153 unsigned midBase = 0;
154 vector<unsigned> merge[N_FRONT];
155
156 //...Wire by wire connection table...
157 outfile << "# Generated by " << NAME << " " << VERSION << endl;
158 outfile << "# " << ts1 << endl;
159 outfile << "#" << endl;
160 outfile << cdcVersion << endl;
161 outfile << "CDC Trigger Config Version " << version << endl;
162 outfile << "#" << endl;
163 outfile << "# note : id is id of a board. Therefore tsf id is same as "
164 << "super layer id" << endl;
165 outfile << "# note : id 99999 means no connection" << endl;
166 outfile << "#" << endl;
167 outfile << "# wire id | layer id | front id | merge id | tsf id" << endl;
168 unsigned nWires = 0;
169 for (unsigned i = 0; i < lines; i++) {
170
171 //...# of front-end...
172 const unsigned nFront = nw[i] / 16;
173
174 //...# of merger...
175 unsigned nMerge = nFront / 4;
176 if (nFront % 4)
177 ++nMerge;
178
179// cout << "nMerge = " << nMerge << endl;
180
181 //...Wire loop...
182 for (unsigned j = 0; j < nw[i]; j++) {
183
184 //...Wire ID...
185 const unsigned wid = nWires + j;
186
187 //...Front-end...
188 const unsigned fid = j / 16 + fidBase;
189 front[fid].push_back(wid);
190
191 //...Merger...
192 unsigned mid = j / 64 + midBase;
193 if (fid < 10)
194 mid = NOT_CONNECTED;
195 else
196 merge[mid].push_back(wid);
197
198 outfile.width(9);
199 outfile << wid;
200 outfile << " ";
201 outfile.width(8);
202 outfile << i;
203 outfile << " ";
204 outfile.width(8);
205 outfile << fid;
206 outfile << " ";
207 outfile.width(8);
208 outfile << mid;
209 outfile << " ";
210 outfile.width(6);
211 if (mid == NOT_CONNECTED)
212 outfile << NOT_CONNECTED;
213 else
214 outfile << sid[i];
215 outfile << endl;
216 }
217
218 //...Front-end...
219 if (fidBase == 0) {
220 if (front[fidBase].size() == 32)
221 fidBase += nFront;
222 } else {
223 if (front[fidBase].size() == 48)
224 fidBase += nFront;
225 }
226
227 //...Merger...
228 if (merge[midBase].size() == 384)
229 midBase += nMerge;
230
231 //...# of wires...
232 nWires += nw[i];
233
234 }
235
236 //...Implementaion...
237
238
239 //...Termination...
240 cout << NAME << " ... terminated" << endl;
241}
std::vector< std::vector< double > > merge(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.