| The Gaudi Framework v32r1 (f65d50dc)

Producer.h
Go to the documentation of this file.
1 #ifndef GAUDI_FUNCTIONAL_PRODUCER_H
2 #define GAUDI_FUNCTIONAL_PRODUCER_H
3
4 #include "GaudiAlg/FunctionalDetails.h"
5 #include "GaudiAlg/FunctionalUtilities.h"
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_> {
17 using details::DataHandleMixin<std::tuple<Out...>, void, Traits_>::DataHandleMixin;
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_> {
45 using details::DataHandleMixin<std::tuple<Out...>, void, Traits_>::DataHandleMixin;
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_> {
72 using details::DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
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_> {
90 using details::DataHandleMixin<std::tuple<Out>, void, Traits_>::DataHandleMixin;
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>
109 using Producer = details::Producer<Signature, Traits_, details::isLegacy<Traits_>>;
110
111 } // namespace Gaudi::Functional
112
113 #endif
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
Gaudi::Functional::details::Producer< std::tuple< Out... >(), Traits_, false >::execute
StatusCode execute(const EventContext &) const override final
Definition: Producer.h:48
Gaudi::Functional::details::Producer
Definition: Producer.h:13
GaudiException::message
virtual const std::string & message() const
error message to be printed
Definition: GaudiException.h:58
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
std
STL namespace.
Gaudi::Functional::details::Producer< std::tuple< Out... >(), Traits_, true >::execute
StatusCode execute() override final
Definition: Producer.h:20
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
Gaudi::Functional
Definition: Consumer.h:8
Gaudi::Functional::details::Producer< Out(), Traits_, true >::execute
StatusCode execute() override final
Definition: Producer.h:74
Gaudi::Functional::details::Producer< Out(), Traits_, false >::execute
StatusCode execute(const EventContext &) const override final
Definition: Producer.h:92
Gaudi::Functional::details::DataHandleMixin
Definition: FunctionalDetails.h:390
details
Definition: AnyDataWrapper.h:10
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
FunctionalUtilities.h
std::tuple
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition: GaudiException.h:76
Gaudi::Functional::details::put
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: FunctionalDetails.h:121
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
FunctionalDetails.h