The Gaudi Framework  v29r0 (ff2e7097)
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 {
13  namespace Functional
14  {
15 
16  template <typename Signature, typename Traits_ = Traits::useDefaults>
18 
20 
22  template <typename Out, typename In, typename Traits_>
23  class MergingTransformer<Out( const vector_of_const_<In>& ), Traits_>
25  {
27 
28  public:
31 
33  const KeyValue& output );
34 
35  // derived classes can NOT implement execute
36  StatusCode execute() override final;
37 
38  virtual Out operator()( const vector_of_const_<In>& inputs ) const = 0;
39 
40  private:
41  // if In is a pointer, it signals optional (as opposed to mandatory) input
42  template <typename T>
43  using InputHandle_t = details::InputHandle_t<Traits_, typename std::remove_pointer<T>::type>;
44  std::vector<std::string> m_inputLocations; // TODO/FIXME: remove this duplication...
45  std::vector<InputHandle_t<In>> m_inputs; // and make the handles properties instead...
46  };
47 
48  template <typename Out, typename In, typename Traits_>
49  MergingTransformer<Out( const vector_of_const_<In>& ), Traits_>::MergingTransformer( const std::string& name,
50  ISvcLocator* pSvcLocator,
51  const KeyValues& inputs,
52  const KeyValue& output )
53  : base_class( name, pSvcLocator, output ), m_inputLocations( inputs.second )
54  {
55  // TODO/FIXME: replace vector of string property + call-back with a
56  // vector<handle> property ... as soon as declareProperty can deal with that.
57  auto p = this->declareProperty( inputs.first, m_inputLocations );
58  p->declareUpdateHandler( [=]( Gaudi::Details::PropertyBase& ) {
59  this->m_inputs = details::make_vector_of_handles<decltype( this->m_inputs )>( this, m_inputLocations,
61  if ( std::is_pointer<In>::value ) { // handle constructor does not (yet) allow to set optional flag... so do it
62  // explicitly here...
63  std::for_each( this->m_inputs.begin(), this->m_inputs.end(), []( auto& h ) { h.setOptional( true ); } );
64  }
65  } );
66  p->useUpdateHandler(); // invoke call-back now, to be sure the input handles are synced with the property...
67  }
68 
69  template <typename Out, typename In, typename Traits_>
71  {
72  vector_of_const_<In> ins;
73  ins.reserve( m_inputs.size() );
74  std::transform( m_inputs.begin(), m_inputs.end(), std::back_inserter( ins ),
76  try {
77  using details::as_const;
78  details::put( std::get<0>( this->m_outputs ), as_const( *this )( as_const( ins ) ) );
79  } catch ( GaudiException& e ) {
80  ( e.code() ? this->warning() : this->error() ) << e.message() << endmsg;
81  return e.code();
82  }
83  return StatusCode::SUCCESS;
84  }
85  }
86 }
87 
88 #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.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init, Gaudi::DataHandle::Mode mode)
StatusCode execute() override final
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
STL namespace.
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.
constexpr double second
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, TYPE &value, const std::string &doc="none")
Declare a property (templated)
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
std::vector< std::string > m_inputLocations
std::vector< InputHandle_t< In > > m_inputs
T back_inserter(T...args)
MergingTransformer(const std::string &name, ISvcLocator *locator, const KeyValues &inputs, const KeyValue &output)
struct[[deprecated("use MergingTransformer instead")]] Traits_
T transform(T...args)
T for_each(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)