ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
MuonCalib::RegionElement Class Reference

#include <RegionElement.h>

Inheritance diagram for MuonCalib::RegionElement:
Collaboration diagram for MuonCalib::RegionElement:

Public Member Functions

 RegionElement ()=default
 constructor More...
 
 RegionElement (const std::string &region)
 
 ~RegionElement ()=default
 
bool Initialize (const std::string &region)
 Initialize functions. More...
 
bool Result (const MuonFixedId &region) const
 return true if in region More...
 
void Print (std::ostream &os) const
 print region More...
 

Static Public Member Functions

static std::unique_ptr< RegionSelectorBaseGetRegion (const std::string &input)
 create a region from a string More...
 

Private Member Functions

bool process_station_name (std::string &name)
 process a astation name string More...
 
bool process_int_range (std::string &range, std::vector< int > &target_start, std::vector< int > &target_end)
 process a numerical id More...
 

Static Private Member Functions

static std::unique_ptr< RegionSelectorBaseprocess_region (const std::string &input, unsigned int &i, bool is_in_braces)
 
static void print_position (const std::string &input, const unsigned int &position, MsgStream *msgStr)
 

Private Attributes

std::string m_region
 
std::set< int > m_stations
 regions More...
 
std::vector< int > m_eta_start
 
std::vector< int > m_eta_end
 
std::vector< int > m_phi_start
 
std::vector< int > m_phi_end
 
int m_ml {-1}
 

Detailed Description

Definition at line 19 of file RegionElement.h.

Constructor & Destructor Documentation

◆ RegionElement() [1/2]

MuonCalib::RegionElement::RegionElement ( )
default

constructor

◆ RegionElement() [2/2]

MuonCalib::RegionElement::RegionElement ( const std::string &  region)
inline

Definition at line 23 of file RegionElement.h.

23 : RegionSelectorBase(), m_region(region) {}

◆ ~RegionElement()

MuonCalib::RegionElement::~RegionElement ( )
default

Member Function Documentation

◆ GetRegion()

std::unique_ptr< RegionSelectorBase > MuonCalib::RegionSelectorBase::GetRegion ( const std::string &  input)
staticinherited

create a region from a string

Definition at line 13 of file RegionSelectorBase.cxx.

13  {
14  unsigned int i(0);
15  return process_region(input, i, false);
16  }

◆ Initialize()

bool MuonCalib::RegionElement::Initialize ( const std::string &  region)

Initialize functions.

Definition at line 16 of file RegionElement.cxx.

16  {
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  }

◆ Print()

void MuonCalib::RegionElement::Print ( std::ostream &  os) const
virtual

print region

Implements MuonCalib::RegionSelectorBase.

Definition at line 59 of file RegionElement.cxx.

59 { os << m_region; }

◆ print_position()

void MuonCalib::RegionSelectorBase::print_position ( const std::string &  input,
const unsigned int &  position,
MsgStream *  msgStr 
)
staticprivateinherited

Definition at line 133 of file RegionSelectorBase.cxx.

133  {
134  unsigned int i(0);
135  std::string st1, st2;
136  for (; i < input.size() && i < position; i++) { st1 += input[i]; }
137  for (; i < input.size(); i++) { st2 += input[i]; }
138  *msgStr << MSG::WARNING << st1 << "*" << st2 << endmsg;
139  }

◆ process_int_range()

bool MuonCalib::RegionElement::process_int_range ( std::string &  range,
std::vector< int > &  target_start,
std::vector< int > &  target_end 
)
private

process a numerical id

Definition at line 118 of file RegionElement.cxx.

118  {
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  }

◆ process_region()

std::unique_ptr< RegionSelectorBase > MuonCalib::RegionSelectorBase::process_region ( const std::string &  input,
unsigned int &  i,
bool  is_in_braces 
)
staticprivateinherited

Definition at line 18 of file RegionSelectorBase.cxx.

