The Gaudi Framework  v36r7 (7f57a304)
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 \*****************************************************************************/
12 #include "GaudiKernel/IBinder.h"
13 
14 #define GAUDI_FUNCTIONAL_TOOL_BINDER_USES_CREATE
15 
16 namespace Gaudi::Functional {
17  namespace details {
18  // add a baseclass in case it isn't defined yet...
19  template <typename Tr, typename Base = FixTESPath<AlgTool>>
20  using add_base_t = std::conditional_t<Gaudi::cpp17::is_detected_v<detail2::BaseClass_t, Tr>, Tr,
22 
23  template <typename Signature, typename Traits>
24  class ToolBinder;
25 
26  template <typename IFace, typename... Args, typename Traits>
27  class ToolBinder<Gaudi::Interface::Bind::Box<IFace>( Args const&... ), Traits>
28  : public extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>> {
29 
30  constexpr static std::size_t N = sizeof...( Args );
31 
32  template <typename IArgs, std::size_t... I>
34  Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ),
35  std::index_sequence<I...> )
36  : extends<details::BaseClass_t<Traits>, Gaudi::Interface::Bind::IBinder<IFace>>{ std::move( type ),
37  std::move( name ), parent }
38  , m_handles{ std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )... }
39  , m_creator{ creator } {}
40 
42  Gaudi::Interface::Bind::Box<IFace> ( *m_creator )( void const*, Args const&... );
43 
44  public:
48  Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ) )
49  : ToolBinder{ std::move( type ), std::move( name ), parent, inputs, creator, std::make_index_sequence<N>{} } {
50  }
51 
53  return std::apply(
54  [&]( auto const&... arg ) {
55  using namespace details;
56  return std::invoke( m_creator, this, get( arg, *this, ctx )... );
57  },
58  m_handles );
59  }
60 
61  template <std::size_t N = 0>
62  decltype( auto ) inputLocation() const {
63  using namespace details;
64  return getKey( std::get<N>( m_handles ) );
65  }
66  template <typename T>
67  decltype( auto ) inputLocation() const {
68  using namespace details;
69  return getKey( std::get<InputHandle_t<Traits, std::decay_t<T>>>( m_handles ) );
70  }
71 
72  // TODO: make this a callable instance?
73  template <typename BoundInstance, typename Self>
74  static auto construct( Self* ) {
75  static_assert( std::is_base_of_v<ToolBinder, Self> );
76  return +[]( void const* ptr, const Args&... args ) {
77  return Gaudi::Interface::Bind::Box<IFace>{ std::in_place_type<BoundInstance>,
78  static_cast<std::add_const_t<Self>*>( ptr ), args... };
79  };
80  }
81  };
82  } // namespace details
83 
84  template <typename Signature, typename Traits_ = Traits::use_<Traits::BaseClass_t<AlgTool>>>
86 
87 } // 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:21
std::string
STL class.
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
IOTest.N
int N
Definition: IOTest.py:115
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:52
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:41
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:74
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
gaudirun.type
type
Definition: gaudirun.py:160
gaudirun.args
args
Definition: gaudirun.py:336
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:24
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:46
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:33
Gaudi::Functional::details::getKey
auto getKey(const Handle &h) -> decltype(h.objKey())
Definition: FunctionalDetails.h:456