The Gaudi Framework  v32r0 (3325bb39)
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> : details::DataHandleMixin<std::tuple<Out...>, void, Traits_> {
18 
19  // derived classes are NOT allowed to implement execute ...
20  StatusCode execute() override final {
21  try {
22  std::apply(
23  [&]( auto&... ohandle ) {
24  std::apply(
25  [&ohandle...]( auto&&... data ) {
26  ( details::put( ohandle, std::forward<decltype( data )>( data ) ), ... );
27  },
28  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>
44  : details::DataHandleMixin<std::tuple<Out...>, void, Traits_> {
46 
47  // derived classes are NOT allowed to implement execute ...
48  StatusCode execute( const EventContext& ) const override final {
49  try {
50  std::apply(
51  [&]( auto&... ohandle ) {
52  std::apply(
53  [&ohandle...]( auto&&... data ) {
54  ( details::put( ohandle, std::forward<decltype( data )>( data ) ), ... );
55  },
56  ( *this )() );
57  },
58  this->m_outputs );
59  return StatusCode::SUCCESS;
60  } catch ( GaudiException& e ) {
61  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
62  return e.code();
63  }
64  }
65 
66  // ... instead, they must implement the following operator
67  virtual std::tuple<Out...> operator()() const = 0;
68  };
69 
70  template <typename Out, typename Traits_>
71  struct Producer<Out(), Traits_, true> : public details::DataHandleMixin<std::tuple<Out>, void, Traits_> {
73  // derived classes are NOT allowed to implement execute ...
74  StatusCode execute() override final {
75  try {
76  details::put( std::get<0>( this->m_outputs ), std::as_const( *this )() );
77  return StatusCode::SUCCESS;
78  } catch ( GaudiException& e ) {
79  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
80  return e.code();
81  }
82  }
83 
84  // ... instead, they must implement the following operator
85  virtual Out operator()() const = 0;
86  };
87 
88  template <typename Out, typename Traits_>
89  struct Producer<Out(), Traits_, false> : public details::DataHandleMixin<std::tuple<Out>, void, Traits_> {
91  // derived classes are NOT allowed to implement execute ...
92  StatusCode execute( const EventContext& ) const override final {
93  try {
94  details::put( std::get<0>( this->m_outputs ), ( *this )() );
95  return StatusCode::SUCCESS;
96  } catch ( GaudiException& e ) {
97  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
98  return e.code();
99  }
100  }
101 
102  // ... instead, they must implement the following operator
103  virtual Out operator()() const = 0;
104  };
105 
106  } // namespace details
107 
108  template <typename Signature, typename Traits_ = Traits::useDefaults>
110 
111 } // namespace Gaudi::Functional
112 
113 #endif
class MergingTransformer< Out(const vector_of_const_< In > true
virtual const std::string & message() const
error message to be printed
Define general base for Gaudi exception.
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
StatusCode execute(const EventContext &) const override final
Definition: Producer.h:48
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
virtual const StatusCode & code() const
StatusCode for Exception.
class MergingTransformer< Out(const vector_of_const_< In > Traits_
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
StatusCode execute(const EventContext &) const override final
Definition: Producer.h:92
class MergingTransformer< Out(const vector_of_const_< In > void
class MergingTransformer< Out(const vector_of_const_< In > false
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192