Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
10 
11 namespace Gaudi {
12  namespace Functional {
13 
14  template <typename Signature, typename Traits_ = Traits::useDefaults>
16 
18 
20  template <typename Out, typename In, typename Traits_>
21  class MergingTransformer<Out( const vector_of_const_<In>& ), Traits_>
24 
25  public:
28 
29  MergingTransformer( const std::string& name, ISvcLocator* locator, const KeyValues& inputs,
30  const KeyValue& output );
31 
32  // accessor to input Locations
33  const std::string& inputLocation( unsigned int n ) const { return m_inputLocations.value()[n]; }
34  unsigned int inputLocationSize() const { return m_inputLocations.value().size(); }
35 
36  // derived classes can NOT implement execute
37  StatusCode execute() override final {
38  vector_of_const_<In> ins;
39  ins.reserve( m_inputs.size() );
40  std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
42  try {
43  using details::as_const;
44  details::put( std::get<0>( this->m_outputs ), as_const( *this )( as_const( ins ) ) );
45  } catch ( GaudiException& e ) {
46  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
47  return e.code();
48  }
49  return StatusCode::SUCCESS;
50  }
51 
52  virtual Out operator()( const vector_of_const_<In>& inputs ) const = 0;
53 
54  private:
55  // if In is a pointer, it signals optional (as opposed to mandatory) input
56  template <typename T>
58  std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
59  Gaudi::Property<std::vector<std::string>> m_inputLocations; // TODO/FIXME: remove this duplication...
60  // TODO/FIXME: replace vector of string property + call-back with a
61  // vector<handle> property ... as soon as declareProperty can deal with that.
62  };
63 
64  template <typename Out, typename In, typename Traits_>
66  ISvcLocator* pSvcLocator,
67  const KeyValues& inputs,
68  const KeyValue& output )
69  : base_class( name, pSvcLocator, output )
70  , m_inputLocations{this, inputs.first, inputs.second,
72  this->m_inputs =
73  details::make_vector_of_handles<decltype( this->m_inputs )>( this, m_inputLocations );
74  if ( std::is_pointer<In>::value ) { // handle constructor does not (yet) allow to set
75  // optional flag... so do it
76  // explicitly here...
77  std::for_each( this->m_inputs.begin(), this->m_inputs.end(),
78  []( auto& h ) { h.setOptional( true ); } );
79  }
80  },
82  } // namespace Functional
83 } // namespace Gaudi
84 
85 #endif
virtual const std::string & message() const
error message to be printed
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Gaudi::Property< std::vector< std::string > > m_inputLocations
Implementation of property with value of concrete type.
Definition: Property.h:352
Gaudi::cpp17::detected_or_t< DataObjectReadHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
StatusCode execute() override final
Gaudi::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
Definition: Property.h:141
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
class MergingTransformer< Out(const vector_of_const_< In > void
details::InputHandle_t< Traits_, typename std::remove_pointer< T >::type > InputHandle_t
virtual const StatusCode & code() const
StatusCode for Exception.
STL class.
unsigned int inputLocationSize() const
class MergingTransformer< Out(const vector_of_const_< In > Traits_
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
constexpr std::add_const_t< T > & as_const(T &t) noexcept
std::vector< InputHandle_t< In > > m_inputs
STL class.
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
const std::string & inputLocation(unsigned int n) const
T back_inserter(T...args)
MergingTransformer(const std::string &name, ISvcLocator *locator, const KeyValues &inputs, const KeyValue &output)
T transform(T...args)
T for_each(T...args)
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init)
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:192
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)