Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SplittingTransformer.h
Go to the documentation of this file.
1 #ifndef SPLITTING_TRANSFORMER_H
2 #define SPLITTING_TRANSFORMER_H
3 
4 #include <functional>
5 #include <string>
6 #include <vector>
7 
10 #include "GaudiKernel/apply.h"
11 
12 namespace Gaudi {
13  namespace Functional {
14 
15  template <typename Signature, typename Traits_ = Traits::useDefaults>
17 
18  template <typename Container>
20  template <typename Container>
22 
24  template <typename Out, typename... In, typename Traits_>
25  class SplittingTransformer<vector_of_<Out>( const In&... ), Traits_>
28 
29  public:
30  constexpr static std::size_t N = sizeof...( In );
33 
35  const KeyValues& output );
36 
37  SplittingTransformer( const std::string& name, ISvcLocator* locator, const KeyValue& input,
38  const KeyValues& output )
39  : SplittingTransformer( name, locator, std::array<KeyValue, 1>{input}, output ) {
40  static_assert( N == 1, "single input argument requires single input signature" );
41  }
42 
43  // accessor to output Locations
44  const std::string& outputLocation( unsigned int n ) const { return m_outputLocations.value()[n]; }
45  unsigned int outputLocationSize() const { return m_outputLocations.value().size(); }
46 
47  // derived classes can NOT implement execute
48  StatusCode execute() override final {
49  try {
50  // TODO:FIXME: how does operator() know the number and order of expected outputs?
51  using details::as_const;
52  auto out = details::filter_evtcontext_t<In...>::apply( *this, this->m_inputs );
53  if ( out.size() != m_outputs.size() ) {
54  throw GaudiException( "Error during transform: expected " + std::to_string( m_outputs.size() ) +
55  " containers, got " + std::to_string( out.size() ) + " instead",
56  this->name(), StatusCode::FAILURE );
57  }
58  for ( unsigned i = 0; i != out.size(); ++i ) details::put( m_outputs[i], std::move( out[i] ) );
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  // TODO/FIXME: how does the callee know in which order to produce the outputs?
67  // (note: 'missing' items can be specified by making Out an boost::optional<Out>,
68  // and only those entries which contain an Out are stored)
69  virtual vector_of_<Out> operator()( const In&... ) const = 0;
70 
71  private:
72  template <typename T>
75  Gaudi::Property<std::vector<std::string>> m_outputLocations; // TODO/FIXME for now: use a call-back to update the
76  // actual handles!
77  };
78 
79  template <typename Out, typename... In, typename Traits_>
81  const std::string& name, ISvcLocator* pSvcLocator, const std::array<KeyValue, N>& inputs,
82  const KeyValues& outputs )
83  : base_class( name, pSvcLocator, inputs )
84  , m_outputLocations( this, outputs.first, outputs.second,
85  [=]( Gaudi::Details::PropertyBase& ) {
86  this->m_outputs = details::make_vector_of_handles<decltype( this->m_outputs )>(
87  this, m_outputLocations );
88  if ( details::is_optional<Out>::value ) { // handle constructor does not (yet) allow to
89  // set optional flag... so
90  // do it explicitly here...
91  std::for_each( this->m_outputs.begin(), this->m_outputs.end(),
92  []( auto& h ) { h.setOptional( true ); } );
93  }
94  },
96  } // namespace Functional
97 } // namespace Gaudi
98 
99 #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
Implementation of property with value of concrete type.
Definition: Property.h:352
Gaudi::tagged_bool< class ImmediatelyInvokeHandler_tag > ImmediatelyInvokeHandler
Definition: Property.h:141
T to_string(T...args)
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
typename Gaudi::cpp17::is_detected< details2::is_optional_, Arg > is_optional
STL namespace.
details::OutputHandle_t< Traits_, details::remove_optional_t< T >> OutputHandle
class MergingTransformer< Out(const vector_of_const_< In > void
virtual const StatusCode & code() const
StatusCode for Exception.
constexpr double second
STL class.
int N
Definition: IOTest.py:99
class MergingTransformer< Out(const vector_of_const_< In > Traits_
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SplittingTransformer(const std::string &name, ISvcLocator *locator, const KeyValue &input, const KeyValues &output)
static auto apply(const Algorithm &algo, Handles &handles)
details::template vector_of_const_< Container > vector_of_
T move(T...args)
constexpr std::add_const_t< T > & as_const(T &t) noexcept
std::vector< InputHandle_t< In > > m_inputs
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
STL class.
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
Gaudi::cpp17::detected_or_t< DataObjectWriteHandle< T >, detail2::OutputHandle_t, Tr, T > OutputHandle_t
STL class.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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)