ATLAS Offline Software
Loading...
Searching...
No Matches
ExpressionParserUser.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4/* Dear emacs, this is -*-c++-*- */
5#ifndef _ExpressionParserUser_H_
6#define _ExpressionParserUser_H_
7
8#include <memory>
9#include <string>
10#include <vector>
11#include <functional>
12#include <type_traits>
13#include <array>
15#include "GaudiKernel/StatusCode.h"
16#include "GaudiKernel/DataHandle.h"
17
20
21// Forward declarations
22namespace ExpressionParsing {
25 using AppendLoaderFunc = std::function<StatusCode(ExpressionParsing::MultipleProxyLoader &)>;
26 inline StatusCode NoLoaderFunc(ExpressionParsing::MultipleProxyLoader &) { return StatusCode::SUCCESS;}
27
29 template <unsigned short NUM_PARSER>
31 public:
33 static
34 std::array< std::unique_ptr<ExpressionParsing::ExpressionParser>, NUM_PARSER >
36 const std::vector< std::string> &selection_string,
37 unsigned short num_parser);
38
40 static
41 std::vector<std::string> getVariables(const std::array<std::unique_ptr<ExpressionParsing::ExpressionParser>,NUM_PARSER> &parser);
42 };
43
46 public:
48 static
49 std::unique_ptr<ExpressionParsing::ExpressionParser>
51 const std::string &selection_string,
52 unsigned short num_parser);
53
55 static
56 std::vector<std::string> getVariables(const std::unique_ptr<ExpressionParsing::ExpressionParser> &parser);
57
58 };
59
61 template <unsigned short NUM_PARSER>
62 using ParserHelper = typename std::conditional< NUM_PARSER == 1, class SingleParserHelper, class MultiParserHelper<NUM_PARSER> >::type;
63
65 template <unsigned short NUM_PARSER>
66 using SelectionArg = typename std::conditional< NUM_PARSER == 1, std::string, std::vector< std::string > >::type;
67}
68
69
70template <class T_Base, unsigned short const NUM_PARSER>
72 : public T_Base,
73 virtual public IDynamicDataConsumer
74{
75public:
76 template <typename...Args>
77 ExpressionParserUserBase(Args...args) : T_Base(args...) {}
78 virtual ~ExpressionParserUserBase() = default;
79
80
81 StatusCode finalizeParser();
82
83 virtual bool updateDataNeeds(const std::vector<const DataObjID*> &input_data_in,
84 const std::vector<const DataObjID*> &output_data_in,
85 std::vector<Gaudi::DataHandle *> &new_input_handles,
86 std::vector<Gaudi::DataHandle *> &new_output_handles) override;
87
88 virtual bool renounceInput( const DataObjID &output_data_id) override;
89
90protected:
94
97 std::unique_ptr<ExpressionParsing::IProxyLoader> m_proxyLoaders;
98 typename std::conditional< NUM_PARSER == 1,
99 std::unique_ptr<ExpressionParsing::ExpressionParser>,
100 std::array< std::unique_ptr<ExpressionParsing::ExpressionParser>, NUM_PARSER> >::type m_parser;
101
102 std::vector<std::string> m_renounce;
103};
104
105template <class T_Base, unsigned short const NUM_PARSER = 1>
106class ExpressionParserUser : public ExpressionParserUserBase<T_Base, NUM_PARSER>
107{
108public:
109 template <typename...Args>
111 : ExpressionParserUserBase<T_Base,NUM_PARSER>(std::forward<Args>(args)...) {}
113
114};
115#endif
virtual bool renounceInput(const DataObjID &output_data_id) override
std::unique_ptr< ExpressionParsing::IProxyLoader > m_proxyLoaders
StatusCode finalizeParser()
ExpressionParsing::SGxAODProxyLoader * m_xAODProxyLoader
The expression parser.
std::conditional< NUM_PARSER==1, std::unique_ptr< ExpressionParsing::ExpressionParser >, std::array< std::unique_ptr< ExpressionParsing::ExpressionParser >, NUM_PARSER > >::type m_parser
std::vector< std::string > m_renounce
virtual ~ExpressionParserUserBase()=default
StatusCode _initializeParser(const ExpressionParsing::SelectionArg< NUM_PARSER > &selection_string, ExpressionParsing::AppendLoaderFunc pre_xaod_loader=ExpressionParsing::NoLoaderFunc, ExpressionParsing::AppendLoaderFunc post_xaod_loader=ExpressionParsing::NoLoaderFunc)
virtual bool updateDataNeeds(const std::vector< const DataObjID * > &input_data_in, const std::vector< const DataObjID * > &output_data_in, std::vector< Gaudi::DataHandle * > &new_input_handles, std::vector< Gaudi::DataHandle * > &new_output_handles) override
Inform a dynamic data consumer about all consumed or produced data.
ExpressionParserUser(Args &&...args)
StatusCode initializeParser(const ExpressionParsing::SelectionArg< NUM_PARSER > &selection_string)
Helper class to handle an array expression parsers to be used in the generic code.
static std::array< std::unique_ptr< ExpressionParsing::ExpressionParser >, NUM_PARSER > createParser(ExpressionParsing::IProxyLoader &proxy_loader, const std::vector< std::string > &selection_string, unsigned short num_parser)
create an expression parser for each of the given expression strings
static std::vector< std::string > getVariables(const std::array< std::unique_ptr< ExpressionParsing::ExpressionParser >, NUM_PARSER > &parser)
get the union of all variables used by the given list of expression parsers.
Auxiliary class to access content of xAOD objects referred to by variables of an expressions handled ...
Helper class to handle a single expression parser to be used in the generic code.
static std::unique_ptr< ExpressionParsing::ExpressionParser > createParser(ExpressionParsing::IProxyLoader &proxy_loader, const std::string &selection_string, unsigned short num_parser)
Create a single expression parser for the given expression.
static std::vector< std::string > getVariables(const std::unique_ptr< ExpressionParsing::ExpressionParser > &parser)
Get the variables from used by the given expression parser.
Namespace holding all the expression evaluation code.
typename std::conditional< NUM_PARSER==1, std::string, std::vector< std::string > >::type SelectionArg
type to be used for expression string(s) for a single or multiple expression parsers
std::function< StatusCode(ExpressionParsing::MultipleProxyLoader &)> AppendLoaderFunc
typename std::conditional< NUM_PARSER==1, class SingleParserHelper, class MultiParserHelper< NUM_PARSER > >::type ParserHelper
type of a helper class to create n-parser for the given expression or list of expressions.
StatusCode NoLoaderFunc(ExpressionParsing::MultipleProxyLoader &)
STL namespace.