The Gaudi Framework  v29r0 (ff2e7097)
ScalarTransformer.h
Go to the documentation of this file.
1 #ifndef SCALAR_TRANSFORMER_H
2 #define SCALAR_TRANSFORMER_H
3 
4 #include "GaudiAlg/Transformer.h"
5 #include <utility>
6 
7 namespace Gaudi
8 {
9  namespace Functional
10  {
11 
12  // Scalar->Vector adapted N->1 algorithm
13  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
15  template <typename ScalarOp, typename Out, typename... In, typename Traits_>
16  class ScalarTransformer<ScalarOp, Out( const In&... ), Traits_> : public Transformer<Out( const In&... ), Traits_>
17  {
18 
20  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
21 
22  private:
24  template <typename Tuple, typename Scalar, std::size_t... I>
25  inline decltype( auto ) getScalar( const Tuple& t, const Scalar& s, std::index_sequence<I...> ) const
26  {
27  return s( details::deref( std::get<I>( t ) )... );
28  }
29 
30  public:
31  using Transformer<Out( const In&... ), Traits_>::Transformer;
32 
34  Out operator()( const In&... in ) const override final
35  {
36  const auto inrange = details::zip::const_range( in... );
37  Out out;
38  out.reserve( inrange.size() );
39  auto& scalar = scalarOp();
40  for ( const auto&& i : inrange ) {
41  details::insert( out, getScalar( i, scalar, std::index_sequence_for<In...>{} ) );
42  }
43  details::applyPostProcessing( scalar, out ); // awaiting a post-processor call
44  return out;
45  }
46  };
47 
48  // Scalar->Vector adapted N->M algorithm
49  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
51  template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
52  class MultiScalarTransformer<ScalarOp, std::tuple<Out...>( const In&... ), Traits_>
53  : public MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>
54  {
55 
57  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
58 
59  private:
61  template <typename Tuple, std::size_t... I>
62  inline void reserve( Tuple& t, const std::size_t resSize, std::index_sequence<I...> ) const
63  {
64  std::initializer_list<long unsigned int>{( std::get<I>( t ).reserve( resSize ), I )...};
65  }
66 
68  template <typename Tuple, typename Scalar, std::size_t... I>
69  inline decltype( auto ) getScalar( const Tuple& t, const Scalar& s, std::index_sequence<I...> ) const
70  {
71  return s( details::deref( std::get<I>( t ) )... );
72  }
73 
75  template <typename InTuple, typename OutTuple, std::size_t... I>
76  void insert( InTuple&& in, OutTuple& out, std::index_sequence<I...> ) const
77  {
78  if ( in ) {
80  ( details::insert( std::get<I>( out ), std::move( std::get<I>( *in ) ) ), I )...};
81  }
82  }
83 
84  public:
85  using MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>::MultiTransformer;
86 
88  std::tuple<Out...> operator()( const In&... in ) const final
89  {
90  const auto inrange = details::zip::const_range( in... );
91  std::tuple<Out...> out;
92  reserve( out, inrange.size(), std::index_sequence_for<Out...>{} );
93  auto& scalar = scalarOp();
94  for ( const auto&& i : inrange ) {
95  insert( getScalar( i, scalar, std::index_sequence_for<In...>{} ), out, std::index_sequence_for<Out...>{} );
96  }
97  details::applyPostProcessing( scalar, out ); // awaiting a post-processor call
98  return out;
99  }
100  };
101  }
102 }
103 
104 #endif
constexpr struct Gaudi::Functional::details::insert_t insert
void insert(InTuple &&in, OutTuple &out, std::index_sequence< I... >) const
Insert the returned tuple of objects into the correct containers.
STL namespace.
constexpr struct Gaudi::Functional::details::deref_t deref
std::tuple< Out... > operator()(const In &...in) const final
The main operator.
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
void reserve(Tuple &t, const std::size_t resSize, std::index_sequence< I... >) const
Reserve the given size in all output containers.
const ScalarOp & scalarOp() const
Access the scalar operator.
T move(T...args)
Out operator()(const In &...in) const override final
The main operator.
string s
Definition: gaudirun.py:253
struct[[deprecated("use MergingTransformer instead")]] Traits_
decltype(auto) const_range(Args &&...args)
Zips multiple containers together to form a single const range.
Helper functions to set/get the application return code.
Definition: __init__.py:1