The Gaudi Framework  master (37c0b60a)
ScalarTransformer.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include "Transformer.h"
14 
15 namespace Gaudi::Functional {
16 
17  // Scalar->Vector adapted N->1 algorithm
18  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
20  template <typename ScalarOp, typename Out, typename... In, typename Traits_>
21  class ScalarTransformer<ScalarOp, Out( const In&... ), Traits_> : public Transformer<Out( const In&... ), Traits_> {
22 
24  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
25 
26  public:
27  using Transformer<Out( const In&... ), Traits_>::Transformer;
28 
30  Out operator()( const In&... in ) const override final {
31  const auto inrange = details::zip::range( in... );
32  Out out;
33  out.reserve( inrange.size() );
34  auto& scalar = scalarOp();
35  for ( const auto&& tuple : inrange ) {
38  [&out]( auto&& arg ) { details::insert( out, std::forward<decltype( arg )>( arg ) ); },
39  std::apply( [&]( const auto&... i ) { return scalar( details::deref( i )... ); }, tuple ) );
40  }
42  return out;
43  }
44  };
45 
46  // Scalar->Vector adapted N->M algorithm
47  template <typename ScalarOp, typename TransformerSignature, typename Traits_ = Traits::useDefaults>
49  template <typename ScalarOp, typename... Out, typename... In, typename Traits_>
50  class MultiScalarTransformer<ScalarOp, std::tuple<Out...>( const In&... ), Traits_>
51  : public MultiTransformer<std::tuple<Out...>( const In&... ), Traits_> {
52 
54  const ScalarOp& scalarOp() const { return static_cast<const ScalarOp&>( *this ); }
55 
56  public:
57  using MultiTransformer<std::tuple<Out...>( const In&... ), Traits_>::MultiTransformer;
58 
60  std::tuple<Out...> operator()( const In&... in ) const override final {
61  const auto inrange = details::zip::range( in... );
62  std::tuple<Out...> out;
63  std::apply( [sz = inrange.size()]( auto&&... o ) { ( o.reserve( sz ), ... ); }, out );
64  auto& scalar = scalarOp();
65  for ( const auto&& indata : inrange ) {
66  std::apply(
67  [&scalar, &indata]( auto&... out ) {
72  [&out...]( auto&& outdata ) {
73  GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN
74  std::apply(
75  [&out...]( auto&&... outdata1 ) {
76  ( details::insert( out, std::forward<decltype( outdata1 )>( outdata1 ) ), ... );
77  },
78  std::forward<decltype( outdata )>( outdata ) );
80  },
81  std::apply( [&scalar]( const auto&... args ) { return scalar( details::deref( args )... ); },
82  indata ) );
83  },
84  out );
85  }
87  return out;
88  }
89  };
90 } // namespace Gaudi::Functional
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::operator()
Out operator()(const In &... in) const override final
The main operator.
Definition: ScalarTransformer.h:30
Gaudi::Functional::details::invoke_optionally
constexpr struct Gaudi::Functional::details::invoke_optionally_t invoke_optionally
Gaudi::Functional::details::applyPostProcessing
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
Definition: details.h:701
std::tuple
Gaudi::Functional::ScalarTransformer< ScalarOp, Out(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:24
std::forward
T forward(T... args)
Gaudi::Functional::details::deref
constexpr struct Gaudi::Functional::details::deref_t deref
Gaudi::Functional::ScalarTransformer
Definition: ScalarTransformer.h:19
Transformer.h
Gaudi::Functional
Definition: Consumer.h:19
GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
#define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
Definition: details.h:40
Gaudi::Functional::MultiScalarTransformer
Definition: ScalarTransformer.h:48
Gaudi ::Functional::MultiTransformer
details::MultiTransformer< Signature, Traits_, details::isLegacy< Traits_ > > MultiTransformer
Definition: Transformer.h:240
Gaudi::Functional::MultiScalarTransformer< ScalarOp, std::tuple< Out... >(const In &...), Traits_ >::scalarOp
const ScalarOp & scalarOp() const
Access the scalar operator.
Definition: ScalarTransformer.h:54
gaudirun.args
args
Definition: gaudirun.py:336
std
STL namespace.
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:60
Gaudi ::Functional::Transformer
details::Transformer< Signature, Traits_, details::isLegacy< Traits_ > > Transformer
Definition: Transformer.h:237
Gaudi::Functional::details::insert
constexpr struct Gaudi::Functional::details::insert_t insert
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: details.h:97
PrepareBase.out
out
Definition: PrepareBase.py:20