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