Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FunctionalTool.h
Go to the documentation of this file.
1 /*****************************************************************************\
2 * (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration *
3 * *
4 * This software is distributed under the terms of the GNU General Public *
5 * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
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 \*****************************************************************************/
13 #include "GaudiKernel/IBinder.h"
14 
15 #define GAUDI_FUNCTIONAL_TOOL_BINDER_USES_CREATE
16 
17 namespace Gaudi::Functional {
18  namespace details {
19  // add a baseclass in case it isn't defined yet...
20  template <typename Tr, typename Base = FixTESPath<AlgTool>>
21  using add_base_t = std::conditional_t<Gaudi::cpp17::is_detected_v<detail2::BaseClass_t, Tr>, Tr,
23 
24  template <typename Signature, typename Traits>
25  class ToolBinder;
26 
27  template <typename IFace, typename... Args, typename Traits>
28  class ToolBinder<Gaudi::Interface::Bind::Box<IFace>( Args const&... ), Traits>
29  : public extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>> {
30 
31  constexpr static std::size_t N = sizeof...( Args );
32 
33  template <typename IArgs, std::size_t... I>
35  Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ),
36  std::index_sequence<I...> )
37  : extends<details::BaseClass_t<Traits>, Gaudi::Interface::Bind::IBinder<IFace>>{ std::move( type ),
38  std::move( name ), parent }
39  , m_handles{ std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )... }
40  , m_creator{ creator } {}
41 
43  Gaudi::Interface::Bind::Box<IFace> ( *m_creator )( void const*, Args const&... );
44 
45  public:
49  Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ) )
50  : ToolBinder{ std::move( type ), std::move( name ), parent, inputs, creator, std::make_index_sequence<N>{} } {
51  }
52 
54  return std::apply(
55  [&]( auto const&... arg ) {
56  using namespace details;
57  return std::invoke( m_creator, this, get( arg, *this, ctx )... );
58  },
59  m_handles );
60  }
61 
62  template <std::size_t N = 0>
63  decltype( auto ) inputLocation() const {
64  using namespace details;
65  return getKey( std::get<N>( m_handles ) );
66  }
67  template <typename T>
68  decltype( auto ) inputLocation() const {
69  using namespace details;
70  return getKey( std::get<InputHandle_t<Traits, std::decay_t<T>>>( m_handles ) );
71  }
72 
73  // TODO: make this a callable instance?
74  template <typename BoundInstance, typename Self>
75  static auto construct( Self* ) {
76  static_assert( std::is_base_of_v<ToolBinder, Self> );
77  return +[]( void const* ptr, const Args&... args ) {
78  return Gaudi::Interface::Bind::Box<IFace>{ std::in_place_type<BoundInstance>,
79  static_cast<std::add_const_t<Self>*>( ptr ), args... };
80  };
81  }
82  };
83  } // namespace details
84 
85  template <typename Signature, typename Traits_ = Traits::use_<Traits::BaseClass_t<AlgTool>>>
87 
88 } // namespace Gaudi::Functional
Gaudi::Functional::details::add_base_t
std::conditional_t< Gaudi::cpp17::is_detected_v< detail2::BaseClass_t, Tr >, Tr, Traits::use_< Tr, BaseClass_t< Base > >> add_base_t
Definition: FunctionalTool.h:22
std::string
STL class.
IOTest.N
N
Definition: IOTest.py:110
std::move
T move(T... args)
Gaudi::Functional::details::InputHandle_t
Gaudi::cpp17::detected_or_t< detail2::DefaultInputHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
Definition: FunctionalDetails.h:423
std::pair< std::string, std::string >
Gaudi::Interface::Bind::Box
Definition: IBinder.h:23
Gaudi::Functional::details::ToolBinder< Gaudi::Interface::Bind::Box< IFace >(Args const &...), Traits >::bind
Gaudi::Interface::Bind::Box< IFace > bind(EventContext const &ctx) const final
Definition: FunctionalTool.h:53
std::tuple
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: FunctionalDetails.h:444
TimingHistograms.name
name
Definition: TimingHistograms.py:25
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:588
details
Definition: AnyDataWrapper.h:18
Gaudi::Functional::Traits::use_
Definition: FunctionalUtilities.h:68
Gaudi::Functional::details::ToolBinder< Gaudi::Interface::Bind::Box< IFace >(Args const &...), Traits >::m_handles
std::tuple< details::InputHandle_t< Traits, Args >... > m_handles
Definition: FunctionalTool.h:42
Write.creator
creator
Definition: Write.py:23
Gaudi::Functional::details::ToolBinder< Gaudi::Interface::Bind::Box< IFace >(Args const &...), Traits >::construct
static auto construct(Self *)
Definition: FunctionalTool.h:75
Gaudi::Functional
Definition: Consumer.h:19
std::forward_as_tuple
T forward_as_tuple(T... args)
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
IBinder.h
FunctionalUtilities.h
gaudirun.type
type
Definition: gaudirun.py:162
gaudirun.args
args
Definition: gaudirun.py:338
IInterface
Definition: IInterface.h:237
EventContext
Definition: EventContext.h:34
Gaudi::Functional::details::RepeatValues_
decltype(get_values_helper< Value >(std::make_index_sequence< N >())) RepeatValues_
Definition: FunctionalDetails.h:167
Gaudi::Functional::details::ToolBinder
Definition: FunctionalTool.h:25
std::tuple_cat
T tuple_cat(T... args)
std::size_t
Gaudi::Functional::details::BaseClass_t
Gaudi::cpp17::detected_or_t< Base, detail2::BaseClass_t, Tr > BaseClass_t
Definition: FunctionalDetails.h:414
FunctionalDetails.h
Gaudi::Functional::details::ToolBinder< Gaudi::Interface::Bind::Box< IFace >(Args const &...), Traits >::ToolBinder
ToolBinder(std::string type, std::string name, const IInterface *parent, Gaudi::Functional::details::RepeatValues_< KeyValue, N > const &inputs, Gaudi::Interface::Bind::Box< IFace >(*creator)(void const *, Args const &...))
Definition: FunctionalTool.h:47
Gaudi::Functional::details::ToolBinder< Gaudi::Interface::Bind::Box< IFace >(Args const &...), Traits >::ToolBinder
ToolBinder(std::string type, std::string name, const IInterface *parent, IArgs &&args, Gaudi::Interface::Bind::Box< IFace >(*creator)(void const *, Args const &...), std::index_sequence< I... >)
Definition: FunctionalTool.h:34
Gaudi::Functional::details::getKey
auto getKey(const Handle &h) -> decltype(h.objKey())
Definition: FunctionalDetails.h:456