Producer.h
Go to the documentation of this file.
1 #ifndef GAUDI_FUNCTIONAL_PRODUCER_H
2 #define GAUDI_FUNCTIONAL_PRODUCER_H
3 
4 #include <utility>
7 
8 namespace Gaudi { namespace Functional {
9 
10  template <typename Signature, typename Traits_ = Traits::useDefaults> class Producer;
11 
12  template <typename... Out, typename Traits_>
13  class Producer<std::tuple<Out...>(), Traits_>
14  : public details::DataHandleMixin<std::tuple<Out...>,void,Traits_> {
15  public:
16  using details::DataHandleMixin<std::tuple<Out...>,void,Traits_>::DataHandleMixin;
17 
18  // derived classes are NOT allowed to implement execute ...
19  StatusCode execute() override final
20  { return invoke(std::index_sequence_for<Out...>{}); }
21 
22  // ... instead, they must implement the following operator
23  virtual std::tuple<Out...> operator()() const = 0;
24 
25  private:
26  template <std::size_t... O>
27  StatusCode invoke(std::index_sequence<O...>) {
28  using details::as_const; using details::put;
29  try {
31  (put(std::get<O>(this->m_outputs),std::get<O>( as_const(*this)() )),0)...
32  };
33  } catch ( GaudiException& e ) {
34  (e.code() ? this->warning() : this->error() )
35  << e.message() << endmsg;
36  return e.code();
37  }
38  return StatusCode::SUCCESS;
39  }
40  };
41 
42  template <typename Out, typename Traits_>
43  class Producer<Out(),Traits_>
44  : public details::DataHandleMixin<std::tuple<Out>,void,Traits_> {
45  public:
47  // derived classes are NOT allowed to implement execute ...
48  StatusCode execute() override final {
49  using details::as_const; using details::put;
50  try {
51  put(std::get<0>(this->m_outputs),as_const(*this)() );
52  } catch ( GaudiException& e ) {
53  this->error() << "Error during transform: " << e.message() << " returning " << e.code() << endmsg;
54  return e.code();
55  }
56  return StatusCode::SUCCESS;
57  }
58 
59  // ... instead, they must implement the following operator
60  virtual Out operator()() const = 0;
61  };
62 }}
63 
64 #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:48
class MergingTransformer< Out(const vector_of_const_< In > Traits_
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
StatusCode invoke(std::index_sequence< O... >)
Definition: Producer.h:27
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:244
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)