| The Gaudi Framework v32r1 (f65d50dc)

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::Functional {
7
8 // Scalar->Vector adapted N->1 algorithm
9 template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
10 class ScalarTransformer;
11 template <typename ScalarOp, typename Out, typename... In, typename Traits_>
12 class ScalarTransformer<ScalarOp, Out( const In&... ), Traits_> : public Transformer<Out( const In&... ), Traits_> {
13
15 const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
16
17 public:
18 using Transformer<Out( const In&... ), Traits_>::Transformer;
19
21 Out operator()( const In&... in ) const override final {
22 const auto inrange = details::zip::const_range( in... );
23 Out out;
24 out.reserve( inrange.size() );
25 auto& scalar = scalarOp();
26 for ( const auto&& tuple : inrange ) {
28 details::invoke_optionally(
29 [&out]( auto&& arg ) { details::insert( out, std::forward<decltype( arg )>( arg ) ); },
30 std::apply( [&]( const auto&... i ) { return scalar( details::deref( i )... ); }, tuple ) );
31 }
32 details::applyPostProcessing( scalar, out );
33 return out;
34 }
35 };
36
37 // Scalar->Vector adapted N->M algorithm
38 template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
39 class MultiScalarTransformer;
40 template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
41 class MultiScalarTransformer<ScalarOp, std::tuple<Out...>( const In&... ), Traits_>
42 : public MultiTransformer<std::tuple<Out...>( const In&... ), Traits_> {
43
45 const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
46
47 public:
48 using MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>::MultiTransformer;
49
51 std::tuple<Out...> operator()( const In&... in ) const override final {
52 const auto inrange = details::zip::const_range( in... );
53 std::tuple<Out...> out;
54 std::apply( [sz = inrange.size()]( auto&&... o ) { ( o.reserve( sz ), ... ); }, out );
55 auto& scalar = scalarOp();
56 for ( const auto&& indata : inrange ) {
57 std::apply(
58 [&scalar, &indata]( auto&... out ) {
62 details::invoke_optionally(
63 [&out...]( auto&& outdata ) {
64 std::apply(
65 [&out...]( auto&&... outdata1 ) {
66 ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), ... );
67 },
68 std::forward<decltype( outdata )>( outdata ) );
69 },
70 std::apply( [&scalar]( const auto&... args ) { return scalar( details::deref( args )... ); },
71 indata ) );
72 },
73 out );
74 }
75 details::applyPostProcessing( scalar, out );
76 return out;
77 }
78 };
79 } // namespace Gaudi::Functional
80
81 #endif
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:45
Transformer.h
Gaudi::Functional::MultiScalarTransformer
Definition: ScalarTransformer.h:39
Gaudi::Functional::details::insert
constexpr struct Gaudi::Functional::details::insert_t insert
std
STL namespace.
Gaudi ::Functional::MultiTransformer
details::MultiTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MultiTransformer
Definition: Transformer.h:217
Gaudi::Functional
Definition: Consumer.h:8
Gaudi::Functional::details::deref
constexpr struct Gaudi::Functional::details::deref_t deref
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::operator()
Out operator()(const In &... in) const override final
The main operator.
Definition: ScalarTransformer.h:21
Gaudi::Functional::details::invoke_optionally
constexpr struct Gaudi::Functional::details::invoke_optionally_t invoke_optionally
gaudirun.args
args
Definition: gaudirun.py:307
Gaudi::Functional::details::applyPostProcessing
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
Definition: FunctionalDetails.h:560
Gaudi ::Functional::Transformer
details::Transformer< Signature, Traits_, details::isLegacy< Traits_ > > Transformer
Definition: Transformer.h:214
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:80
std::tuple
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:15
Gaudi::Functional::ScalarTransformer
Definition: ScalarTransformer.h:10
std::forward
T forward(T... args)
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::operator()
std::tuple< Out... > operator()(const In &... in) const override final
The main operator.
Definition: ScalarTransformer.h:51