ATLAS Offline Software
Loading...
Searching...
No Matches
TGCDatabasePPToSL.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
10namespace MuonTGC_Cabling
11{
12
13TGCDatabasePPToSL::TGCDatabasePPToSL(const std::string& filename,
14 const std::string& blockname)
15 : TGCDatabase(TGCDatabase::PPToSL, filename, blockname)
16{
17 // read out ascii file and fill database
19}
20
25
26
28 std::ifstream file(m_filename.c_str());
29 std::string buf;
30
31 unsigned int space = m_blockname.find(' ');
32 std::string_view module =std::string_view( m_blockname).substr(0,space);
33 std::string_view region = std::string_view(m_blockname).substr(space+1,1);
34 std::string_view type = std::string_view(m_blockname).substr(space+2);
35
36 int offset=-1;
37 if(type == "WT") offset = 1;
38 if(type == "WD") offset = 2;
39 if(type == "ST") offset = 3;
40 if(type == "SD") offset = 4;
41 if(type == "WI") offset = 5;
42 if(type == "SI") offset = 6;
43 if(type == "W") offset = 1;
44 if(type == "S") offset = 2;
45
46 while(getline(file,buf)){
47 if(buf.compare(0,1,region)==0) break;
48 }
49
50 while(getline(file,buf)){
51 if(buf.compare(1,module.size(),module)==0) break;
52 }
53
54 while(getline(file,buf)){
55 if(buf.compare(0,2," ")!=0) break;
56 if(buf.compare(2,1,"0")==0) offset--;
57 if(offset==0){
58 std::istringstream line(buf);
59 std::vector<int> entry;
60 for(int i=0; i<3; i++){
61 int temp=-1;
62 line >> temp;
63 entry.push_back(temp);
64 }
65 m_database.emplace_back(std::move(entry));
66 }
67 }
68
69 file.close();
70}
71
75
76bool TGCDatabasePPToSL::update(const std::vector<int>& input)
77{
78 int ip = find(input);
79 if(ip<0) return false;
80
81 const unsigned int input_size = input.size();
82
83 const unsigned int database_size = m_database[ip].size();
84 for(unsigned int i=1; i<database_size; i++){
85 if(i<input_size){
86 m_database[ip].at(i) = input.at(i);
87 } else {
88 m_database[ip].at(i) = -1;
89 }
90 }
91
92 return true;
93}
94
95int TGCDatabasePPToSL::find(const std::vector<int>& channel) const
96{
97 int index=-1;
98 const unsigned int size = m_database.size();
99 for(unsigned int i=0; i<size; i++){
100 if(m_database[i].at(0) == channel.at(0)){
101 index = i;
102 break;
103 }
104 }
105 return index;
106}
107
108} // end of namespace
TGCDatabasePPToSL(const std::string &filename, const std::string &blockname)
virtual bool update(const std::vector< int > &)
virtual int find(const std::vector< int > &) const
std::vector< std::vector< int > > m_database
Definition TGCDatabase.h:54
TGCDatabase(DatabaseType type=NoDatabaseType)
Definition index.py:1
TFile * file