The Gaudi Framework  v30r4 (9b837755)
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 
6 namespace Gaudi
7 {
8  namespace Functional
9  {
10 
11  // Scalar->Vector adapted N->1 algorithm
12  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
14  template <typename ScalarOp, typename Out, typename... In, typename Traits_>
15  class ScalarTransformer<ScalarOp, Out( const In&... ), Traits_> : public Transformer<Out( const In&... ), Traits_>
16  {
17 
19  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
20 
21  public:
22  using Transformer<Out( const In&... ), Traits_>::Transformer;
23 
25  Out operator()( const In&... in ) const override final
26  {
27  const auto inrange = details::zip::const_range( in... );
28  Out out;
29  out.reserve( inrange.size() );
30  auto& scalar = scalarOp();
31  for ( const auto&& tuple : inrange ) {
34  [&out]( auto&& arg ) { details::insert( out, std::forward<decltype( arg )>( arg ) ); },
35  Gaudi::apply( [&]( const auto&... i ) { return scalar( details::deref( i )... ); }, tuple ) );
36  }
37  details::applyPostProcessing( scalar, out );
38  return out;
39  }
40  };
41 
42  // Scalar->Vector adapted N->M algorithm
43  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
45  template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
46  class MultiScalarTransformer<ScalarOp, std::tuple<Out...>( const In&... ), Traits_>
47  : public MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>
48  {
49 
51  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
52 
53  public:
54  using MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>::MultiTransformer;
55 
57  std::tuple<Out...> operator()( const In&... in ) const override final
58  {
59  const auto inrange = details::zip::const_range( in... );
60  std::tuple<Out...> out;
62  [sz = inrange.size()]( auto&&... o ) {
63 #if __cplusplus < 201703L
64  (void)std::initializer_list<int>{( o.reserve( sz ), 0 )...};
65 #else
66  ( o.reserve( sz ), ... );
67 #endif
68  },
69  out );
70  auto& scalar = scalarOp();
71  for ( const auto&& indata : inrange ) {
73  [&scalar, &indata]( auto&... out ) {
74 
79  [&out...]( auto&& outdata ) {
80  Gaudi::apply(
81  [&out...]( auto&&... outdata1 ) {
82 #if __cplusplus < 201703L
83  (void)std::initializer_list<int>{
84  ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), 0 )...};
85 #else
86  ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), ... );
87 #endif
88  },
89  std::forward<decltype( outdata )>( outdata ) );
90  },
91  Gaudi::apply( [&scalar]( const auto&... args ) { return scalar( details::deref( args )... ); },
92  indata ) );
93  },
94  out );
95  }
96  details::applyPostProcessing( scalar, out );
97  return out;
98  }
99  };
100  }
101 }
102 
103 #endif
constexpr struct Gaudi::Functional::details::insert_t insert
STL namespace.
class MergingTransformer< Out(const vector_of_const_< In > void
decltype(auto) constexpr apply(F &&f, Tuple &&t) noexcept(noexcept( detail::apply_impl(std::forward< F >(f), std::forward< Tuple >(t), std::make_index_sequence< std::tuple_size< std::remove_reference_t< Tuple >>::value >{})))
Definition: apply.h:31
constexpr struct Gaudi::Functional::details::deref_t deref
constexpr struct Gaudi::Functional::details::invoke_optionally_t invoke_optionally
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
std::tuple< Out... > operator()(const In &...in) const override final
The main operator.
const ScalarOp & scalarOp() const
Access the scalar operator.
Out operator()(const In &...in) const override final
The main operator.
struct[[deprecated("use MergingTransformer instead")]] Traits_
decltype(auto) const_range(Args &&...args)
Zips multiple containers together to form a single const range.
T forward(T...args)
Helper functions to set/get the application return code.
Definition: __init__.py:1