The Gaudi Framework  master (a1077a66)
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#include "details.h"
13#include "utilities.h"
14#include <GaudiKernel/AlgTool.h>
15#include <GaudiKernel/IBinder.h>
16
17namespace Gaudi::Functional {
18 namespace details {
19 template <typename Signature, typename Traits>
21
22 template <typename IFace, typename... Args, typename Traits>
23 class ToolBinder<Gaudi::Interface::Bind::Box<IFace>( Args const&... ), Traits>
24 : public extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>> {
25
26 public:
27 constexpr static std::size_t N = sizeof...( Args );
32 using Creator = Gaudi::Interface::Bind::Box<IFace> ( * )( void const*, Args const&... );
33
34 template <size_t... I>
35 ToolBinder( std::string type, std::string name, const IInterface* parent, InputSpecTuple const& args,
36 Creator creator, std::index_sequence<I...> )
37 : extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>>{ std::move( type ),
38 std::move( name ),
39 parent }
40 , m_handles{ std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )... }
41 , m_creator{ creator } {}
42
43 private:
44 std::tuple<details::InputHandle_t<Traits, Args>...> m_handles;
46
47 public:
48 ToolBinder( std::string type, std::string name, const IInterface* parent, InputSpecs const& inputs,
49 Creator creator )
50 : ToolBinder{ std::move( type ), std::move( name ), parent,
51 inputs.tuple(), creator, std::make_index_sequence<N>{} } {}
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
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:53
Gaudi::Interface::Bind::Box< IFace >(*)(void const *, Args const &...) Creator
Definition ToolBinder.h:32
ToolBinder(std::string type, std::string name, const IInterface *parent, InputSpecTuple const &args, Creator creator, std::index_sequence< I... >)
Definition ToolBinder.h:35
ToolBinder(std::string type, std::string name, const IInterface *parent, InputSpecs const &inputs, Creator creator)
Definition ToolBinder.h:48
Definition of the basic interface.
Definition IInterface.h:225
Base class used to extend a class implementing other interfaces.
Definition extends.h:19
typename detail2::InputHandle< T, Tr, detail2::DefaultInputHandle_t >::type InputHandle_t
Definition details.h:564
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Definition details.h:717
auto getKey(const Handle &h) -> decltype(h.objKey())
Definition details.h:739
std::tuple< LocationSpec_t< Args >... > LocationSpecs_t
Definition details.h:615
detail2::BaseClass< Tr, Default >::type BaseClass_t
Definition details.h:555
details::ToolBinder< Signature, Traits_ > ToolBinder
Definition ToolBinder.h:86
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.
std::pair< std::string, std::string > KeyValue
Definition details.h:570
std::pair< std::string, std::vector< std::string > > KeyValues
Definition details.h:571