Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:30

0001 /*****************************************************************************\
0002 * (c) Copyright 2021-2023 CERN for the benefit of the LHCb Collaboration      *
0003 *                                                                             *
0004 * This software is distributed under the terms of the GNU General Public      *
0005 * Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING".   *
0006 *                                                                             *
0007 * In applying this licence, CERN does not waive the privileges and immunities *
0008 * granted to it by virtue of its status as an Intergovernmental Organization  *
0009 * or submit itself to any jurisdiction.                                       *
0010 \*****************************************************************************/
0011 #pragma once
0012 
0013 #include "details.h"
0014 #include "utilities.h"
0015 #include <GaudiKernel/IBinder.h>
0016 
0017 #define GAUDI_FUNCTIONAL_TOOL_BINDER_USES_CREATE
0018 
0019 namespace Gaudi::Functional {
0020   namespace details {
0021     template <typename Signature, typename Traits>
0022     class ToolBinder;
0023 
0024     template <typename IFace, typename... Args, typename Traits>
0025     class ToolBinder<Gaudi::Interface::Bind::Box<IFace>( Args const&... ), Traits>
0026         : public extends<details::BaseClass_t<Traits, AlgTool>, Gaudi::Interface::Bind::IBinder<IFace>> {
0027 
0028       constexpr static std::size_t N = sizeof...( Args );
0029 
0030       template <typename IArgs, std::size_t... I>
0031       ToolBinder( std::string type, std::string name, const IInterface* parent, IArgs&& args,
0032                   Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ),
0033                   std::index_sequence<I...> )
0034           : extends<details::BaseClass_t<Traits>, Gaudi::Interface::Bind::IBinder<IFace>>{ std::move( type ),
0035                                                                                            std::move( name ), parent }
0036           , m_handles{ std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( args ) )... }
0037           , m_creator{ creator } {}
0038 
0039       std::tuple<details::InputHandle_t<Traits, Args>...> m_handles;
0040       Gaudi::Interface::Bind::Box<IFace> ( *m_creator )( void const*, Args const&... );
0041 
0042     public:
0043       using KeyValue = std::pair<std::string, std::string>;
0044       ToolBinder( std::string type, std::string name, const IInterface* parent,
0045                   Gaudi::Functional::details::RepeatValues_<KeyValue, N> const& inputs,
0046                   Gaudi::Interface::Bind::Box<IFace> ( *creator )( void const*, Args const&... ) )
0047           : ToolBinder{ std::move( type ), std::move( name ), parent, inputs, creator, std::make_index_sequence<N>{} } {
0048       }
0049 
0050       Gaudi::Interface::Bind::Box<IFace> bind( EventContext const& ctx ) const final {
0051         return std::apply(
0052             [&]( auto const&... arg ) {
0053               using namespace details;
0054               return std::invoke( m_creator, this, get( arg, *this, ctx )... );
0055             },
0056             m_handles );
0057       }
0058 
0059       template <std::size_t N = 0>
0060       decltype( auto ) inputLocation() const {
0061         using namespace details;
0062         return getKey( std::get<N>( m_handles ) );
0063       }
0064       template <typename T>
0065       decltype( auto ) inputLocation() const {
0066         using namespace details;
0067         return getKey( std::get<InputHandle_t<Traits, std::decay_t<T>>>( m_handles ) );
0068       }
0069 
0070       // TODO: make this a callable instance?
0071       template <typename BoundInstance, typename Self>
0072       static auto construct( Self* ) {
0073         static_assert( std::is_base_of_v<ToolBinder, Self> );
0074         return +[]( void const* ptr, const Args&... args ) {
0075           return Gaudi::Interface::Bind::Box<IFace>{ std::in_place_type<BoundInstance>,
0076                                                      static_cast<std::add_const_t<Self>*>( ptr ), args... };
0077         };
0078       }
0079     };
0080   } // namespace details
0081 
0082   template <typename Signature, typename Traits_ = Traits::use_<Traits::BaseClass_t<AlgTool>>>
0083   using ToolBinder = details::ToolBinder<Signature, Traits_>;
0084 
0085 } // namespace Gaudi::Functional