| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
14 class ScalarTransformer;
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>
50 class MultiScalarTransformer;
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 ) {
79 std::initializer_list<long unsigned int>{
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
Transformer.h
Gaudi::Functional::MultiScalarTransformer
Definition: ScalarTransformer.h:50
Gaudi::Functional::details::insert
constexpr struct Gaudi::Functional::details::insert_t insert
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::insert
void insert(InTuple &&in, OutTuple &out, std::index_sequence< I... >) const
Insert the returned tuple of objects into the correct containers.
Definition: ScalarTransformer.h:76
std
STL namespace.
std::size_t
Gaudi::Functional::details::deref
constexpr struct Gaudi::Functional::details::deref_t deref
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::operator()
std::tuple< Out... > operator()(const In &...in) const final
The main operator.
Definition: ScalarTransformer.h:88
Gaudi::Functional::details::applyPostProcessing
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
Definition: FunctionalDetails.h:579
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::reserve
void reserve(Tuple &t, const std::size_t resSize, std::index_sequence< I... >) const
Reserve the given size in all output containers.
Definition: ScalarTransformer.h:62
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:20
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:57
std::move
T move(T...args)
Gaudi::Functional::Transformer
Definition: Transformer.h:22
std::tuple
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::operator()
Out operator()(const In &...in) const override final
The main operator.
Definition: ScalarTransformer.h:34
gaudirun.s
string s
Definition: gaudirun.py:253
Gaudi::Functional::Traits_
struct[[deprecated("use MergingTransformer instead")]] Traits_
Definition: ListTransformer.h:14
Gaudi::Functional::MultiTransformer
Definition: Transformer.h:59
Gaudi::Functional::ScalarTransformer
Definition: ScalarTransformer.h:14
Gaudi::Functional::details::zip::const_range
decltype(auto) const_range(Args &&...args)
Zips multiple containers together to form a single const range.
Definition: FunctionalDetails.h:94
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::initializer_list
GaudiPython.GaudiAlgs.Tuple
Tuple
Definition: GaudiAlgs.py:1130