The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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
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>, 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
39 std::tuple<details::InputHandle_t<Traits, Args>...> m_handles;
40 Gaudi::Interface::Bind::Box<IFace> ( *m_creator )( void const*, Args const&... );
41
42 public:
43 using KeyValue = std::pair<std::string, std::string>;
44 ToolBinder( std::string type, std::string name, const IInterface* parent,
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
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:50
Gaudi::Interface::Bind::Box< IFace >(* m_creator)(void const *, Args const &...)
Definition ToolBinder.h:40
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:44
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:478
auto getKey(const Handle &h) -> decltype(h.objKey())
Definition details.h:490
typename detail2::InputHandle< T, Tr, detail2::DefaultInputHandle >::type InputHandle_t
Definition details.h:458
detail2::BaseClass< Tr, Default >::type BaseClass_t
Definition details.h:449
decltype(get_values_helper< Value >(std::make_index_sequence< N >())) RepeatValues_
Definition details.h:158
details::ToolBinder< Signature, Traits_ > ToolBinder
Definition ToolBinder.h:83
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.