The Gaudi Framework  v30r2 (9eca68f7)
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
9 {
10  namespace Functional
11  {
12 
13  template <typename Signature, typename Traits_ = Traits::useDefaults>
14  class Producer;
15 
16  template <typename... Out, typename Traits_>
17  class Producer<std::tuple<Out...>(), Traits_> : public details::DataHandleMixin<std::tuple<Out...>, void, Traits_>
18  {
19  public:
20  using details::DataHandleMixin<std::tuple<Out...>, void, Traits_>::DataHandleMixin;
21 
22  // derived classes are NOT allowed to implement execute ...
23  StatusCode execute() override final
24  {
25  try {
26  invoke( std::index_sequence_for<Out...>{} );
27  } catch ( GaudiException& e ) {
28  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
29  return e.code();
30  }
31  return StatusCode::SUCCESS;
32  }
33 
34  // ... instead, they must implement the following operator
35  virtual std::tuple<Out...> operator()() const = 0;
36 
37  private:
38  template <std::size_t... O>
39  void invoke( std::index_sequence<O...> )
40  {
42  ( details::put( std::get<O>( this->m_outputs ), std::get<O>( details::as_const( *this )() ) ), 0 )...};
43  }
44  };
45 
46  template <typename Out, typename Traits_>
47  class Producer<Out(), Traits_> : public details::DataHandleMixin<std::tuple<Out>, void, Traits_>
48  {
49  public:
50  using details::DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
51  // derived classes are NOT allowed to implement execute ...
52  StatusCode execute() override final
53  {
54  using details::as_const;
55  using details::put;
56  try {
57  put( std::get<0>( this->m_outputs ), as_const( *this )() );
58  } catch ( GaudiException& e ) {
59  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
60  return e.code();
61  }
62  return StatusCode::SUCCESS;
63  }
64 
65  // ... instead, they must implement the following operator
66  virtual Out operator()() const = 0;
67  };
68  }
69 }
70 
71 #endif
virtual const std::string & message() const
error message to be printed
Define general base for Gaudi exception.
STL namespace.
class MergingTransformer< Out(const vector_of_const_< In > void
virtual const StatusCode & code() const
StatusCode for Exception.
StatusCode execute() override final
Definition: Producer.h:52
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
constexpr std::add_const_t< T > & as_const(T &t) noexcept
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
struct[[deprecated("use MergingTransformer instead")]] Traits_
auto invoke(F &&f, ArgTypes &&...args) noexcept(noexcept(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))) -> decltype(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))
Definition: invoke.h:85
Helper functions to set/get the application return code.
Definition: __init__.py:1
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)