ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CP::SelectionExprParser Class Reference

Public interface for the expression parsing facility. More...

#include <SelectionExprParser.h>

Collaboration diagram for CP::SelectionExprParser:

Public Member Functions

 SelectionExprParser (DetailSelectionExprParser::Lexer lexer, bool defaultToChar=false)
 Constructor for the parser which accepts a Lecer. More...
 
StatusCode build (std::unique_ptr< ISelectionReadAccessor > &accessor)
 Triggers the actual parsing of the expression. More...
 

Private Member Functions

StatusCode expression (std::unique_ptr< ISelectionReadAccessor > &root)
 
StatusCode term (std::unique_ptr< ISelectionReadAccessor > &root)
 
StatusCode factor (std::unique_ptr< ISelectionReadAccessor > &root)
 

Private Attributes

DetailSelectionExprParser::Lexer m_lexer
 
DetailSelectionExprParser::Lexer::Symbol m_symbol
 
bool m_defaultToChar
 

Detailed Description

Public interface for the expression parsing facility.

Definition at line 80 of file SelectionExprParser.h.

Constructor & Destructor Documentation

◆ SelectionExprParser()

CP::SelectionExprParser::SelectionExprParser ( DetailSelectionExprParser::Lexer  lexer,
bool  defaultToChar = false 
)

Constructor for the parser which accepts a Lecer.

Parameters
lexerThe lexer to use for parsing
Note
Lexer can be auto-constructed from a string, so you can pass one directly.
Parameters
defaultToCharAssume "as_char" as default encoding

Definition at line 90 of file SelectionExprParser.cxx.

91  : m_lexer(std::move(lexer)), m_defaultToChar(defaultToChar) {}

Member Function Documentation

◆ build()

StatusCode CP::SelectionExprParser::build ( std::unique_ptr< ISelectionReadAccessor > &  accessor)

Triggers the actual parsing of the expression.

Parameters
[out]accessorUnique pointer the resulting accessor will be written to.
Returns
StatusCode noting whether the operation succeeded.

Definition at line 93 of file SelectionExprParser.cxx.

94  {
95  std::unique_ptr<ISelectionReadAccessor> root{nullptr};
97 
98  if (m_symbol.type != Lexer::END) {
99  throw std::runtime_error(
100  "Not all symbols in expression were consumed. Check your expression.");
101  }
102 
103  accessor = std::move(root);
104  return StatusCode::SUCCESS;
105 }

◆ expression()

StatusCode CP::SelectionExprParser::expression ( std::unique_ptr< ISelectionReadAccessor > &  root)
private

Definition at line 107 of file SelectionExprParser.cxx.

108  {
109  ANA_CHECK(term(root));
110  while (m_symbol.type == Lexer::OR) {
111  std::unique_ptr<ISelectionReadAccessor> left = std::move(root);
112  ANA_CHECK(term(root));
113  std::unique_ptr<ISelectionReadAccessor> right = std::move(root);
114  root = std::make_unique<SelectionAccessorExprOr>(std::move(left),
115  std::move(right));
116  }
117  return StatusCode::SUCCESS;
118 }

◆ factor()

StatusCode CP::SelectionExprParser::factor ( std::unique_ptr< ISelectionReadAccessor > &  root)
private

Definition at line 139 of file SelectionExprParser.cxx.

140  {
142  if (m_symbol.type == Lexer::TRUE_LITERAL) {
143  root = std::make_unique<SelectionReadAccessorNull>(true);
145  } else if (m_symbol.type == Lexer::FALSE_LITERAL) {
146  root = std::make_unique<SelectionReadAccessorNull>(false);
148  } else if (m_symbol.type == Lexer::NOT) {
150  std::unique_ptr<ISelectionReadAccessor> notEx =
151  std::make_unique<SelectionAccessorExprNot>(std::move(root));
152  root = std::move(notEx);
153  } else if (m_symbol.type == Lexer::LEFT) {
155  if (m_symbol.type != Lexer::RIGHT) {
156  throw std::runtime_error(
157  "Missing closing bracket, check your expression.");
158  }
160 
161  } else if (m_symbol.type == Lexer::VAR) {
164  } else {
165  throw std::runtime_error("Malformed expression.");
166  }
167 
168  return StatusCode::SUCCESS;
169 }

◆ term()

StatusCode CP::SelectionExprParser::term ( std::unique_ptr< ISelectionReadAccessor > &  root)
private

Definition at line 120 of file SelectionExprParser.cxx.

121  {
123  std::vector<std::unique_ptr<ISelectionReadAccessor>> factors;
124  factors.push_back(std::move(root));
125 
126  while (m_symbol.type == Lexer::AND) {
128  factors.push_back(std::move(root));
129  }
130 
131  if (factors.size() == 1) {
132  root = std::move(factors[0]);
133  } else {
134  root = std::make_unique<SelectionAccessorList>(std::move(factors));
135  }
136  return StatusCode::SUCCESS;
137 }

Member Data Documentation

◆ m_defaultToChar

bool CP::SelectionExprParser::m_defaultToChar
private

Definition at line 107 of file SelectionExprParser.h.

◆ m_lexer

DetailSelectionExprParser::Lexer CP::SelectionExprParser::m_lexer
private

Definition at line 103 of file SelectionExprParser.h.

◆ m_symbol

DetailSelectionExprParser::Lexer::Symbol CP::SelectionExprParser::m_symbol
private

Definition at line 105 of file SelectionExprParser.h.


The documentation for this class was generated from the following files:
Root::AND
@ AND
Definition: TGRLCollection.h:32
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
CP::SelectionExprParser::term
StatusCode term(std::unique_ptr< ISelectionReadAccessor > &root)
Definition: SelectionExprParser.cxx:120
CP::SelectionExprParser::expression
StatusCode expression(std::unique_ptr< ISelectionReadAccessor > &root)
Definition: SelectionExprParser.cxx:107
Trk::RIGHT
@ RIGHT
the drift radius is positive (see Trk::AtaStraightLine)
Definition: DriftCircleSide.h:22
internal_poltrig::END
@ END
Definition: PolygonTriangulator.cxx:112
CP::DetailSelectionExprParser::Lexer::nextSymbol
Symbol nextSymbol()
Generate a new symbol from the token sequence.
Definition: SelectionExprParser.cxx:52
CP::DetailSelectionExprParser::Lexer::Symbol::value
std::string value
Definition: SelectionExprParser.h:66
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
CP::SelectionExprParser::m_lexer
DetailSelectionExprParser::Lexer m_lexer
Definition: SelectionExprParser.h:103
CP::makeSelectionReadAccessorVar
StatusCode makeSelectionReadAccessorVar(const std::string &name, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
Produces a simple ISelectionReadAccessor accessing the given decoration.
Definition: ISelectionAccessor.cxx:139
CP::DetailSelectionExprParser::Lexer::Symbol::type
Type type
Definition: SelectionExprParser.h:65
CP::SelectionExprParser::factor
StatusCode factor(std::unique_ptr< ISelectionReadAccessor > &root)
Definition: SelectionExprParser.cxx:139
Root::OR
@ OR
Definition: TGRLCollection.h:32
CP::SelectionExprParser::m_symbol
DetailSelectionExprParser::Lexer::Symbol m_symbol
Definition: SelectionExprParser.h:105
Trk::LEFT
@ LEFT
the drift radius is negative (see Trk::AtaStraightLine)
Definition: DriftCircleSide.h:20
CP::SelectionExprParser::m_defaultToChar
bool m_defaultToChar
Definition: SelectionExprParser.h:107