Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  namespace Functional {
8 
9  // Scalar->Vector adapted N->1 algorithm
10  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
12  template <typename ScalarOp, typename Out, typename... In, typename Traits_>
13  class ScalarTransformer<ScalarOp, Out( const In&... ), Traits_> : public Transformer<Out( const In&... ), Traits_> {
14 
16  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
17 
18  public:
19  using Transformer<Out( const In&... ), Traits_>::Transformer;
20 
22  Out operator()( const In&... in ) const override final {
23  const auto inrange = details::zip::const_range( in... );
24  Out out;
25  out.reserve( inrange.size() );
26  auto& scalar = scalarOp();
27  for ( const auto&& tuple : inrange ) {
30  [&out]( auto&& arg ) { details::insert( out, std::forward<decltype( arg )>( arg ) ); },
31  Gaudi::apply( [&]( const auto&... i ) { return scalar( details::deref( i )... ); }, tuple ) );
32  }
33  details::applyPostProcessing( scalar, out );
34  return out;
35  }
36  };
37 
38  // Scalar->Vector adapted N->M algorithm
39  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
41  template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
42  class MultiScalarTransformer<ScalarOp, std::tuple<Out...>( const In&... ), Traits_>
43  : public MultiTransformer<std::tuple<Out...>( const In&... ), Traits_> {
44 
46  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
47 
48  public:
49  using MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>::MultiTransformer;
50 
52  std::tuple<Out...> operator()( const In&... in ) const override final {
53  const auto inrange = details::zip::const_range( in... );
54  std::tuple<Out...> out;
56  [sz = inrange.size()]( auto&&... o ) {
57 #if __cplusplus < 201703L
58  (void)std::initializer_list<int>{( o.reserve( sz ), 0 )...};
59 #else
60  ( o.reserve( sz ), ... );
61 #endif
62  },
63  out );
64  auto& scalar = scalarOp();
65  for ( const auto&& indata : inrange ) {
67  [&scalar, &indata]( auto&... out ) {
72  [&out...]( auto&& outdata ) {
73  Gaudi::apply(
74  [&out...]( auto&&... outdata1 ) {
75 #if __cplusplus < 201703L
76  (void)std::initializer_list<int>{
77  ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), 0 )...};
78 #else
79  ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), ... );
80 #endif
81  },
82  std::forward<decltype( outdata )>( outdata ) );
83  },
84  Gaudi::apply( [&scalar]( const auto&... args ) { return scalar( details::deref( args )... ); },
85  indata ) );
86  },
87  out );
88  }
89  details::applyPostProcessing( scalar, out );
90  return out;
91  }
92  };
93  } // namespace Functional
94 } // namespace Gaudi
95 
96 #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:27
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...)
class MergingTransformer< Out(const vector_of_const_< In > Traits_
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.
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