18  {
19  unsigned int start_sub(i);
20  // create master region as logical operation
21  std::unique_ptr<RegionLogicalOperation> new_region = std::make_unique<RegionLogicalOperation>();
22  bool currect_inverse(false);
23  MsgStream log(Athena::getMessageSvc(), "RegionSelectorBase");
24  // loop over characters
25  for (; i < input.size(); i++) {
26  int start_element(i);
27  switch (input[i]) {
28  // read elementary region
29  case '[': {
30  std::string element;
31  int start_element(i);
32  for (; i < input.size(); i++) {
33  element.push_back(input[i]);
34  if (input[i] == ']') break;
35  }
36  if (i == input.size()) {
37  log << MSG::WARNING << "Missing ']' at end of input! Started here:" << endmsg;
38  print_position(input, start_element, &log);
39  return nullptr;
40  }
41  std::unique_ptr<RegionElement> reg_el = std::make_unique<RegionElement>();
42  // syntax error in region
43  if (!reg_el->Initialize(element)) {
44  print_position(input, start_element, &log);
45  return nullptr;
46  }
47  // add region to operation
48  if (!new_region->AddRegion(std::move(reg_el), currect_inverse)) {
49  log << MSG::WARNING << "Missing operator!" << endmsg;
50  print_position(input, start_element, &log);
51  return nullptr;
52  }
53  currect_inverse = false;
54  break;
55  }
56  // new substring - start recursive processing
57  case '(': {
58  i++;
59  if (i >= input.size()) {
60  log << MSG::WARNING << "'(' at end of input!" << endmsg;
61  print_position(input, start_element, &log);
62  return nullptr;
63  }
64  std::unique_ptr<RegionSelectorBase> second_region{process_region(input, i, true)};
65  if (!second_region) { return nullptr; }
66  if (!new_region->AddRegion(std::move(second_region), currect_inverse)) {
67  log << MSG::WARNING << "Missing operator!" << endmsg;
68  print_position(input, start_element, &log);
69  return nullptr;
70  }
71  currect_inverse = false;
72  break;
73  }
74  // invert the following region
75  case '!': {
76  if (currect_inverse) {
77  log << MSG::WARNING << "Surplus '!'" << endmsg;
78  print_position(input, start_element, &log);
79  return nullptr;
80  }
81  currect_inverse = true;
82  break;
83  }
84  // operator
85  case '&':
86  case '|': {
87  bool next_op(input[i] == '|');
88  if (!new_region->AddOperator(next_op)) {
89  log << MSG::WARNING << "Unexpected operator!" << endmsg;
90  print_position(input, start_element, &log);
91  return nullptr;
92  }
93  break;
94  }
95  // end of current subregion
96  case ')': {
97  if (new_region->SurplusOperator()) {
98  log << MSG::WARNING << "Surplus operator" << endmsg;
99  print_position(input, start_element, &log);
100  return nullptr;
101  }
102  if (is_in_braces) { return new_region; }
103  log << MSG::WARNING << "Unexpected ')'" << endmsg;
104  print_position(input, start_element, &log);
105  return nullptr;
106  }
107  // ignore whitespaces
108  case ' ':
109  case '\t':
110  case '\n':
111  break;
112  // any other characters are junk at this point
113  default:
114  log << MSG::WARNING << "Syntax Error" << endmsg;
115  print_position(input, start_element, &log);
116  return nullptr;
117  }
118  }
119  // if we ar ein a subregion and reached the end of input there is an error
120  if (is_in_braces) {
121  log << MSG::WARNING << "Missing ')'" << endmsg;
122  print_position(input, start_sub, &log);
123  return nullptr;
124  }
125  if (new_region->SurplusOperator()) {
126  log << MSG::WARNING << "Surplus operator" << endmsg;
128  return nullptr;
129  }
130  return new_region;
131  }

◆ process_station_name()

bool MuonCalib::RegionElement::process_station_name ( std::string &  name)
private

process a astation name string

Definition at line 93 of file RegionElement.cxx.

93  {
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  }

◆ Result()

bool MuonCalib::RegionElement::Result ( const MuonFixedId region) const
virtual

return true if in region

Implements MuonCalib::RegionSelectorBase.

Definition at line 61 of file RegionElement.cxx.

61  {
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  }

Member Data Documentation

◆ m_eta_end

std::vector<int> MuonCalib::RegionElement::m_eta_end
private

Definition at line 37 of file RegionElement.h.

◆ m_eta_start

std::vector<int> MuonCalib::RegionElement::m_eta_start
private

Definition at line 36 of file RegionElement.h.

◆ m_ml

int MuonCalib::RegionElement::m_ml {-1}
private

Definition at line 40 of file RegionElement.h.

◆ m_phi_end

std::vector<int> MuonCalib::RegionElement::m_phi_end
private

Definition at line 39 of file RegionElement.h.

◆ m_phi_start

std::vector<int> MuonCalib::RegionElement::m_phi_start
private

Definition at line 38 of file RegionElement.h.

◆ m_region

std::string MuonCalib::RegionElement::m_region
private

Definition at line 33 of file RegionElement.h.

◆ m_stations

std::set<int> MuonCalib::RegionElement::m_stations
private

regions

Definition at line 35 of file RegionElement.h.


The documentation for this class was generated from the following files:
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
MuonCalib::RegionElement::m_phi_start
std::vector< int > m_phi_start
Definition: RegionElement.h:38
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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::RegionSelectorBase::print_position
static void print_position(const std::string &input, const unsigned int &position, MsgStream *msgStr)
Definition: RegionSelectorBase.cxx:133
MuonCalib::RegionElement::m_eta_start
std::vector< int > m_eta_start
Definition: RegionElement.h:36
MuonCalib::RegionSelectorBase::process_region
static std::unique_ptr< RegionSelectorBase > process_region(const std::string &input, unsigned int &i, bool is_in_braces)
Definition: RegionSelectorBase.cxx:18
MuonCalib::RegionElement::m_eta_end
std::vector< int > m_eta_end
Definition: RegionElement.h:37
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
createCablingJSON.station_name
int station_name
Simple script to generate a BIS78 cabling map as used for the Monte Carlo processing.
Definition: createCablingJSON.py:8
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
MuonCalib::RegionSelectorBase::RegionSelectorBase
RegionSelectorBase()=default
Constructor.
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:194
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
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
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356