ATLAS Offline Software
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"
9 #include "MuonGeoModel/MYSQL.h"
10 #include "MuonGeoModel/Station.h"
11 
12 #include <fstream>
13 #include <sstream>
14 #include <utility>
15 
16 namespace 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
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonGM::StationSelector::m_selector
std::vector< std::string > m_selector
Definition: StationSelector.h:28
MuonGM::StationSelector::m_theMap
StationMap m_theMap
Definition: StationSelector.h:29
skel.it
it
Definition: skel.GENtoEVGEN.py:396
MuonGM::MYSQL
Definition: MYSQL.h:43
MuonGM::StationSelector::SetSelectionType
static void SetSelectionType(int t)
Definition: StationSelector.cxx:104
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
MuonGM::StationSelector::m_selectType
static std::atomic< int > m_selectType
Definition: StationSelector.h:31
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonGM::StationSelector::select
bool select(const std::string &name)
Definition: StationSelector.cxx:48
MuonGM::StationSelector::StationSelector
StationSelector(const MYSQL &mysql, const std::string &filename)
Definition: StationSelector.cxx:20
Station.h
StationSelector.h
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
sel
sel
Definition: SUSYToolsTester.cxx:97
MYSQL.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MuonGM::StationSelector::end
StationIterator end()
Definition: StationSelector.cxx:46
MuonGM::StationSelector::StationIterator
StationMap::const_iterator StationIterator
Definition: StationSelector.h:20
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
MuonGM::StationSelector::begin
StationIterator begin()
Definition: StationSelector.cxx:45
MuonGM::MYSQL::stationMap
const StationMap & stationMap() const
Definition: MYSQL.cxx:227
fitman.k
k
Definition: fitman.py:528
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37