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{
12
13TGCDatabaseInPP::TGCDatabaseInPP(const std::string& filename,
14 const std::string& blockname)
15 : TGCDatabase(TGCDatabase::InPP, filename, blockname), m_NIndexDBIn(0)
16{
17 for(int iIndexIn=0; iIndexIn<NIndexIn; iIndexIn++) {
18 m_maxIndexIn[iIndexIn] = 0;
19 m_minIndexIn[iIndexIn] = 9999;
20 }
21
22 // read out ascii file and fill database
24}
25
34
38
39bool TGCDatabaseInPP::update(const std::vector<int>& input)
40{
41 int ip = find(input);
42 if(ip<0) return false;
43
44 const unsigned int input_size = input.size();
45
46 const unsigned int database_ip_size = m_database[ip].size();
47 for(unsigned int i=3; i<database_ip_size; i++){
48 if( i< input.size()){
49 m_database[ip].at(i) = input.at(i);
50 } else {
51 m_database[ip].at(i) = -1;
52 }
53 }
54 if(database_ip_size < input_size){
55 for(unsigned int i=database_ip_size; i<input_size; i++){
56 m_database[ip].push_back(input.at(i));
57 }
58 }
59 return true;
60}
61
62int TGCDatabaseInPP::find(const std::vector<int>& channel) const
63{
64 int index=-1;
65 const unsigned int size = m_database.size();
66 for(unsigned int i=0; i<size; i++){
67 if(m_database[i].at(2) == channel.at(2) &&
68 m_database[i].at(1) == channel.at(1) &&
69 m_database[i].at(0) == channel.at(0)) {
70 index = i;
71 break;
72 }
73 }
74 return index;
75}
76
77int TGCDatabaseInPP::getIndexDBIn(int* indexIn) const
78{
79 if(!indexIn) return -1;
80
81 int converted = convertIndexDBIn(indexIn);
82 if(converted<0 || converted>=m_NIndexDBIn) return -1;
83
84 return m_indexDBIn.at(converted);
85}
86
87void TGCDatabaseInPP::getindexDBVectorIn(std::vector<int>& tmpindexDBIn) const
88{
89 tmpindexDBIn = m_indexDBIn;
90}
91
92void TGCDatabaseInPP::getNIndexDBIn(int& tmpNIndexDBIn) const
93{
94 tmpNIndexDBIn = m_NIndexDBIn;
95}
96
97void TGCDatabaseInPP::getmaxIndexIn(int* tmpmaxIndexIn) const
98{
99 for(int iIndexIn=0; iIndexIn<NIndexIn; iIndexIn++) {
100 tmpmaxIndexIn[iIndexIn] = m_maxIndexIn[iIndexIn];
101 }
102}
103
104void TGCDatabaseInPP::getminIndexIn(int* tmpminIndexIn) const
105{
106 for(int iIndexIn=0; iIndexIn<NIndexIn; iIndexIn++) {
107 tmpminIndexIn[iIndexIn] = m_minIndexIn[iIndexIn];
108 }
109}
110
112 std::ifstream file(m_filename.c_str());
113 std::string buf;
114
115 for(int iIndexIn=0; iIndexIn<NIndexIn; iIndexIn++) {
116 m_maxIndexIn[iIndexIn] = 0;
117 m_minIndexIn[iIndexIn] = 9999;
118 }
119
120 while(getline(file,buf)){
121 if(buf.substr(0,m_blockname.size())==m_blockname) break;
122 }
123
124 while(getline(file,buf)){
125 if(buf.substr(0,1)=="E"||buf.substr(0,1)=="F") break;
126 std::istringstream line(buf);
127 std::vector<int> entry;
128 for(int i=0; i<6; i++){
129 int temp=-1;
130 line >> temp;
131 entry.push_back(temp);
132
133 if(IndexInMin<=i && i<=IndexInMax) {
134 int j = i-IndexInMin;
135 if(m_maxIndexIn[j]<temp) {
136 m_maxIndexIn[j] = temp;
137 }
138 if(m_minIndexIn[j]>temp) {
139 m_minIndexIn[j] = temp;
140 }
141 }
142 }
143 for(int i=0; i<3; i++){
144 int temp=-1;
145 line >> temp;
146 if(temp<0) break;
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] = m_database.at(i).at(iIndexIn+IndexInMin);
171 }
172 m_indexDBIn.at(convertIndexDBIn(tmpValIndexIn)) = i;
173 }
174}
175
177{
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} // end of namespace
virtual void makeIndexDBIn(void)
Make the IndexDBIn table.
virtual ~TGCDatabaseInPP(void)
Destructor.
virtual void readDB(void) override
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 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 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.
std::vector< std::vector< int > > m_database
Definition TGCDatabase.h:54
TGCDatabase(DatabaseType type=NoDatabaseType)
Definition index.py:1
TFile * file