| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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 <utility>
5 #include "GaudiAlg/Transformer.h"
6
7 namespace Gaudi { namespace Functional {
8
9 // Scalar->Vector adapted N->1 algorithm
10 template <typename ScalarOp,
11 typename TransformerSignature,
12 typename Traits_ = Traits::useDefaults> class ScalarTransformer;
13 template <typename ScalarOp, typename Out, typename... In, typename Traits_>
14 class ScalarTransformer<ScalarOp,Out(const In&...),Traits_> : public Transformer<Out(const In&...),Traits_>
15 {
16
18 const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>(*this); }
19
20 private:
21
23 template< typename Tuple, typename Scalar, std::size_t... I >
24 inline decltype(auto) getScalar( const Tuple & t,
25 const Scalar & s,
26 std::index_sequence<I...> ) const
27 {
28 return s( details::deref(std::get<I>(t))... );
29 }
30
31 public:
32
33 using Transformer<Out(const In&...),Traits_>::Transformer;
34
36 Out operator()(const In&... in) const override final
37 {
38 const auto inrange = details::zip::const_range(in...);
39 Out out;
40 out.reserve(inrange.size());
41 auto & scalar = scalarOp();
42 for ( const auto && i : inrange )
43 { details::insert( out, getScalar( i, scalar, std::index_sequence_for<In...>{} ) ); }
44 //details::apply( scalar, out ); // awaiting a post-processor call
45 return out;
46 }
47
48 };
49
50 // Scalar->Vector adapted N->M algorithm
51 template <typename ScalarOp,
52 typename TransformerSignature,
53 typename Traits_ = Traits::useDefaults> class MultiScalarTransformer;
54 template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
55 class MultiScalarTransformer<ScalarOp,std::tuple<Out...>(const In&...),Traits_>
56 : public MultiTransformer<std::tuple<Out...>(const In&...),Traits_>
57 {
58
60 const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>(*this); }
61
62 private:
63
65 template< typename Tuple, std::size_t... I >
66 inline void reserve( Tuple & t,
67 const std::size_t resSize,
68 std::index_sequence<I...> ) const
69 {
70 std::initializer_list<long unsigned int> { (std::get<I>(t).reserve(resSize),I)... };
71 }
72
74 template< typename Tuple, typename Scalar, std::size_t... I >
75 inline decltype(auto) getScalar( const Tuple & t,
76 const Scalar & s,
77 std::index_sequence<I...> ) const
78 {
79 return s( details::deref(std::get<I>(t))... );
80 }
81
83 template< typename InTuple, typename OutTuple, std::size_t... I >
84 void insert( InTuple && in, OutTuple & out, std::index_sequence<I...> ) const
85 {
86 if ( in )
87 { std::initializer_list<long unsigned int>
88 { ( details::insert( std::get<I>(out), std::move(std::get<I>(*in)) ), I )... }; }
89 }
90
91 public:
92
93 using MultiTransformer<std::tuple<Out...>(const In&...),Traits_>::MultiTransformer;
94
96 std::tuple<Out...> operator()(const In&... in) const final
97 {
98 const auto inrange = details::zip::const_range(in...);
99 std::tuple<Out...> out;
100 reserve( out, inrange.size(), std::index_sequence_for<Out...>{} );
101 auto & scalar = scalarOp();
102 for ( const auto && i : inrange )
103 {
104 insert( getScalar( i, scalar, std::index_sequence_for<In...>{} ), out,
105 std::index_sequence_for<Out...>{} );
106 }
107 //details::apply( scalar, out ); // awaiting a post-processor call
108 return out;
109 }
110
111 };
112
113 }}
114
115 #endif
Transformer.h
Gaudi::Functional::MultiScalarTransformer
Definition: ScalarTransformer.h:53
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:84
std
STL namespace.
std::size_t
Gaudi::Functional::Traits::use_
Definition: FunctionalUtilities.h:59
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:96
Gaudi::Functional::Traits_
class MergingTransformer< Out(const vector_of_const_< In > Traits_
Definition: MergingTransformer.h:19
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:66
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:18
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:60
std::move
T move(T...args)
Gaudi::Functional::Transformer
Definition: Transformer.h:18
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:36
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:66
gaudirun.s
string s
Definition: gaudirun.py:245
Gaudi::Functional::MultiTransformer
Definition: Transformer.h:53
Gaudi::Functional::ScalarTransformer
Definition: ScalarTransformer.h:12
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::initializer_list
GaudiPython.GaudiAlgs.Tuple
Tuple
Definition: GaudiAlgs.py:1041