ATLAS Offline Software
Loading...
Searching...
No Matches
StationSelector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include "GaudiKernel/MsgStream.h"
11
12#include <fstream>
13#include <sstream>
14#include <utility>
15
16namespace MuonGM {
17
18 std::atomic<int> StationSelector::m_selectType = 0;
19
20 StationSelector::StationSelector(const MYSQL& mysql, const std::string& filename) {
21 std::ifstream from;
22 from.open(filename.c_str());
23 char buffer[200];
24 while (from.getline(buffer, 200)) {
25 std::istringstream line(buffer);
26 std::string key;
27 line >> key;
28 m_selector.push_back(key);
29 }
30
31 for (const auto& [name, station] : mysql.stationMap()) {
32 if (select(name))
33 m_theMap[name] = station.get();
34 }
35 }
36
37 StationSelector::StationSelector(const MYSQL& mysql, std::vector<std::string> s) : m_selector(std::move(s)) {
39 for (const auto& [name, station] : mysql.stationMap()) {
40 if (select(name))
41 m_theMap[name] = station.get();
42 }
43 }
44
47
48 bool StationSelector::select(const std::string& name ) {
49 MsgStream log(Athena::getMessageSvc(), "MuonGeoModel");
50 int selFlag = m_selectType;
51 if (m_selector[0] == "*") {
52 selFlag = 1; // override JO choice for general configuration
53 }
54
55 if (selFlag == 1) {
56 for (unsigned int k = 0; k < m_selector.size(); k++) {
57 std::string sel = m_selector[k];
58
59 if (sel.size() <= name.size()) {
60 bool myflag = true;
61 for (unsigned int i = 0; i < sel.size(); i++) {
62 if (sel[i] == '*')
63 continue;
64 if (sel[i] != name[i]) {
65 myflag = false;
66 break;
67 }
68 }
69
70 if (myflag)
71 return myflag;
72 }
73 }
74 return false;
75 } else if (selFlag == 2) {
76 for (unsigned int k = 0; k < m_selector.size(); k++) {
77 std::string sel = m_selector[k];
78
79 if (sel.size() != name.size())
80 continue; // require exact match
81
82 bool myflag = true;
83 for (unsigned int i = 0; i < sel.size(); i++) {
84 if (sel[i] == '*')
85 continue;
86 if (sel[i] != name[i]) {
87 myflag = false;
88 break;
89 }
90 }
91
92 if (myflag) {
93 log << MSG::INFO << " StationSelector: removing station " << name << endmsg;
94 return false;
95 }
96 }
97
98 return true;
99 }
100
101 return true;
102 }
103
105
106} // namespace MuonGM
#define endmsg
const StationMap & stationMap() const
Definition MYSQL.cxx:227
static std::atomic< int > m_selectType
std::vector< std::string > m_selector
bool select(const std::string &name)
static void SetSelectionType(int t)
StationMap::const_iterator StationIterator
StationSelector(const MYSQL &mysql, const std::string &filename)
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
Ensure that the Athena extensions are properly loaded.
Definition GeoMuonHits.h:27
STL namespace.