The Gaudi Framework  v30r3 (a5ef0a68)
Producer.h
Go to the documentation of this file.
1 #ifndef GAUDI_FUNCTIONAL_PRODUCER_H
2 #define GAUDI_FUNCTIONAL_PRODUCER_H
3 
6 #include "GaudiKernel/apply.h"
7 #include <utility>
8 
9 namespace Gaudi
10 {
11  namespace Functional
12  {
13 
14  template <typename Signature, typename Traits_ = Traits::useDefaults>
15  class Producer;
16 
17  template <typename... Out, typename Traits_>
18  class Producer<std::tuple<Out...>(), Traits_> : public details::DataHandleMixin<std::tuple<Out...>, void, Traits_>
19  {
20  public:
21  using details::DataHandleMixin<std::tuple<Out...>, void, Traits_>::DataHandleMixin;
22 
23  // derived classes are NOT allowed to implement execute ...
24  StatusCode execute() override final
25  {
26  try {
28  [&]( auto&... ohandle ) {
30  [&ohandle...]( auto&&... data ) {
31 #if __cplusplus < 201703L
32  (void)std::initializer_list<int>{
33  ( details::put( ohandle, std::forward<decltype( data )>( data ) ), 0 )...};
34 #else
35  ( details::put( ohandle, std::forward<decltype( data )>( data ) ), ... );
36 #endif
37  },
38  details::as_const( *this )() );
39  },
40  this->m_outputs );
41  } catch ( GaudiException& e ) {
42  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
43  return e.code();
44  }
45  return StatusCode::SUCCESS;
46  }
47 
48  // ... instead, they must implement the following operator
49  virtual std::tuple<Out...> operator()() const = 0;
50  };
51 
52  template <typename Out, typename Traits_>
53  class Producer<Out(), Traits_> : public details::DataHandleMixin<std::tuple<Out>, void, Traits_>
54  {
55  public:
56  using details::DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
57  // derived classes are NOT allowed to implement execute ...
58  StatusCode execute() override final
59  {
60  try {
61  details::put( std::get<0>( this->m_outputs ), details::as_const( *this )() );
62  } catch ( GaudiException& e ) {
63  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
64  return e.code();
65  }
66  return StatusCode::SUCCESS;
67  }
68 
69  // ... instead, they must implement the following operator
70  virtual Out operator()() const = 0;
71  };
72  }
73 }
74 
75 #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
decltype(auto) constexpr apply(F &&f, Tuple &&t) noexcept(noexcept( detail::apply_impl(std::forward< F >(f), std::forward< Tuple >(t), std::make_index_sequence< std::tuple_size< std::remove_reference_t< Tuple >>::value >{})))
Definition: apply.h:31
virtual const StatusCode & code() const
StatusCode for Exception.
StatusCode execute() override final
Definition: Producer.h:58
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_
T forward(T...args)
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)