The Gaudi Framework  v29r0 (ff2e7097)
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 { return invoke( std::index_sequence_for<Out...>{} ); }
24 
25  // ... instead, they must implement the following operator
26  virtual std::tuple<Out...> operator()() const = 0;
27 
28  private:
29  template <std::size_t... O>
30  StatusCode invoke( std::index_sequence<O...> )
31  {
32  using details::as_const;
33  using details::put;
34  try {
36  ( put( std::get<O>( this->m_outputs ), std::get<O>( as_const( *this )() ) ), 0 )...};
37  } catch ( GaudiException& e ) {
38  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
39  return e.code();
40  }
41  return StatusCode::SUCCESS;
42  }
43  };
44 
45  template <typename Out, typename Traits_>
46  class Producer<Out(), Traits_> : public details::DataHandleMixin<std::tuple<Out>, void, Traits_>
47  {
48  public:
49  using details::DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
50  // derived classes are NOT allowed to implement execute ...
51  StatusCode execute() override final
52  {
53  using details::as_const;
54  using details::put;
55  try {
56  put( std::get<0>( this->m_outputs ), as_const( *this )() );
57  } catch ( GaudiException& e ) {
58  this->error() << "Error during transform: " << e.message() << " returning " << e.code() << endmsg;
59  return e.code();
60  }
61  return StatusCode::SUCCESS;
62  }
63 
64  // ... instead, they must implement the following operator
65  virtual Out operator()() const = 0;
66  };
67  }
68 }
69 
70 #endif
virtual const std::string & message() const
error message to be printed
constexpr std::add_const< T >::type & as_const(T &t) noexcept
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:51
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
StatusCode invoke(std::index_sequence< O... >)
Definition: Producer.h:30
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:83
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)