ATLAS Offline Software
Loading...
Searching...
No Matches
TGCDatabaseSLBToROD.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
12TGCDatabaseSLBToROD::TGCDatabaseSLBToROD(const std::string& filename,
13 const std::string& blockname)
14 : TGCDatabase(TGCDatabase::SLBToROD, filename, blockname) {
15 // read out ascii file and fill database
17}
18
20 std::ifstream file(m_filename.c_str());
21 std::string buf;
22
23 unsigned int space = m_blockname.find(' ');
24 std::string_view module = std::string_view(m_blockname).substr(0, space);
25 std::string_view type = std::string_view(m_blockname).substr(space + 1);
26
27 while (getline(file, buf)) {
28 if (buf.compare(0, module.size(), module) == 0) {
29 break;
30 }
31 }
32
33 while (getline(file, buf)) {
34 if (buf.compare(1, type.size(), type) == 0) {
35 break;
36 }
37 }
38
39 while (getline(file, buf)) {
40 if (buf.compare(0, 2, " ") != 0) {
41 break;
42 }
43 std::istringstream line(buf);
44 std::vector<int> entry;
45 for (int i = 0; i < 6; i++) {
46 int temp = -1;
47 line >> temp;
48 entry.push_back(temp);
49 }
50 m_database.emplace_back(std::move(entry));
51 }
52
53 file.close();
54}
55
57
58bool TGCDatabaseSLBToROD::update(const std::vector<int>& input) {
59 int ip = find(input);
60 if (ip < 0) {
61 return false;
62 }
63
64 if (input.size() < 6) {
65 // SSW block
66 m_database[ip].at(1) = input.at(1);
67 } else {
68 // SLB block
69 m_database[ip].at(4) = input.at(4);
70 m_database[ip].at(5) = input.at(5);
71 }
72
73 return true;
74}
75
76int TGCDatabaseSLBToROD::find(const std::vector<int>& channel) const {
77 int index = -1;
78
79 const unsigned int size = m_database.size();
80
81 if (channel.size() < 4) {
82 // SSW block
83 for (unsigned int i = 0; i < size; i++) {
84 if (m_database[i].at(0) == channel.at(0)) {
85 index = i;
86 break;
87 }
88 }
89 } else {
90 // SLB block
91 for (unsigned int i = 0; i < size; i++) {
92 if (m_database[i].at(3) == channel.at(3) &&
93 m_database[i].at(2) == channel.at(2) &&
94 m_database[i].at(1) == channel.at(1) &&
95 m_database[i].at(0) == channel.at(0)) {
96 index = i;
97 break;
98 }
99 }
100 }
101
102 return index;
103}
104
105} // namespace MuonTGC_Cabling
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