ATLAS Offline Software
TGCDatabaseInPP.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <fstream>
8 #include <sstream>
9 
10 namespace MuonTGC_Cabling
11 {
12 
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 
27  : TGCDatabase(right)
28 {
33 }
34 
36 {
37 }
38 
39 bool 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 
62 int 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 
77 int 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 
87 void TGCDatabaseInPP::getindexDBVectorIn(std::vector<int>& tmpindexDBIn) const
88 {
89  tmpindexDBIn = m_indexDBIn;
90 }
91 
92 void TGCDatabaseInPP::getNIndexDBIn(int& tmpNIndexDBIn) const
93 {
94  tmpNIndexDBIn = m_NIndexDBIn;
95 }
96 
97 void TGCDatabaseInPP::getmaxIndexIn(int* tmpmaxIndexIn) const
98 {
99  for(int iIndexIn=0; iIndexIn<NIndexIn; iIndexIn++) {
100  tmpmaxIndexIn[iIndexIn] = m_maxIndexIn[iIndexIn];
101  }
102 }
103 
104 void 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(entry);
150  }
151 
152  file.close();
153 
154  makeIndexDBIn();
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 
176 int TGCDatabaseInPP::convertIndexDBIn(int* indexIn) const
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
MuonTGC_Cabling::TGCDatabaseInPP::IndexInMax
@ IndexInMax
Definition: TGCDatabaseInPP.h:31
ConvertOldHistosToNewHistos.converted
converted
Definition: ConvertOldHistosToNewHistos.py:40
checkFileSG.line
line
Definition: checkFileSG.py:75
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
MuonTGC_Cabling::TGCDatabaseInPP::~TGCDatabaseInPP
virtual ~TGCDatabaseInPP(void)
Destructor.
Definition: TGCDatabaseInPP.cxx:35
index
Definition: index.py:1
MuonTGC_Cabling::TGCDatabaseInPP::find
virtual int find(const std::vector< int > &) const override
Definition: TGCDatabaseInPP.cxx:62
MuonTGC_Cabling::TGCDatabaseInPP::update
virtual bool update(const std::vector< int > &) override
Definition: TGCDatabaseInPP.cxx:39
MuonTGC_Cabling::TGCDatabaseInPP::m_minIndexIn
int m_minIndexIn[NIndexIn]
Definition: TGCDatabaseInPP.h:69
MuonTGC_Cabling::TGCDatabaseInPP::readDB
virtual void readDB(void) override
Definition: TGCDatabaseInPP.cxx:111
MuonTGC_Cabling::TGCDatabaseInPP::getminIndexIn
virtual void getminIndexIn(int *tmpminIndexIn) const
Get the minimum values of indexIn with NIndexIn dimensions.
Definition: TGCDatabaseInPP.cxx:104
MuonTGC_Cabling::TGCDatabaseInPP::getindexDBVectorIn
virtual void getindexDBVectorIn(std::vector< int > &tmpindexDBIn) const
Get the IndexDBIn table.
Definition: TGCDatabaseInPP.cxx:87
MuonTGC_Cabling::TGCDatabaseInPP::getNIndexDBIn
virtual void getNIndexDBIn(int &tmpNIndexDBIn) const
Get the size of the IndexDBIn table.
Definition: TGCDatabaseInPP.cxx:92
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::TGCDatabaseInPP
Definition: TGCDatabaseInPP.h:14
TGCDatabaseInPP.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
MuonTGC_Cabling::TGCDatabaseInPP::m_indexDBIn
std::vector< int > m_indexDBIn
Definition: TGCDatabaseInPP.h:66
MuonTGC_Cabling
Definition: TGCCable.h:13
MuonTGC_Cabling::TGCDatabaseInPP::TGCDatabaseInPP
TGCDatabaseInPP(void)
Definition: TGCDatabaseInPP.h:59
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
file
TFile * file
Definition: tile_monitor.h:29
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
python.egammaTruthD3PDObject.blockname
blockname
Definition: egammaTruthD3PDObject.py:64
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
MuonTGC_Cabling::TGCDatabaseInPP::makeIndexDBIn
virtual void makeIndexDBIn(void)
Make the IndexDBIn table.
Definition: TGCDatabaseInPP.cxx:157
MuonTGC_Cabling::TGCDatabase::m_blockname
std::string m_blockname
Definition: TGCDatabase.h:53
MuonTGC_Cabling::TGCDatabaseInPP::m_NIndexDBIn
int m_NIndexDBIn
Definition: TGCDatabaseInPP.h:67
DeMoScan.index
string index
Definition: DeMoScan.py:362
MuonTGC_Cabling::TGCDatabaseInPP::IndexInMin
@ IndexInMin
Definition: TGCDatabaseInPP.h:31
MuonTGC_Cabling::TGCDatabaseInPP::convertIndexDBIn
virtual int convertIndexDBIn(int *indexIn) const
Get the internal number, which is between 0 and NIndexDBIn-1.
Definition: TGCDatabaseInPP.cxx:176
MuonTGC_Cabling::TGCDatabaseInPP::getmaxIndexIn
virtual void getmaxIndexIn(int *tmpmaxIndexIn) const
Get the maximum values of indexIn with NIndexIn dimensions.
Definition: TGCDatabaseInPP.cxx:97
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
MuonTGC_Cabling::TGCDatabase::m_database
std::vector< std::vector< int > > m_database
Definition: TGCDatabase.h:54
MuonTGC_Cabling::TGCDatabaseInPP::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: TGCDatabaseInPP.cxx:77
MuonTGC_Cabling::TGCDatabaseInPP::NIndexIn
@ NIndexIn
Definition: TGCDatabaseInPP.h:31
MuonTGC_Cabling::TGCDatabaseInPP::m_maxIndexIn
int m_maxIndexIn[NIndexIn]
Definition: TGCDatabaseInPP.h:68