The Gaudi Framework  v32r2 (46d42edc)
Producer.h
Go to the documentation of this file.
1 #ifndef GAUDI_FUNCTIONAL_PRODUCER_H
2 #define GAUDI_FUNCTIONAL_PRODUCER_H
3 
6 #include <utility>
7 
8 namespace Gaudi::Functional {
9 
10  namespace details {
11 
12  template <typename Signature, typename Traits_, bool isLegacy>
13  struct Producer;
14 
15  template <typename... Out, typename Traits_>
16  struct Producer<std::tuple<Out...>(), Traits_, true> : DataHandleMixin<std::tuple<Out...>, void, Traits_> {
17  using DataHandleMixin<std::tuple<Out...>, void, Traits_>::DataHandleMixin;
18 
19  // derived classes are NOT allowed to implement execute ...
20  StatusCode execute() override final {
21  try {
22  std::apply(
23  [&]( auto&... ohandle ) {
25  std::apply( [&ohandle...](
26  auto&&... data ) { ( put( ohandle, std::forward<decltype( data )>( data ) ), ... ); },
27  std::as_const( *this )() );
29  },
30  this->m_outputs );
31  return StatusCode::SUCCESS;
32  } catch ( GaudiException& e ) {
33  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
34  return e.code();
35  }
36  }
37 
38  // ... instead, they must implement the following operator
39  virtual std::tuple<Out...> operator()() const = 0;
40  };
41 
42  template <typename... Out, typename Traits_>
43  struct Producer<std::tuple<Out...>(), Traits_, false> : DataHandleMixin<std::tuple<Out...>, void, Traits_> {
44  using DataHandleMixin<std::tuple<Out...>, void, Traits_>::DataHandleMixin;
45 
46  // derived classes are NOT allowed to implement execute ...
47  StatusCode execute( const EventContext& ) const override final {
48  try {
49  std::apply(
51 
52  [&]( auto&... ohandle ) {
53  std::apply(
54  [&ohandle...]( auto&&... data ) {
55  ( put( ohandle, std::forward<decltype( data )>( data ) ), ... );
56  },
57  ( *this )() );
58  },
60 
61  this->m_outputs );
62  return StatusCode::SUCCESS;
63  } catch ( GaudiException& e ) {
64  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
65  return e.code();
66  }
67  }
68 
69  // ... instead, they must implement the following operator
70  virtual std::tuple<Out...> operator()() const = 0;
71  };
72 
73  template <typename Out, typename Traits_>
74  struct Producer<Out(), Traits_, true> : public DataHandleMixin<std::tuple<Out>, void, Traits_> {
75  using DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
76  // derived classes are NOT allowed to implement execute ...
77  StatusCode execute() override final {
78  try {
79  put( std::get<0>( this->m_outputs ), std::as_const( *this )() );
80  return StatusCode::SUCCESS;
81  } catch ( GaudiException& e ) {
82  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
83  return e.code();
84  }
85  }
86 
87  // ... instead, they must implement the following operator
88  virtual Out operator()() const = 0;
89  };
90 
91  template <typename Out, typename Traits_>
92  struct Producer<Out(), Traits_, false> : public DataHandleMixin<std::tuple<Out>, void, Traits_> {
93  using DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
94  // derived classes are NOT allowed to implement execute ...
95  StatusCode execute( const EventContext& ) const override final {
96  try {
97  put( std::get<0>( this->m_outputs ), ( *this )() );
98  return StatusCode::SUCCESS;
99  } catch ( GaudiException& e ) {
100  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
101  return e.code();
102  }
103  }
104 
105  // ... instead, they must implement the following operator
106  virtual Out operator()() const = 0;
107  };
108 
109  } // namespace details
110 
111  template <typename Signature, typename Traits_ = Traits::useDefaults>
113 
114 } // namespace Gaudi::Functional
115 
116 #endif
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Define general base for Gaudi exception.
StatusCode execute(const EventContext &) const override final
Definition: Producer.h:47
#define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN
virtual const std::string & message() const
error message to be printed
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
StatusCode execute(const EventContext &) const override final
Definition: Producer.h:95
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
virtual const StatusCode & code() const
StatusCode for Exception.
#define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192