14 #define TRG_SHORT_NAMES
21 #include "trg/trg/Utilities.h"
27 #define NAME "TRGCDCConfig"
28 #define VERSION "version 0.01"
29 #define ENV_PATH "BELLE2_LOCAL_DIR"
31 #define NOT_CONNECTED 99999
34 main(
int argc,
char* argv[])
37 cout << NAME <<
" ... " << VERSION << endl;
38 const string tab =
" ";
42 cout << NAME <<
" !!! two arguments necessary" << endl
43 << tab <<
" 1 : CDCWireConfig data file" << endl
44 << tab <<
" 2 : Version for new config file" << endl;
49 string ts0 = TRGUtil::dateStringF();
50 string ts1 = TRGUtil::dateString();
53 const string version = argv[2];
56 const string outname =
"TRGCDCConfig_" + version +
"_" + ts0 +
".dat";
59 const string path = getenv(ENV_PATH);
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;
65 ifstream infile(inname.c_str(), ios::in);
67 cout << NAME <<
" !!! can not open file" << endl
68 <<
" " << inname << endl;
78 string cdcVersion =
"";
88 while (! infile.eof()) {
89 infile.getline(b, 800);
93 for (
unsigned i = 0; i < 7; i++) {
94 string car = TRGUtil::carstring(l);
95 l = TRGUtil::cdrstring(l);
100 }
else if (car ==
"CDC") {
101 cdcVersion = string(b);
107 id[lines] = atoi(car.c_str());
111 sid[lines] = atoi(car.c_str());
113 nw[lines] = atoi(car.c_str());
115 lid[lines] = atoi(car.c_str());
117 asid[lines] = atoi(car.c_str());
119 assid[lines] = atoi(car.c_str());
129 <<
" " << type[lines]
133 <<
" " << asid[lines]
134 <<
" " << assid[lines]
142 ofstream outfile(outname.c_str(), ios::out);
143 if (outfile.fail()) {
144 cout << NAME <<
" !!! can not open file" << endl
145 <<
" " << outname << endl;
150 unsigned fidBase = 0;
151 vector<unsigned> front[N_FRONT];
154 unsigned midBase = 0;
155 vector<unsigned>
merge[N_FRONT];
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;
170 for (
unsigned i = 0; i < lines; i++) {
173 const unsigned nFront = nw[i] / 16;
176 unsigned nMerge = nFront / 4;
183 for (
unsigned j = 0; j < nw[i]; j++) {
186 const unsigned wid = nWires + j;
189 const unsigned fid = j / 16 + fidBase;
190 front[fid].push_back(wid);
193 unsigned mid = j / 64 + midBase;
197 merge[mid].push_back(wid);
212 if (mid == NOT_CONNECTED)
213 outfile << NOT_CONNECTED;
221 if (front[fidBase].size() == 32)
224 if (front[fidBase].size() == 48)
229 if (
merge[midBase].size() == 384)
241 cout << NAME <<
" ... terminated" << endl;