ATLAS Offline Software
RegionElement.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cstdlib>
8 
10 #include "GaudiKernel/MsgStream.h"
12 #include "sstream"
13 
14 namespace MuonCalib {
15 
16  bool RegionElement::Initialize(const std::string &region) {
17  m_region = region;
18  std::string inner_region(region, 1, region.size() - 2);
19  // clear all - empty means all chambers
20  m_stations.clear();
21  m_eta_start.clear();
22  m_eta_end.clear();
23  m_phi_start.clear();
24  m_phi_end.clear();
25  m_ml = 0;
26  // loop on the four elements of a region element
27  std::istringstream region_stream(inner_region);
28  std::string item;
29  for (int i = 0; i < 4; i++) {
30  getline(region_stream, item, ',');
31  if (region_stream.fail()) break;
32  // split in subelements
33  std::string item2;
34  std::istringstream item_stream(item);
35  while (!item_stream.eof()) {
36  item_stream >> item2;
37  if (item2.size() == 0) continue;
38  switch (i) {
39  case 0:
40  if (!process_station_name(item2)) return false;
41  break;
42  case 1:
43  if (!process_int_range(item2, m_phi_start, m_phi_end)) return false;
44  break;
45  case 2:
46  if (!process_int_range(item2, m_eta_start, m_eta_end)) return false;
47  break;
48  case 3: {
49  m_ml = atoi(item2.c_str());
50  if (m_ml < 0 || m_ml > 2) return false;
51  break;
52  }
53  }
54  }
55  }
56  return true;
57  }
58 
59  void RegionElement::Print(std::ostream &os) const { os << m_region; }
60 
61  bool RegionElement::Result(const MuonFixedId &id) const {
62  // check for station
63  if (m_stations.size() != 0 && m_stations.find(id.stationName()) == m_stations.end()) return false;
64  // check for eta
65  if (m_eta_start.size() > 0) {
66  bool match(false);
67  for (unsigned int i = 0; i < m_eta_start.size(); i++) {
68  if (m_eta_start[i] <= id.eta() && id.eta() <= m_eta_end[i]) {
69  match = true;
70  break;
71  }
72  }
73  if (!match) return false;
74  }
75  // check for phi
76  if (m_phi_start.size() > 0) {
77  bool match(false);
78  for (unsigned int i = 0; i < m_phi_start.size(); i++) {
79  if (m_phi_start[i] <= id.phi() && id.phi() <= m_phi_end[i]) {
80  match = true;
81  break;
82  }
83  }
84  if (!match) return false;
85  }
86  // check for multilayer
87  if (m_ml > 0) {
88  if (id.mdtMultilayer() != m_ml) return false;
89  }
90  return true;
91  }
92 
93  bool RegionElement::process_station_name(std::string &substr) {
94  if (substr.size() > 3) {
95  MsgStream log(Athena::getMessageSvc(), "RegionElement");
96  log << MSG::WARNING << "Syntax Error '" << substr << "'" << endmsg;
97  return false;
98  }
99  std::string name_template("???");
100  for (unsigned int i = 0; i < substr.size(); i++) { name_template[i] = substr[i]; }
101  // get matching stations
102  MuonFixedId id;
103  std::string station_name;
104  for (int i = 1; true; i++) {
105  station_name = id.stationNumberToFixedStationString(i);
106  if (station_name == "XXX") break;
107  bool match(true);
108  for (int j = 0; j < 3; j++) {
109  if (name_template[j] == '?') continue;
110  if (name_template[j] == station_name[j]) continue;
111  match = false;
112  }
113  if (match) { m_stations.insert(i); }
114  }
115  return true;
116  }
117 
118  bool RegionElement::process_int_range(std::string &substr, std::vector<int> &target_start, std::vector<int> &target_end) {
119  // check for - in substring
120  std::string begin_range[2];
121  int n_substrings(0);
122  bool begin_number(true);
123  for (unsigned int i = 0; i < substr.size(); i++) {
124  switch (substr[i]) {
125  case '0':
126  case '1':
127  case '2':
128  case '3':
129  case '4':
130  case '5':
131  case '6':
132  case '7':
133  case '8':
134  case '9':
135  begin_range[n_substrings] += substr[i];
136  begin_number = false;
137  break;
138  case '-':
139  if (begin_number) {
140  begin_range[n_substrings] += substr[i];
141  begin_number = false;
142  break;
143  }
144  if (n_substrings > 0) {
145  MsgStream log(Athena::getMessageSvc(), "RegionElement");
146  log << MSG::WARNING << "Surplus '-' in " << substr << endmsg;
147  return false;
148  }
149  begin_number = true;
150  n_substrings = 1;
151  break;
152  default:
153  MsgStream log(Athena::getMessageSvc(), "RegionElement");
154  log << MSG::WARNING << "Syntax error in " << substr << endmsg;
155  return false;
156  }
157  }
158  if (begin_range[0].size() == 0) { return true; }
159  target_start.push_back(atoi(begin_range[0].c_str()));
160  if (n_substrings == 0)
161  target_end.push_back(atoi(begin_range[0].c_str()));
162  else
163  target_end.push_back(atoi(begin_range[1].c_str()));
164  return true;
165  }
166 } // namespace MuonCalib
MuonCalib::RegionElement::Result
bool Result(const MuonFixedId &region) const
return true if in region
Definition: RegionElement.cxx:61
MuonCalib::RegionElement::Print
void Print(std::ostream &os) const
print region
Definition: RegionElement.cxx:59
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
MuonCalib::RegionElement::m_phi_start
std::vector< int > m_phi_start
Definition: RegionElement.h:38
MuonCalib::RegionElement::Initialize
bool Initialize(const std::string &region)
Initialize functions.
Definition: RegionElement.cxx:16
MuonCalib::RegionElement::m_region
std::string m_region
Definition: RegionElement.h:33
MuonCalib::RegionElement::m_ml
int m_ml
Definition: RegionElement.h:40
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
MuonCalib::RegionElement::m_eta_start
std::vector< int > m_eta_start
Definition: RegionElement.h:36
MuonCalib::RegionElement::m_eta_end
std::vector< int > m_eta_end
Definition: RegionElement.h:37
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::RegionElement::process_int_range
bool process_int_range(std::string &range, std::vector< int > &target_start, std::vector< int > &target_end)
process a numerical id
Definition: RegionElement.cxx:118
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
MuonCalib::RegionElement::process_station_name
bool process_station_name(std::string &name)
process a astation name string
Definition: RegionElement.cxx:93
MuonCalib::RegionElement::m_phi_end
std::vector< int > m_phi_end
Definition: RegionElement.h:39
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
MuonCalib::MuonFixedId
Definition: MuonFixedId.h:50
item
Definition: ItemListSvc.h:43
MuonCalib::RegionElement::m_stations
std::set< int > m_stations
regions
Definition: RegionElement.h:35
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
RegionElement.h
createDCubeDigitHistograms.mdtMultilayer
mdtMultilayer
Definition: createDCubeDigitHistograms.py:112
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
createCablingJSON.station_name
string station_name
Simple script to generate a BIS78 cabling map as used for the Monte Carlo processing.
Definition: createCablingJSON.py:13
MuonFixedId.h
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356