| The Gaudi Framework v32r1 (f65d50dc)

MergingTransformer.h
Go to the documentation of this file.
1 #ifndef MERGING_TRANSFORMER_H
2 #define MERGING_TRANSFORMER_H
3
4 #include <functional>
5 #include <string>
6 #include <vector>
7
8 #include "Gaudi/Algorithm.h"
9 #include "GaudiAlg/FunctionalDetails.h"
10 #include "GaudiAlg/FunctionalUtilities.h"
11
12 namespace Gaudi::Functional {
13
14 using details::vector_of_const_;
15
16 namespace details {
17
18 template <typename Signature, typename Traits_, bool isLegacy>
19 struct MergingTransformer;
20
22 template <typename Out, typename In, typename Traits_>
23 struct MergingTransformer<Out( const vector_of_const_<In>& ), Traits_, true>
24 : details::DataHandleMixin<std::tuple<Out>, void, Traits_> {
25 private:
26 using base_class = details::DataHandleMixin<std::tuple<Out>, void, Traits_>;
27
28 public:
29 using KeyValue = typename base_class::KeyValue;
30 using KeyValues = typename base_class::KeyValues;
31
32 MergingTransformer( const std::string& name, ISvcLocator* locator, const KeyValues& inputs,
33 const KeyValue& output )
34 : base_class( name, locator, output )
35 , m_inputLocations{this, inputs.first, inputs.second,
36 [=]( Gaudi::Details::PropertyBase& ) {
37 this->m_inputs = details::make_vector_of_handles<decltype( this->m_inputs )>(
38 this, m_inputLocations );
39 if ( std::is_pointer_v<In> ) { // handle constructor does not (yet) allow to set
40 // optional flag... so do it
41 // explicitly here...
42 std::for_each( this->m_inputs.begin(), this->m_inputs.end(),
43 []( auto& h ) { h.setOptional( true ); } );
44 }
45 },
46 Gaudi::Details::Property::ImmediatelyInvokeHandler{true}} {}
47
48 // accessor to input Locations
49 const std::string& inputLocation( unsigned int n ) const { return m_inputLocations.value()[n]; }
50 unsigned int inputLocationSize() const { return m_inputLocations.value().size(); }
51
52 // derived classes can NOT implement execute
53 StatusCode execute() override final {
54 vector_of_const_<In> ins;
55 ins.reserve( m_inputs.size() );
56 std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
57 details::details2::get_from_handle<In>{} );
58 try {
59 details::put( std::get<0>( this->m_outputs ), std::as_const( *this )( std::as_const( ins ) ) );
60 return StatusCode::SUCCESS;
61 } catch ( GaudiException& e ) {
62 ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
63 return e.code();
64 }
65 }
66
67 virtual Out operator()( const vector_of_const_<In>& inputs ) const = 0;
68
69 private:
70 // if In is a pointer, it signals optional (as opposed to mandatory) input
71 template <typename T>
72 using InputHandle_t = details::InputHandle_t<Traits_, std::remove_pointer_t<T>>;
73 std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
74 Gaudi::Property<std::vector<std::string>> m_inputLocations; // TODO/FIXME: remove this duplication...
75 // TODO/FIXME: replace vector of string property + call-back with a
76 // vector<handle> property ... as soon as declareProperty can deal with that.
77 };
78
79 template <typename Out, typename In, typename Traits_>
80 struct MergingTransformer<Out( const vector_of_const_<In>& ), Traits_, false>
81 : details::DataHandleMixin<std::tuple<Out>, void, Traits_> {
82 private:
83 using base_class = details::DataHandleMixin<std::tuple<Out>, void, Traits_>;
84
85 public:
86 using KeyValue = typename base_class::KeyValue;
87 using KeyValues = typename base_class::KeyValues;
88
89 MergingTransformer( const std::string& name, ISvcLocator* locator, const KeyValues& inputs,
90 const KeyValue& output )
91 : base_class( name, locator, output )
92 , m_inputLocations{this, inputs.first, inputs.second,
93 [=]( Gaudi::Details::PropertyBase& ) {
94 this->m_inputs = details::make_vector_of_handles<decltype( this->m_inputs )>(
95 this, m_inputLocations );
96 if ( std::is_pointer_v<In> ) { // handle constructor does not (yet) allow to set
97 // optional flag... so do it
98 // explicitly here...
99 std::for_each( this->m_inputs.begin(), this->m_inputs.end(),
100 []( auto& h ) { h.setOptional( true ); } );
101 }
102 },
103 Gaudi::Details::Property::ImmediatelyInvokeHandler{true}} {}
104
105 // accessor to input Locations
106 const std::string& inputLocation( unsigned int n ) const { return m_inputLocations.value()[n]; }
107 unsigned int inputLocationSize() const { return m_inputLocations.value().size(); }
108
109 // derived classes can NOT implement execute
110 StatusCode execute( const EventContext& ) const override final {
111 vector_of_const_<In> ins;
112 ins.reserve( m_inputs.size() );
113 std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
114 details::details2::get_from_handle<In>{} );
115 try {
116 details::put( std::get<0>( this->m_outputs ), ( *this )( std::as_const( ins ) ) );
117 return StatusCode::SUCCESS;
118 } catch ( GaudiException& e ) {
119 ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
120 return e.code();
121 }
122 }
123
124 virtual Out operator()( const vector_of_const_<In>& inputs ) const = 0;
125
126 private:
127 // if In is a pointer, it signals optional (as opposed to mandatory) input
128 template <typename T>
129 using InputHandle_t = details::InputHandle_t<Traits_, std::remove_pointer_t<T>>;
130 std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
131 Gaudi::Property<std::vector<std::string>> m_inputLocations; // TODO/FIXME: remove this duplication...
132 // TODO/FIXME: replace vector of string property + call-back with a
133 // vector<handle> property ... as soon as declareProperty can deal with that.
134 };
135
136 } // namespace details
137
138 template <typename Signature, typename Traits_ = Traits::useDefaults>
139 using MergingTransformer = details::MergingTransformer<Signature, Traits_, details::isLegacy<Traits_>>;
140
141 // Many of the same -> N
142 template <typename Signature, typename Traits_ = Traits::BaseClass_t<Gaudi::Algorithm>>
143 struct MergingMultiTransformer;
144
145 template <typename... Outs, typename In, typename Traits_>
146 struct MergingMultiTransformer<std::tuple<Outs...>( vector_of_const_<In> const& ), Traits_>
147 : details::DataHandleMixin<std::tuple<Outs...>, void, Traits_> {
148
149 private:
150 using base_class = details::DataHandleMixin<std::tuple<Outs...>, void, Traits_>;
151
152 public:
153 using KeyValue = typename base_class::KeyValue;
154 using KeyValues = typename base_class::KeyValues;
155 using OutKeys = std::array<KeyValue, sizeof...( Outs )>;
156
157 MergingMultiTransformer( std::string const& name, ISvcLocator* locator, KeyValues const& inputs,
158 OutKeys const& outputs );
159
160 // accessor to input Locations
161 std::string const& inputLocation( unsigned int n ) const { return m_inputLocations.value()[n]; }
162 unsigned int inputLocationSize() const { return m_inputLocations.value().size(); }
163
164 // derived classes can NOT implement execute
165 StatusCode execute( EventContext const& ) const override final {
166 vector_of_const_<In> ins;
167 ins.reserve( m_inputs.size() );
168 std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
169 details::details2::get_from_handle<In>{} );
170 try {
171 std::apply(
172 [&]( auto&... outhandle ) {
173 std::apply(
174 [&outhandle...]( auto&&... data ) {
175 ( details::put( outhandle, std::forward<decltype( data )>( data ) ), ... );
176 },
177 std::as_const( *this )( std::as_const( ins ) ) );
178 },
179 this->m_outputs );
180 } catch ( GaudiException& e ) {
181 ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
182 return e.code();
183 }
184 return StatusCode::SUCCESS;
185 }
186
187 virtual std::tuple<Outs...> operator()( const vector_of_const_<In>& inputs ) const = 0;
188
189 private:
190 // if In is a pointer, it signals optional (as opposed to mandatory) input
191 template <typename T>
192 using InputHandle_t = details::InputHandle_t<Traits_, typename std::remove_pointer<T>::type>;
193 std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
194 Gaudi::Property<std::vector<std::string>> m_inputLocations; // TODO/FIXME: remove this duplication...
195 // TODO/FIXME: replace vector of string property + call-back with a
196 // vector<handle> property ... as soon as declareProperty can deal with that.
197 };
198
199 template <typename... Outs, typename In, typename Traits_>
200 MergingMultiTransformer<std::tuple<Outs...>( const vector_of_const_<In>& ), Traits_>::MergingMultiTransformer(
201 std::string const& name, ISvcLocator* pSvcLocator, KeyValues const& inputs, OutKeys const& outputs )
202 : base_class( name, pSvcLocator, outputs )
203 , m_inputLocations{
204 this, inputs.first, inputs.second,
205 [=]( Gaudi::Details::PropertyBase& ) {
206 this->m_inputs = details::make_vector_of_handles<decltype( this->m_inputs )>( this, m_inputLocations );
207 if ( std::is_pointer_v<In> ) { // handle constructor does not (yet) allow to set
208 // optional flag... so do it
209 // explicitly here...
210 std::for_each( this->m_inputs.begin(), this->m_inputs.end(), []( auto& h ) { h.setOptional( true ); } );
211 }
212 },
213 Gaudi::Details::Property::ImmediatelyInvokeHandler{true}} {}
214
215 } // namespace Gaudi::Functional
216
217 #endif
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::inputLocation
std::string const & inputLocation(unsigned int n) const
Definition: MergingTransformer.h:161
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Gaudi::Functional::details::vector_of_const_::reserve
void reserve(size_type size)
Definition: FunctionalDetails.h:257
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::execute
StatusCode execute(EventContext const &) const override final
Definition: MergingTransformer.h:165
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
gaudirun.output
output
Definition: gaudirun.py:484
Gaudi::Functional::details::InputHandle_t
Gaudi::cpp17::detected_or_t< DataObjectReadHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
Definition: FunctionalDetails.h:311
Gaudi::Details::Property::ImmediatelyInvokeHandler
Gaudi::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
Definition: Property.h:141
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
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::m_inputs
std::vector< InputHandle_t< In > > m_inputs
Definition: MergingTransformer.h:193
std
STL namespace.
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::InputHandle_t
details::InputHandle_t< Traits_, typename std::remove_pointer< T >::type > InputHandle_t
Definition: MergingTransformer.h:192
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::KeyValues
typename base_class::KeyValues KeyValues
Definition: MergingTransformer.h:30
Gaudi::Functional::details::details2::get_from_handle
Definition: FunctionalDetails.h:193
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::execute
StatusCode execute(const EventContext &) const override final
Definition: MergingTransformer.h:110
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::KeyValue
typename base_class::KeyValue KeyValue
Definition: MergingTransformer.h:86
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::KeyValues
typename base_class::KeyValues KeyValues
Definition: MergingTransformer.h:154
Gaudi::Functional
Definition: Consumer.h:8
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::KeyValue
typename base_class::KeyValue KeyValue
Definition: MergingTransformer.h:153
Gaudi::Functional::details::vector_of_const_
Definition: FunctionalDetails.h:216
std::string
STL class.
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
Gaudi::Functional::details::MergingTransformer
Definition: MergingTransformer.h:19
Gaudi::Functional::details::DataHandleMixin
Definition: FunctionalDetails.h:390
details
Definition: AnyDataWrapper.h:10
Algorithm.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
FunctionalUtilities.h
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::m_inputLocations
Gaudi::Property< std::vector< std::string > > m_inputLocations
Definition: MergingTransformer.h:74
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::m_inputLocations
Gaudi::Property< std::vector< std::string > > m_inputLocations
Definition: MergingTransformer.h:131
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::MergingTransformer
MergingTransformer(const std::string &name, ISvcLocator *locator, const KeyValues &inputs, const KeyValue &output)
Definition: MergingTransformer.h:89
std::tuple
GaudiException::code
virtual const StatusCode & code() const
StatusCode for Exception.
Definition: GaudiException.h:76
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::inputLocationSize
unsigned int inputLocationSize() const
Definition: MergingTransformer.h:162
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::InputHandle_t
details::InputHandle_t< Traits_, std::remove_pointer_t< T > > InputHandle_t
Definition: MergingTransformer.h:72
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::inputLocationSize
unsigned int inputLocationSize() const
Definition: MergingTransformer.h:107
std::vector
STL class.
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::m_inputs
std::vector< InputHandle_t< In > > m_inputs
Definition: MergingTransformer.h:130
Gaudi::Functional::MergingMultiTransformer
Definition: MergingTransformer.h:143
std::back_inserter
T back_inserter(T... args)
Gaudi::Functional::details::put
Out1 * put(const DataObjectHandle< Out1 > &out_handle, Out2 &&out)
Definition: FunctionalDetails.h:121
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::inputLocation
const std::string & inputLocation(unsigned int n) const
Definition: MergingTransformer.h:49
std::array
STL class.
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::InputHandle_t
details::InputHandle_t< Traits_, std::remove_pointer_t< T > > InputHandle_t
Definition: MergingTransformer.h:129
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::inputLocationSize
unsigned int inputLocationSize() const
Definition: MergingTransformer.h:50
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::MergingTransformer
MergingTransformer(const std::string &name, ISvcLocator *locator, const KeyValues &inputs, const KeyValue &output)
Definition: MergingTransformer.h:32
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::execute
StatusCode execute() override final
Definition: MergingTransformer.h:53
std::transform
T transform(T... args)
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::KeyValues
typename base_class::KeyValues KeyValues
Definition: MergingTransformer.h:87
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, false >::inputLocation
const std::string & inputLocation(unsigned int n) const
Definition: MergingTransformer.h:106
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::m_inputs
std::vector< InputHandle_t< In > > m_inputs
Definition: MergingTransformer.h:73
std::for_each
T for_each(T... args)
Gaudi::Functional::details::MergingTransformer< Out(const vector_of_const_< In > &), Traits_, true >::KeyValue
typename base_class::KeyValue KeyValue
Definition: MergingTransformer.h:29
Gaudi::Functional::details::make_vector_of_handles
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init)
Definition: FunctionalDetails.h:320
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
FunctionalDetails.h
Gaudi::Functional::MergingMultiTransformer< std::tuple< Outs... >(vector_of_const_< In > const &), Traits_ >::m_inputLocations
Gaudi::Property< std::vector< std::string > > m_inputLocations
Definition: MergingTransformer.h:194