ATLAS Offline Software
ExpressionParserUser.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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
22 namespace ExpressionParsing {
23  class SGxAODProxyLoader;
24  class 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 
70 template <class T_Base, unsigned short const NUM_PARSER>
72  : public T_Base,
73  virtual public IDynamicDataConsumer
74 {
75 public:
76  template <typename...Args>
77  ExpressionParserUserBase(Args...args) : T_Base(args...) {}
78  virtual ~ExpressionParserUserBase() = default;
79 
80 
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 
90 protected:
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 
105 template <class T_Base, unsigned short const NUM_PARSER = 1>
106 class ExpressionParserUser : public ExpressionParserUserBase<T_Base, NUM_PARSER>
107 {
108 public:
109  template <typename...Args>
110  ExpressionParserUser(Args...args) : ExpressionParserUserBase<T_Base,NUM_PARSER>(args...) {}
112 
113 };
114 #endif
python.CaloScaleNoiseConfig.parser
parser
Definition: CaloScaleNoiseConfig.py:75
ExpressionParserUserBase::finalizeParser
StatusCode finalizeParser()
ExpressionParsing::AppendLoaderFunc
std::function< StatusCode(ExpressionParsing::MultipleProxyLoader &)> AppendLoaderFunc
Definition: ExpressionParserUser.h:25
ExpressionParsing::SelectionArg
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
Definition: ExpressionParserUser.h:66
ExpressionParserUserBase::m_parser
std::conditional< NUM_PARSER==1, std::unique_ptr< ExpressionParsing::ExpressionParser >, std::array< std::unique_ptr< ExpressionParsing::ExpressionParser >, NUM_PARSER > >::type m_parser
Definition: ExpressionParserUser.h:100
IDynamicDataConsumer
Definition: IDynamicDataConsumer.h:15
ExpressionParserUser::ExpressionParserUser
ExpressionParserUser(Args...args)
Definition: ExpressionParserUser.h:110
ExpressionParserUserBase::m_xAODProxyLoader
ExpressionParsing::SGxAODProxyLoader * m_xAODProxyLoader
The expression parser.
Definition: ExpressionParserUser.h:96
ExpressionParsing::SingleParserHelper::createParser
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.
IDynamicDataConsumer.h
ExpressionParserUserBase::renounceInput
virtual bool renounceInput(const DataObjID &output_data_id) override
Args
Definition: test_lwtnn_fastgraph.cxx:12
ExpressionParserUserBase::_initializeParser
StatusCode _initializeParser(const ExpressionParsing::SelectionArg< NUM_PARSER > &selection_string, ExpressionParsing::AppendLoaderFunc pre_xaod_loader=ExpressionParsing::NoLoaderFunc, ExpressionParsing::AppendLoaderFunc post_xaod_loader=ExpressionParsing::NoLoaderFunc)
ExpressionParserUserBase::m_renounce
std::vector< std::string > m_renounce
Definition: ExpressionParserUser.h:102
ExpressionParsing::IProxyLoader
Definition: IProxyLoader.h:19
ExpressionParserUserBase::updateDataNeeds
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.
ExpressionParserUserBase::ExpressionParserUserBase
ExpressionParserUserBase(Args...args)
Definition: ExpressionParserUser.h:77
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ExpressionParsing
Namespace holding all the expression evaluation code.
Definition: ExpressionParser.h:26
ExpressionParserUserBase
Definition: ExpressionParserUser.h:74
ExpressionParserUser::initializeParser
StatusCode initializeParser(const ExpressionParsing::SelectionArg< NUM_PARSER > &selection_string)
lumiFormat.array
array
Definition: lumiFormat.py:91
ExpressionParserUser
Definition: ExpressionParserUser.h:107
ExpressionParserUserBase::~ExpressionParserUserBase
virtual ~ExpressionParserUserBase()=default
ExpressionParsing::ParserHelper
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.
Definition: ExpressionParserUser.h:62
ExpressionParsing::MultiParserHelper::getVariables
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.
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ExpressionParsing::SingleParserHelper::getVariables
static std::vector< std::string > getVariables(const std::unique_ptr< ExpressionParsing::ExpressionParser > &parser)
Get the variables from used by the given expression parser.
ExpressionParser.h
IProxyLoader.h
ExpressionParsing::SGxAODProxyLoader
Auxiliary class to access content of xAOD objects referred to by variables of an expressions handled ...
Definition: SGxAODProxyLoader.h:46
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
ExpressionParsing::MultiParserHelper::createParser
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
ExpressionParserUserBase::m_proxyLoaders
std::unique_ptr< ExpressionParsing::IProxyLoader > m_proxyLoaders
Definition: ExpressionParserUser.h:97
ExpressionParsing::MultipleProxyLoader
Definition: MultipleProxyLoader.h:24
ExpressionParsing::NoLoaderFunc
StatusCode NoLoaderFunc(ExpressionParsing::MultipleProxyLoader &)
Definition: ExpressionParserUser.h:26
ExpressionParsing::MultiParserHelper
Helper class to handle an array expression parsers to be used in the generic code.
Definition: ExpressionParserUser.h:30
ExpressionParsing::SingleParserHelper
Helper class to handle a single expression parser to be used in the generic code.
Definition: ExpressionParserUser.h:45