ATLAS Offline Software
SelectionExprParser.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 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 
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,
55  NOT,
58  VAR,
59  END
60  };
61 
64  struct Symbol {
66  std::string value;
67  };
68 
71 
72  private:
73  std::string m_string;
76 };
77 } // namespace DetailSelectionExprParser
78 
81  public:
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.
104  // The last extracted symbol
106  // Stores constructor parameter to be used in calls to makeSelectionAccessorVar.
108 };
109 
110 } // namespace CP
111 
112 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
CP::SelectionExprParser
Public interface for the expression parsing facility.
Definition: SelectionExprParser.h:80
CP::DetailSelectionExprParser::Lexer::Lexer
Lexer(Lexer &&)=default
Default move-constructor behaviour.
CP::SelectionExprParser::SelectionExprParser
SelectionExprParser(DetailSelectionExprParser::Lexer lexer, bool defaultToChar=false)
Constructor for the parser which accepts a Lecer.
Definition: SelectionExprParser.cxx:90
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::Separator
Separator to be used in a boost::tokenizer.
Definition: SelectionExprParser.h:22
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
CP::DetailSelectionExprParser::Lexer::m_string
std::string m_string
Definition: SelectionExprParser.h:73
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::DetailSelectionExprParser::Lexer::NOT
@ NOT
Definition: SelectionExprParser.h:55
CP::DetailSelectionExprParser::Lexer::OR
@ OR
Definition: SelectionExprParser.h:52
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
CP::SelectionExprParser::term
StatusCode term(std::unique_ptr< ISelectionReadAccessor > &root)
Definition: SelectionExprParser.cxx:120
CP::DetailSelectionExprParser::Lexer::Symbol
Struct grouping together the type and original string representation of a symbol.
Definition: SelectionExprParser.h:64
CP::DetailSelectionExprParser::Lexer::m_tokenizer
Tokenizer m_tokenizer
Definition: SelectionExprParser.h:74
CP::DetailSelectionExprParser::Lexer::m_iterator
Tokenizer::iterator m_iterator
Definition: SelectionExprParser.h:75
CP::DetailSelectionExprParser::Lexer::RIGHT
@ RIGHT
Definition: SelectionExprParser.h:54
CP::SelectionExprParser::expression
StatusCode expression(std::unique_ptr< ISelectionReadAccessor > &root)
Definition: SelectionExprParser.cxx:107
CP::DetailSelectionExprParser::Lexer::FALSE_LITERAL
@ FALSE_LITERAL
Definition: SelectionExprParser.h:57
CP::DetailSelectionExprParser::Lexer::AND
@ AND
Definition: SelectionExprParser.h:51
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
CP::DetailSelectionExprParser::Tokenizer
boost::tokenizer< Separator > Tokenizer
Definition: SelectionExprParser.h:34
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAODType
Definition: ObjectType.h:13
CP::DetailSelectionExprParser::Lexer::TRUE_LITERAL
@ TRUE_LITERAL
Definition: SelectionExprParser.h:56
CP::DetailSelectionExprParser::Separator::reset
void reset()
Optional state reset method, does nothing.
Definition: SelectionExprParser.h:30
CP::DetailSelectionExprParser::Lexer::LEFT
@ LEFT
Definition: SelectionExprParser.h:53
CP::DetailSelectionExprParser::Lexer::VAR
@ VAR
Definition: SelectionExprParser.h:58
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::DetailSelectionExprParser::Lexer::Symbol::type
Type type
Definition: SelectionExprParser.h:65
CP::SelectionExprParser::build
StatusCode build(std::unique_ptr< ISelectionReadAccessor > &accessor)
Triggers the actual parsing of the expression.
Definition: SelectionExprParser.cxx:93
CP::SelectionExprParser::factor
StatusCode factor(std::unique_ptr< ISelectionReadAccessor > &root)
Definition: SelectionExprParser.cxx:139
ISelectionReadAccessor.h
CP::SelectionExprParser::m_symbol
DetailSelectionExprParser::Lexer::Symbol m_symbol
Definition: SelectionExprParser.h:105
CP::DetailSelectionExprParser::Lexer::Lexer
Lexer(const Lexer &)=delete
Disable copying of this class.
CP::SelectionExprParser::m_defaultToChar
bool m_defaultToChar
Definition: SelectionExprParser.h:107
CP::DetailSelectionExprParser::Lexer::Lexer
Lexer(const std::string &s)
Constructor from a strig.
Definition: SelectionExprParser.cxx:48
CP::DetailSelectionExprParser::Lexer::END
@ END
Definition: SelectionExprParser.h:59
SelectionHelpers.h
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