The Gaudi Framework  master (37c0b60a)
ToolBinder.h
Go to the documentation of this file.
1 /*****************************************************************************\
2 * (c) Copyright 2021-2023 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 \*****************************************************************************/
11 #pragma once
12 
13 #include "details.h"
14 #include "utilities.h"
15 #include <GaudiKernel/IBinder.h>
16 
17 #define GAUDI_FUNCTIONAL_TOOL_BINDER_USES_CREATE
18 
19 namespace Gaudi::Functional {
20  namespace details {
21  template <typename Signature, typename Traits>
22  class ToolBinder;
23 
24  template <typename IFace, typename... Args, typename Traits>
25  class ToolBinder<Gaudi::Interface::Bind::Box<IFace>( Args const&... ), Traits>
26  : public extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>> {
27 
28  constexpr static std::size_t N = sizeof...( Args );
29 
30  template <typename IArgs, std::size_t... I>
32  Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ),
33  std::index_sequence<I...> )
34  : extends<details::BaseClass_t<Traits>, Gaudi::Interface::Bind::IBinder<IFace>>{ std::move( type ),
35  std::move( name ), parent }
36  , m_handles{ std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )... }
37  , m_creator{ creator } {}
38 
40  Gaudi::Interface::Bind::Box<IFace> ( *m_creator )( void const*, Args const&... );
41 
42  public:
46  Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ) )
47  : ToolBinder{ std::move( type ), std::move( name ), parent, inputs, creator, std::make_index_sequence<N>{} } {
48  }
49 
51  return std::apply(
52  [&]( auto const&... arg ) {
53  using namespace details;
54  return std::invoke( m_creator, this, get( arg, *this, ctx )... );
55  },
56  m_handles );
57  }
58 
59  template <std::size_t N = 0>
60  decltype( auto ) inputLocation() const {
61  using namespace details;
62  return getKey( std::get<N>( m_handles ) );
63  }
64  template <typename T>
65  decltype( auto ) inputLocation() const {
66  using namespace details;
67  return getKey( std::get<InputHandle_t<Traits, std::decay_t<T>>>( m_handles ) );
68  }
69 
70  // TODO: make this a callable instance?
71  template <typename BoundInstance, typename Self>
72  static auto construct( Self* ) {
73  static_assert( std::is_base_of_v<ToolBinder, Self> );
74  return +[]( void const* ptr, const Args&... args ) {
75  return Gaudi::Interface::Bind::Box<IFace>{ std::in_place_type<BoundInstance>,
76  static_cast<std::add_const_t<Self>*>( ptr ), args... };
77  };
78  }
79  };
80  } // namespace details
81 
82  template <typename Signature, typename Traits_ = Traits::use_<Traits::BaseClass_t<AlgTool>>>
84 
85 } // namespace Gaudi::Functional
std::string
STL class.
IOTest.N
N
Definition: IOTest.py:112
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: details.h:425
std::pair< std::string, std::string >
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
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: ToolBinder.h:50
std::tuple
Gaudi::Functional::details::get
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition: details.h:446
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
details
Definition: AnyDataWrapper.h:19
Gaudi::Functional::details::ToolBinder< Gaudi::Interface::Bind::Box< IFace >(Args const &...), Traits >::m_handles
std::tuple< details::InputHandle_t< Traits, Args >... > m_handles
Definition: ToolBinder.h:39
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: ToolBinder.h:72
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
utilities.h
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
IBinder.h
gaudirun.type
type
Definition: gaudirun.py:160
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
gaudirun.args
args
Definition: gaudirun.py:336
IInterface
Definition: IInterface.h:239
EventContext
Definition: EventContext.h:34
Gaudi::Functional::details::RepeatValues_
decltype(get_values_helper< Value >(std::make_index_sequence< N >())) RepeatValues_
Definition: details.h:162
Gaudi::Functional::details::ToolBinder
Definition: ToolBinder.h:22
std::tuple_cat
T tuple_cat(T... args)
std::size_t
details.h
Gaudi::Functional::details::BaseClass_t
Gaudi::cpp17::detected_or_t< Base, detail2::BaseClass_t, Tr > BaseClass_t
Definition: details.h:416
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: ToolBinder.h:44
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: ToolBinder.h:31
Gaudi::Functional::details::getKey
auto getKey(const Handle &h) -> decltype(h.objKey())
Definition: details.h:458