The Gaudi Framework  master (50fc5a74)
Loading...
Searching...
No Matches
ToolBinder.h
Go to the documentation of this file.
1/*****************************************************************************\
2* (c) Copyright 2021-2026 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
19namespace Gaudi::Functional {
20 namespace details {
21 template <typename Signature, typename Traits>
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>
31 ToolBinder( std::string type, std::string name, const IInterface* parent, IArgs&& args,
32 Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ),
33 std::index_sequence<I...> )
34 : extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>>{ std::move( type ),
35 std::move( name ),
36 parent }
37 , m_handles{ std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )... }
38 , m_creator{ creator } {}
39
40 std::tuple<details::InputHandle_t<Traits, Args>...> m_handles;
41 Gaudi::Interface::Bind::Box<IFace> ( *m_creator )( void const*, Args const&... );
42
43 public:
44 using KeyValue = std::pair<std::string, std::string>;
45 ToolBinder( std::string type, std::string name, const IInterface* parent,
47 Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ) )
48 : ToolBinder{ std::move( type ), std::move( name ), parent, inputs, creator, std::make_index_sequence<N>{} } {
49 }
50
52 return std::apply(
53 [&]( auto const&... arg ) {
54 using namespace details;
55 return std::invoke( m_creator, this, get( arg, *this, ctx )... );
56 },
57 m_handles );
58 }
59
60 template <std::size_t N = 0>
61 decltype( auto ) inputLocation() const {
62 using namespace details;
63 return getKey( std::get<N>( m_handles ) );
64 }
65 template <typename T>
66 decltype( auto ) inputLocation() const {
67 using namespace details;
68 return getKey( std::get<InputHandle_t<Traits, std::decay_t<T>>>( m_handles ) );
69 }
70
71 // TODO: make this a callable instance?
72 template <typename BoundInstance, typename Self>
73 static auto construct( Self* ) {
74 static_assert( std::is_base_of_v<ToolBinder, Self> );
75 return +[]( void const* ptr, const Args&... args ) {
76 return Gaudi::Interface::Bind::Box<IFace>{ std::in_place_type<BoundInstance>,
77 static_cast<std::add_const_t<Self>*>( ptr ), args... };
78 };
79 }
80 };
81 } // namespace details
82
83 template <typename Signature, typename Traits_ = Traits::use_<Traits::BaseClass_t<AlgTool>>>
85
86} // namespace Gaudi::Functional
Base class from which all the concrete tool classes should be derived.
Definition AlgTool.h:55
This class represents an entry point to all the event specific data.
Gaudi::Interface::Bind::Box< IFace > bind(EventContext const &ctx) const final
Definition ToolBinder.h:51
Gaudi::Interface::Bind::Box< IFace >(* m_creator)(void const *, Args const &...)
Definition ToolBinder.h:41
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
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:45
Definition of the basic interface.
Definition IInterface.h:225
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition details.h:503
auto getKey(const Handle &h) -> decltype(h.objKey())
Definition details.h:515
typename detail2::InputHandle< T, Tr, detail2::DefaultInputHandle >::type InputHandle_t
Definition details.h:494
detail2::BaseClass< Tr, Default >::type BaseClass_t
Definition details.h:485
decltype(get_values_helper< Value >(std::make_index_sequence< N >())) RepeatValues_
Definition details.h:98
details::ToolBinder< Signature, Traits_ > ToolBinder
Definition ToolBinder.h:84
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.