ATLAS Offline Software
Loading...
Searching...
No Matches
TGCDatabaseInPP.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
12TGCDatabaseInPP::TGCDatabaseInPP(const std::string& filename,
13 const std::string& blockname)
14 : TGCDatabase(TGCDatabase::InPP, filename, blockname), m_NIndexDBIn(0) {
15 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
16 m_maxIndexIn[iIndexIn] = 0;
17 m_minIndexIn[iIndexIn] = 9999;
18 }
19
20 // read out ascii file and fill database
22}
23
31
33
34bool TGCDatabaseInPP::update(const std::vector<int>& input) {
35 int ip = find(input);
36 if (ip < 0) {
37 return false;
38 }
39
40 const unsigned int input_size = input.size();
41
42 const unsigned int database_ip_size = m_database[ip].size();
43 for (unsigned int i = 3; i < database_ip_size; i++) {
44 if (i < input.size()) {
45 m_database[ip].at(i) = input.at(i);
46 } else {
47 m_database[ip].at(i) = -1;
48 }
49 }
50 if (database_ip_size < input_size) {
51 for (unsigned int i = database_ip_size; i < input_size; i++) {
52 m_database[ip].push_back(input.at(i));
53 }
54 }
55 return true;
56}
57
58int TGCDatabaseInPP::find(const std::vector<int>& channel) const {
59 int index = -1;
60 const unsigned int size = m_database.size();
61 for (unsigned int i = 0; i < size; i++) {
62 if (m_database[i].at(2) == channel.at(2) &&
63 m_database[i].at(1) == channel.at(1) &&
64 m_database[i].at(0) == channel.at(0)) {
65 index = i;
66 break;
67 }
68 }
69 return index;
70}
71
72int TGCDatabaseInPP::getIndexDBIn(int* indexIn) const {
73 if (!indexIn) {
74 return -1;
75 }
76
77 int converted = convertIndexDBIn(indexIn);
78 if (converted < 0 || converted >= m_NIndexDBIn) {
79 return -1;
80 }
81
82 return m_indexDBIn.at(converted);
83}
84
85void TGCDatabaseInPP::getindexDBVectorIn(std::vector<int>& tmpindexDBIn) const {
86 tmpindexDBIn = m_indexDBIn;
87}
88
89void TGCDatabaseInPP::getNIndexDBIn(int& tmpNIndexDBIn) const {
90 tmpNIndexDBIn = m_NIndexDBIn;
91}
92
93void TGCDatabaseInPP::getmaxIndexIn(int* tmpmaxIndexIn) const {
94 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
95 tmpmaxIndexIn[iIndexIn] = m_maxIndexIn[iIndexIn];
96 }
97}
98
99void TGCDatabaseInPP::getminIndexIn(int* tmpminIndexIn) const {
100 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
101 tmpminIndexIn[iIndexIn] = m_minIndexIn[iIndexIn];
102 }
103}
104
106 std::ifstream file(m_filename.c_str());
107 std::string buf;
108
109 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
110 m_maxIndexIn[iIndexIn] = 0;
111 m_minIndexIn[iIndexIn] = 9999;
112 }
113
114 while (getline(file, buf)) {
115 if (buf.substr(0, m_blockname.size()) == m_blockname) {
116 break;
117 }
118 }
119
120 while (getline(file, buf)) {
121 if (buf.substr(0, 1) == "E" || buf.substr(0, 1) == "F") {
122 break;
123 }
124 std::istringstream line(buf);
125 std::vector<int> entry;
126 for (int i = 0; i < 6; i++) {
127 int temp = -1;
128 line >> temp;
129 entry.push_back(temp);
130
131 if (IndexInMin <= i && i <= IndexInMax) {
132 int j = i - IndexInMin;
133 if (m_maxIndexIn[j] < temp) {
134 m_maxIndexIn[j] = temp;
135 }
136 if (m_minIndexIn[j] > temp) {
137 m_minIndexIn[j] = temp;
138 }
139 }
140 }
141 for (int i = 0; i < 3; i++) {
142 int temp = -1;
143 line >> temp;
144 if (temp < 0) {
145 break;
146 }
147 entry.push_back(temp);
148 }
149 m_database.push_back(std::move(entry));
150 }
151
152 file.close();
153
155}
156
158 m_NIndexDBIn = 1;
159 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
160 m_NIndexDBIn *= (m_maxIndexIn[iIndexIn] - m_minIndexIn[iIndexIn] + 1);
161 }
162 for (int iIndexDBIn = 0; iIndexDBIn < m_NIndexDBIn; iIndexDBIn++) {
163 m_indexDBIn.push_back(-1);
164 }
165
166 const int size = m_database.size();
167 for (int i = 0; i < size; i++) {
168 int tmpValIndexIn[NIndexIn];
169 for (int iIndexIn = 0; iIndexIn < NIndexIn; iIndexIn++) {
170 tmpValIndexIn[iIndexIn] =
171 m_database.at(i).at(iIndexIn + IndexInMin);
172 }
173 m_indexDBIn.at(convertIndexDBIn(tmpValIndexIn)) = i;
174 }
175}
176
177int TGCDatabaseInPP::convertIndexDBIn(int* indexIn) const {
178 int converted = indexIn[0] - m_minIndexIn[0];
179 for (int iIndexIn = 1; iIndexIn < NIndexIn; iIndexIn++) {
180 converted *= (m_maxIndexIn[iIndexIn] - m_minIndexIn[iIndexIn] + 1);
181 converted += indexIn[iIndexIn] - m_minIndexIn[iIndexIn];
182 }
183 return converted;
184}
185
186} // namespace MuonTGC_Cabling
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 makeIndexDBIn()
Make the IndexDBIn table.
virtual int find(const std::vector< int > &) const override
TGCDatabaseInPP(const std::string &filename, const std::string &blockname)
Constructor.
virtual bool update(const std::vector< int > &) override
virtual void getmaxIndexIn(int *tmpmaxIndexIn) const
Get the maximum values of indexIn with NIndexIn dimensions.
virtual void getminIndexIn(int *tmpminIndexIn) const
Get the minimum values of indexIn with NIndexIn dimensions.
virtual void getNIndexDBIn(int &tmpNIndexDBIn) const
Get the size of the IndexDBIn table.
virtual ~TGCDatabaseInPP()
Destructor.
virtual int convertIndexDBIn(int *indexIn) const
Get the internal number, which is between 0 and NIndexDBIn-1.
virtual void getindexDBVectorIn(std::vector< int > &tmpindexDBIn) const
Get the IndexDBIn table.
TGCDatabase(DatabaseType type=NoDatabaseType)
std::vector< std::vector< int > > m_database
Definition TGCDatabase.h:56
Definition index.py:1
TFile * file