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