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,
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,
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 )
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
constexpr struct Gaudi::Functional::details::insert_t insert
void insert(InTuple &&in, OutTuple &out, std::index_sequence< I... >) const
Insert the returned tuple of objects into the correct containers.
STL namespace.
constexpr struct Gaudi::Functional::details::deref_t deref
std::tuple< Out... > operator()(const In &...in) const final
The main operator.
class MergingTransformer< Out(const vector_of_const_< In > Traits_
void reserve(Tuple &t, const std::size_t resSize, std::index_sequence< I... >) const
Reserve the given size in all output containers.
const ScalarOp & scalarOp() const
Access the scalar operator.
T move(T...args)
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.
string s
Definition: gaudirun.py:245
Helper functions to set/get the application return code.
Definition: __init__.py:1