ATLAS Offline Software
Loading...
Searching...
No Matches
TGCDatabaseASDToPP.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <fstream>
8#include <sstream>
9
10namespace MuonTGC_Cabling {
11
12const int TGCDatabaseASDToPP::IndexIn[NIndexIn] = {0, 1, 6};
13const int TGCDatabaseASDToPP::ReverseIndexIn[DATABASESIZE] = {0, 1, -1, -1,
14 -1, -1, 2, -1};
15const int TGCDatabaseASDToPP::IndexOut[NIndexOut] = {3, 4, 5};
16const int TGCDatabaseASDToPP::ReverseIndexOut[DATABASESIZE] = {-1, -1, -1, 0,
17 1, 2, -1, -1};
18
19TGCDatabaseASDToPP::TGCDatabaseASDToPP(const std::string& filename,
20 const std::string& blockname,
21 bool v_isCommon)
22 : TGCDatabase(TGCDatabase::ASDToPP, filename, blockname),
23 m_NIndexDBIn(0),
25 m_isCommon(v_isCommon) {
26 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
27 m_maxIndexIn[iIndexIn] = 0;
28 m_minIndexIn[iIndexIn] = 9999;
29 }
30 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
31 m_maxIndexOut[iIndexOut] = 0;
32 m_minIndexOut[iIndexOut] = 9999;
33 }
34
35 // read out ascii file and fill database
37}
38
52
54
55bool TGCDatabaseASDToPP::update(const std::vector<int>& input) {
56 int ip = find(input);
57 if (ip < 0) {
58 return false;
59 }
60
61 int tmpValIndexOut[NIndexOut];
62 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
63 tmpValIndexOut[iIndexOut] = input.at(IndexOut[iIndexOut]);
64 }
65
66 bool over_range = false;
67 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
68 if (m_maxIndexOut[iIndexOut] < tmpValIndexOut[iIndexOut]) {
69 m_maxIndexOut[iIndexOut] = tmpValIndexOut[iIndexOut];
70 over_range = true;
71 }
72 if (m_minIndexOut[iIndexOut] > tmpValIndexOut[iIndexOut]) {
73 m_minIndexOut[iIndexOut] = tmpValIndexOut[iIndexOut];
74 over_range = true;
75 }
76 }
77 if (over_range) {
78 m_indexDBOut.clear();
80 }
81
82 int converted = convertIndexDBOut(tmpValIndexOut);
83 if (converted < 0 || converted >= m_NIndexDBOut) {
84 return false;
85 }
86
87 m_indexDBOut.at(converted) = ip;
88
89 m_database[ip].at(3) = input.at(3);
90 m_database[ip].at(4) = input.at(4);
91 m_database[ip].at(5) = input.at(5);
92
93 return true;
94}
95
96int TGCDatabaseASDToPP::find(const std::vector<int>& channel) const {
97 int index = -1;
98 const size_t size = m_database.size();
99 for (size_t i = 0; i < size; i++) {
100 if (m_database[i].at(2) == channel.at(2) &&
101 m_database[i].at(1) == channel.at(1) &&
102 m_database[i].at(0) == channel.at(0)) {
103 index = i;
104 break;
105 }
106 }
107 return index;
108}
109
110int TGCDatabaseASDToPP::getIndexDBIn(int* indexIn) const {
111 if (!indexIn) {
112 return -1;
113 }
114
115 int converted = convertIndexDBIn(indexIn);
116 if (converted < 0 || converted >= m_NIndexDBIn) {
117 return -1;
118 }
119
120 return m_indexDBIn.at(converted);
121}
122
124 std::vector<int>& tmpindexDBIn) const {
125 tmpindexDBIn = m_indexDBIn;
126}
127
128void TGCDatabaseASDToPP::getNIndexDBIn(int& tmpNIndexDBIn) const {
129 tmpNIndexDBIn = m_NIndexDBIn;
130}
131
132void TGCDatabaseASDToPP::getmaxIndexIn(int* tmpmaxIndexIn) const {
133 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
134 tmpmaxIndexIn[iIndexIn] = m_maxIndexIn[iIndexIn];
135 }
136}
137
138void TGCDatabaseASDToPP::getminIndexIn(int* tmpminIndexIn) const {
139 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
140 tmpminIndexIn[iIndexIn] = m_minIndexIn[iIndexIn];
141 }
142}
143
144int TGCDatabaseASDToPP::getIndexDBOut(int* indexOut) const {
145 if (!indexOut) {
146 return -1;
147 }
148
149 int converted = convertIndexDBOut(indexOut);
150 if (converted < 0 || converted >= m_NIndexDBOut) {
151 return -1;
152 }
153
154 return m_indexDBOut.at(converted);
155}
156
158 std::vector<int>& tmpindexDBOut) const {
159 tmpindexDBOut = m_indexDBOut;
160}
161
162void TGCDatabaseASDToPP::getNIndexDBOut(int& tmpNIndexDBOut) const {
163 tmpNIndexDBOut = m_NIndexDBOut;
164}
165
166void TGCDatabaseASDToPP::getmaxIndexOut(int* tmpmaxIndexOut) const {
167 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
168 tmpmaxIndexOut[iIndexOut] = m_maxIndexOut[iIndexOut];
169 }
170}
171
172void TGCDatabaseASDToPP::getminIndexOut(int* tmpminIndexOut) const {
173 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
174 tmpminIndexOut[iIndexOut] = m_minIndexOut[iIndexOut];
175 }
176}
177
179 return m_isCommon;
180}
181
183 std::ifstream file(m_filename.c_str());
184 std::string buf;
185
186 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
187 m_maxIndexIn[iIndexIn] = 0;
188 m_minIndexIn[iIndexIn] = 9999;
189 }
190 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
191 m_maxIndexOut[iIndexOut] = 0;
192 m_minIndexOut[iIndexOut] = 9999;
193 }
194
195 while (getline(file, buf)) {
196 if (buf.substr(0, m_blockname.size()) == m_blockname) {
197 break;
198 }
199 }
200
201 while (getline(file, buf)) {
202 if (buf.substr(0, 1) == "E" || buf.substr(0, 1) == "F") {
203 break;
204 }
205 std::istringstream line(buf);
206 std::vector<int> entry;
207 for (int i = 0; i < DATABASESIZE - 2; i++) {
208 int temp = -1;
209 line >> temp;
210 entry.push_back(temp);
211 }
212 m_database.push_back(std::move(entry));
213 }
214
215 file.close();
216
217 int nline = 0;
218 const unsigned int database_size = m_database.size();
219 for (unsigned int i = 0; i < database_size; i++) {
220 // line is defined in whole sector. [0..n]
221 if (i > 0 && m_database[i].at(0) != m_database[i - 1].at(0)) {
222 nline = 0;
223 }
224 m_database[i].push_back(nline++);
225
226 if (i == database_size - 1 ||
227 m_database[i].at(0) != m_database[i + 1].at(0) ||
228 m_database[i].at(1) != m_database[i + 1].at(1)) {
229 // increase with R in chamber [0..n]
230 int totline = m_database[i].at(2) + 1;
231 for (int j = 0; j < totline; j++) {
232 m_database[i - j].push_back(j);
233 }
234 }
235 }
236
237 for (unsigned int i = 0; i < database_size; i++) {
238 for (int j = 0; j < DATABASESIZE; j++) {
239 int temp = m_database[i].at(j);
240 int k = ReverseIndexOut[j];
241 if (k >= 0) {
242 if (m_maxIndexOut[k] < temp) {
243 m_maxIndexOut[k] = temp;
244 }
245 if (m_minIndexOut[k] > temp) {
246 m_minIndexOut[k] = temp;
247 }
248 }
249
250 k = ReverseIndexIn[j];
251 if (k >= 0) {
252 if (m_maxIndexIn[k] < temp) {
253 m_maxIndexIn[k] = temp;
254 }
255 if (m_minIndexIn[k] > temp) {
256 m_minIndexIn[k] = temp;
257 }
258 }
259 }
260 }
261
264}
265
267 m_NIndexDBIn = 1;
268 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
269 m_NIndexDBIn *= (m_maxIndexIn[iIndexIn] - m_minIndexIn[iIndexIn] + 1);
270 }
271 for (int iIndexDBIn = 0; iIndexDBIn < m_NIndexDBIn; iIndexDBIn++) {
272 m_indexDBIn.push_back(-1);
273 }
274
275 const int size = m_database.size();
276 for (int i = 0; i < size; i++) {
277 int tmpValIndexIn[NIndexIn];
278 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
279 tmpValIndexIn[iIndexIn] = m_database.at(i).at(IndexIn[iIndexIn]);
280 }
281 m_indexDBIn.at(convertIndexDBIn(tmpValIndexIn)) = i;
282 }
283}
284
286 int converted = indexIn[0] - m_minIndexIn[0];
287 for (int iIndexIn = 1; iIndexIn < NIndexIn; iIndexIn++) {
288 converted *= (m_maxIndexIn[iIndexIn] - m_minIndexIn[iIndexIn] + 1);
289 converted += indexIn[iIndexIn] - m_minIndexIn[iIndexIn];
290 }
291 return converted;
292}
293
295 m_NIndexDBOut = 1;
296 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
298 (m_maxIndexOut[iIndexOut] - m_minIndexOut[iIndexOut] + 1);
299 }
300 for (int iIndexDBOut = 0; iIndexDBOut < m_NIndexDBOut; iIndexDBOut++) {
301 m_indexDBOut.push_back(-1);
302 }
303
304 const int size = m_database.size();
305 for (int i = 0; i < size; i++) {
306 int tmpValIndexOut[NIndexOut];
307 for (int iIndexOut = 0; iIndexOut < NIndexOut; iIndexOut++) {
308 tmpValIndexOut[iIndexOut] =
309 m_database.at(i).at(IndexOut[iIndexOut]);
310 }
311 m_indexDBOut.at(convertIndexDBOut(tmpValIndexOut)) = i;
312 }
313}
314
316 int converted = indexOut[0] - m_minIndexOut[0];
317 for (int iIndexOut = 1; iIndexOut < NIndexOut; iIndexOut++) {
318 converted *= (m_maxIndexOut[iIndexOut] - m_minIndexOut[iIndexOut] + 1);
319 converted += indexOut[iIndexOut] - m_minIndexOut[iIndexOut];
320 }
321 return converted;
322}
323
324} // namespace MuonTGC_Cabling
static const int IndexIn[NIndexIn]
virtual void makeIndexDBIn(void)
Make the IndexDBIn table.
virtual void getindexDBVectorOut(std::vector< int > &tmpindexDBOut) const
Get the IndexDBOut table.
virtual void makeIndexDBOut(void)
Make the IndexDBOut table.
virtual bool update(const std::vector< int > &) override
TGCDatabaseASDToPP(const std::string &filename, const std::string &blockname, bool v_isCommon=true)
Constructor.
bool m_isCommon
This bool variable is used to know the database is common or sector specific.
static const int ReverseIndexIn[DATABASESIZE]
virtual void getNIndexDBOut(int &tmpNIndexDBOut) const
Get the size of the IndexDBOut table.
virtual ~TGCDatabaseASDToPP(void)
Destructor.
virtual void getminIndexOut(int *tmpminIndexOut) const
Get the minimum values of indexOut with NIndexOut dimensions.
virtual int getIndexDBIn(int *indexIn) const override
Get IndexDBIn (position in the databse between 0 and database.size()-1) from indexIn which is NIndexI...
virtual void getNIndexDBIn(int &tmpNIndexDBIn) const
Get the size of the IndexDBIn table.
virtual void getindexDBVectorIn(std::vector< int > &tmpindexDBIn) const
Get the IndexDBIn table.
virtual int getIndexDBOut(int *indexOut) const override
Get IndexDBOut (position in the databse between 0 and database.size()-1) from indexOut which is NInde...
virtual int convertIndexDBIn(int *indexIn) const
Get the interal number, which is between 0 and NIndexDBIn-1.
virtual void getmaxIndexIn(int *tmpmaxIndexIn) const
Get the maximum values of indexIn with NIndexIn dimensions.
bool isCommon() const
This method is used to know the database is common or sector specific.
static const int IndexOut[NIndexOut]
virtual void getmaxIndexOut(int *tmpmaxIndexOut) const
Get the maximum values of indexOut with NIndexOut dimensions.
virtual int convertIndexDBOut(int *indexOut) const
Get the interal number, which is between 0 and NIndexDBOut-1.
static const int ReverseIndexOut[DATABASESIZE]
virtual void getminIndexIn(int *tmpminIndexIn) const
Get the minimum values of indexIn with NIndexIn dimensions.
virtual int find(const std::vector< int > &) const override
TGCDatabase(DatabaseType type=NoDatabaseType)
std::vector< std::vector< int > > m_database
Definition TGCDatabase.h:56
Definition index.py:1
TFile * file