ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCalib::RegionLogicalOperation Class Reference

#include <RegionLogicalOperation.h>

Inheritance diagram for MuonCalib::RegionLogicalOperation:
Collaboration diagram for MuonCalib::RegionLogicalOperation:

Public Member Functions

 RegionLogicalOperation ()=default
 Constructor.
virtual ~RegionLogicalOperation ()=default
 Destructor.
bool AddRegion (std::unique_ptr< RegionSelectorBase > region, bool invert=false)
 Add a region to the operation.
bool AddOperator (bool op)
 Set next operator.
bool SurplusOperator () const
 check for surplus operators
bool Result (const MuonFixedId &region) const
 return the reslut of the logical operation
void Print (std::ostream &os) const
 character output of region

Static Public Member Functions

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

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::vector< std::unique_ptr< RegionSelectorBase > > m_regions
 region data
std::vector< bool > m_operator
 region operator - true=or false=and
std::vector< bool > m_inverse
 inverse region selection

Detailed Description

Definition at line 17 of file RegionLogicalOperation.h.

Constructor & Destructor Documentation

◆ RegionLogicalOperation()

MuonCalib::RegionLogicalOperation::RegionLogicalOperation ( )
default

Constructor.

◆ ~RegionLogicalOperation()

virtual MuonCalib::RegionLogicalOperation::~RegionLogicalOperation ( )
virtualdefault

Destructor.

Member Function Documentation

◆ AddOperator()

bool MuonCalib::RegionLogicalOperation::AddOperator ( bool op)

Set next operator.

Parameters
optrue=or false=and return false if number of operators is too high

Definition at line 20 of file RegionLogicalOperation.cxx.

20 {
21 if ((m_regions.size() <= m_operator.size())) return false;
22 m_operator.push_back(op);
23 return true;
24 }
std::vector< bool > m_operator
region operator - true=or false=and
std::vector< std::unique_ptr< RegionSelectorBase > > m_regions
region data

◆ AddRegion()

bool MuonCalib::RegionLogicalOperation::AddRegion ( std::unique_ptr< RegionSelectorBase > region,
bool invert = false )

Add a region to the operation.

Parameters
regionthe region to be added
invertinverted logic for this region Returns false when number of operators is insufficient

Definition at line 13 of file RegionLogicalOperation.cxx.

13 {
14 if (m_regions.size() > m_operator.size()) return false;
15 m_regions.emplace_back(std::move(region));
16 m_inverse.push_back(invert);
17 return true;
18 }
std::vector< bool > m_inverse
inverse region selection

◆ 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 }
static std::unique_ptr< RegionSelectorBase > process_region(const std::string &input, unsigned int &i, bool is_in_braces)

◆ Print()

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

character output of region

Implements MuonCalib::RegionSelectorBase.

Definition at line 40 of file RegionLogicalOperation.cxx.

40 {
41 os << "(";
42 for (unsigned int i = 0; i < m_regions.size(); i++) {
43 if (m_inverse[i]) os << "!";
44 m_regions[i]->Print(os);
45 if (i < m_operator.size()) {
46 if (m_operator[i])
47 os << " | ";
48 else
49 os << " & ";
50 }
51 }
52 os << ")";
53 }

◆ 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 }
#define endmsg

◆ 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;
127 print_position(input, i, &log);
128 return nullptr;
129 }
130 return new_region;
131 }
static void print_position(const std::string &input, const unsigned int &position, MsgStream *msgStr)
IMessageSvc * getMessageSvc(bool quiet=false)

◆ Result()

bool MuonCalib::RegionLogicalOperation::Result ( const MuonFixedId & region) const
virtual

return the reslut of the logical operation

Implements MuonCalib::RegionSelectorBase.

Definition at line 26 of file RegionLogicalOperation.cxx.

26 {
27 if (m_regions.size() == 0) return true;
28 bool ret(m_inverse[0] xor m_regions[0]->Result(id));
29 for (unsigned int i = 0; i < m_operator.size(); i++) {
30 bool this_region_result(m_inverse[i + 1] xor m_regions[i + 1]->Result(id));
31 if (m_operator[i]) {
32 ret = ret || this_region_result;
33 } else {
34 ret = ret && this_region_result;
35 }
36 }
37 return ret;
38 }
ICscStripFitter::Result Result

◆ SurplusOperator()

bool MuonCalib::RegionLogicalOperation::SurplusOperator ( ) const
inline

check for surplus operators

Definition at line 35 of file RegionLogicalOperation.h.

35 {
36 if (m_operator.size() > m_regions.size() - 1) return true;
37 return false;
38 }

Member Data Documentation

◆ m_inverse

std::vector<bool> MuonCalib::RegionLogicalOperation::m_inverse
private

inverse region selection

Definition at line 49 of file RegionLogicalOperation.h.

◆ m_operator

std::vector<bool> MuonCalib::RegionLogicalOperation::m_operator
private

region operator - true=or false=and

Definition at line 47 of file RegionLogicalOperation.h.

◆ m_regions

std::vector<std::unique_ptr<RegionSelectorBase> > MuonCalib::RegionLogicalOperation::m_regions
private

region data

Definition at line 45 of file RegionLogicalOperation.h.


The documentation for this class was generated from the following files: