ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
SelectionHelpers
SelectionHelpers
SelectionExprParser.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef SELECTION_HELPERS__SELECTION_EXPR_PARSER_H
6
#define SELECTION_HELPERS__SELECTION_EXPR_PARSER_H
7
8
#include <boost/tokenizer.hpp>
9
#include <functional>
10
#include <memory>
11
#include <string>
12
13
#include "
SelectionHelpers/ISelectionReadAccessor.h
"
14
#include "
SelectionHelpers/SelectionHelpers.h
"
15
16
namespace
CP
{
17
18
// Private detail namespace. This is not strictly private to enable testing
19
namespace
DetailSelectionExprParser
{
20
22
class
Separator
{
23
public
:
25
bool
operator()
(std::string::const_iterator &next,
26
const
std::string::const_iterator &end,
27
std::string &tok)
const
;
28
30
void
reset
() {}
31
};
32
33
// Typedef over boost's tokenizer using the above Separator
34
typedef
boost::tokenizer<Separator>
Tokenizer
;
35
38
class
Lexer
{
39
public
:
41
Lexer
(
const
std::string &s);
42
44
Lexer
(
const
Lexer
&) =
delete
;
46
Lexer
(
Lexer
&&) =
default
;
47
50
enum
Type
{
51
AND
= 0,
52
OR
,
53
LEFT
,
54
RIGHT
,
55
NOT
,
56
TRUE_LITERAL
,
57
FALSE_LITERAL
,
58
VAR
,
59
END
60
};
61
64
struct
Symbol
{
65
Type
type
{};
66
std::string
value
;
67
};
68
70
Symbol
nextSymbol
();
71
72
private
:
73
std::string
m_string
;
74
Tokenizer
m_tokenizer
;
75
Tokenizer::iterator
m_iterator
;
76
};
77
}
// namespace DetailSelectionExprParser
78
80
class
SelectionExprParser
{
81
public
:
86
SelectionExprParser
(
DetailSelectionExprParser::Lexer
lexer,
87
bool
defaultToChar =
false
);
88
92
StatusCode
build
(std::unique_ptr<ISelectionReadAccessor> &accessor);
93
94
private
:
95
// Construct a binary OR
96
StatusCode
expression
(std::unique_ptr<ISelectionReadAccessor> &root);
97
// Construct an AND, attempts to group all ANDs it can see into a list
98
StatusCode
term
(std::unique_ptr<ISelectionReadAccessor> &root);
99
// Handle other constructs, potentially more ORs or ANDs.
100
StatusCode
factor
(std::unique_ptr<ISelectionReadAccessor> &root);
101
102
// The lexer to generate symbols from.
103
DetailSelectionExprParser::Lexer
m_lexer
;
104
// The last extracted symbol
105
DetailSelectionExprParser::Lexer::Symbol
m_symbol
{};
106
// Stores constructor parameter to be used in calls to makeSelectionAccessorVar.
107
bool
m_defaultToChar
{};
108
};
109
110
}
// namespace CP
111
112
#endif
ISelectionReadAccessor.h
SelectionHelpers.h
CP::DetailSelectionExprParser::Lexer
Lexer which turns a token stream into a stream of unambigous symbols to be used by a parser.
Definition
SelectionExprParser.h:38
CP::DetailSelectionExprParser::Lexer::Type
Type
Enum over the possible symbols that can be extracted from the token stream.
Definition
SelectionExprParser.h:50
CP::DetailSelectionExprParser::Lexer::RIGHT
@ RIGHT
Definition
SelectionExprParser.h:54
CP::DetailSelectionExprParser::Lexer::FALSE_LITERAL
@ FALSE_LITERAL
Definition
SelectionExprParser.h:57
CP::DetailSelectionExprParser::Lexer::AND
@ AND
Definition
SelectionExprParser.h:51
CP::DetailSelectionExprParser::Lexer::VAR
@ VAR
Definition
SelectionExprParser.h:58
CP::DetailSelectionExprParser::Lexer::LEFT
@ LEFT
Definition
SelectionExprParser.h:53
CP::DetailSelectionExprParser::Lexer::NOT
@ NOT
Definition
SelectionExprParser.h:55
CP::DetailSelectionExprParser::Lexer::TRUE_LITERAL
@ TRUE_LITERAL
Definition
SelectionExprParser.h:56
CP::DetailSelectionExprParser::Lexer::OR
@ OR
Definition
SelectionExprParser.h:52
CP::DetailSelectionExprParser::Lexer::END
@ END
Definition
SelectionExprParser.h:59
CP::DetailSelectionExprParser::Lexer::m_tokenizer
Tokenizer m_tokenizer
Definition
SelectionExprParser.h:74
CP::DetailSelectionExprParser::Lexer::Lexer
Lexer(const std::string &s)
Constructor from a strig.
Definition
SelectionExprParser.cxx:48
CP::DetailSelectionExprParser::Lexer::nextSymbol
Symbol nextSymbol()
Generate a new symbol from the token sequence.
Definition
SelectionExprParser.cxx:52
CP::DetailSelectionExprParser::Lexer::m_string
std::string m_string
Definition
SelectionExprParser.h:73
CP::DetailSelectionExprParser::Lexer::m_iterator
Tokenizer::iterator m_iterator
Definition
SelectionExprParser.h:75
CP::DetailSelectionExprParser::Lexer::Lexer
Lexer(Lexer &&)=default
Default move-constructor behaviour.
CP::DetailSelectionExprParser::Lexer::Lexer
Lexer(const Lexer &)=delete
Disable copying of this class.
CP::DetailSelectionExprParser::Separator
Separator to be used in a boost::tokenizer.
Definition
SelectionExprParser.h:22
CP::DetailSelectionExprParser::Separator::operator()
bool operator()(std::string::const_iterator &next, const std::string::const_iterator &end, std::string &tok) const
Extracts the subsequent token from the input string iterator.
Definition
SelectionExprParser.cxx:21
CP::DetailSelectionExprParser::Separator::reset
void reset()
Optional state reset method, does nothing.
Definition
SelectionExprParser.h:30
CP::SelectionExprParser::term
StatusCode term(std::unique_ptr< ISelectionReadAccessor > &root)
Definition
SelectionExprParser.cxx:120
CP::SelectionExprParser::SelectionExprParser
SelectionExprParser(DetailSelectionExprParser::Lexer lexer, bool defaultToChar=false)
Constructor for the parser which accepts a Lecer.
Definition
SelectionExprParser.cxx:90
CP::SelectionExprParser::m_lexer
DetailSelectionExprParser::Lexer m_lexer
Definition
SelectionExprParser.h:103
CP::SelectionExprParser::m_symbol
DetailSelectionExprParser::Lexer::Symbol m_symbol
Definition
SelectionExprParser.h:105
CP::SelectionExprParser::factor
StatusCode factor(std::unique_ptr< ISelectionReadAccessor > &root)
Definition
SelectionExprParser.cxx:139
CP::SelectionExprParser::expression
StatusCode expression(std::unique_ptr< ISelectionReadAccessor > &root)
Definition
SelectionExprParser.cxx:107
CP::SelectionExprParser::m_defaultToChar
bool m_defaultToChar
Definition
SelectionExprParser.h:107
CP::SelectionExprParser::build
StatusCode build(std::unique_ptr< ISelectionReadAccessor > &accessor)
Triggers the actual parsing of the expression.
Definition
SelectionExprParser.cxx:93
CP::DetailSelectionExprParser
Definition
SelectionExprParser.cxx:20
CP::DetailSelectionExprParser::Tokenizer
boost::tokenizer< Separator > Tokenizer
Definition
SelectionExprParser.h:34
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
CP::DetailSelectionExprParser::Lexer::Symbol
Struct grouping together the type and original string representation of a symbol.
Definition
SelectionExprParser.h:64
CP::DetailSelectionExprParser::Lexer::Symbol::value
std::string value
Definition
SelectionExprParser.h:66
CP::DetailSelectionExprParser::Lexer::Symbol::type
Type type
Definition
SelectionExprParser.h:65
Generated on
for ATLAS Offline Software by
1.17.0