File indexing completed on 2025-01-18 09:57:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <Gaudi/Algorithm.h>
0014 #include <GaudiKernel/Algorithm.h>
0015 #include <GaudiKernel/DataObjectHandle.h>
0016 #include <GaudiKernel/GaudiException.h>
0017 #include <GaudiKernel/IBinder.h>
0018 #include <GaudiKernel/ThreadLocalContext.h>
0019 #include <GaudiKernel/detected.h>
0020 #include <cassert>
0021 #include <range/v3/version.hpp>
0022 #include <range/v3/view/const.hpp>
0023 #include <range/v3/view/zip.hpp>
0024 #include <sstream>
0025 #include <stdexcept>
0026 #include <type_traits>
0027
0028
0029 #if RANGE_V3_VERSION < 900
0030 namespace ranges::views {
0031 using namespace ranges::view;
0032 }
0033 #endif
0034
0035 #if defined( __clang__ ) && ( __clang_major__ < 11 ) || defined( __APPLE__ ) && ( __clang_major__ < 12 )
0036 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN \
0037 _Pragma( "clang diagnostic push" ) _Pragma( "clang diagnostic ignored \"-Wunused-lambda-capture\"" )
0038 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END _Pragma( "clang diagnostic pop" )
0039 #else
0040 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN
0041 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
0042 #endif
0043
0044
0045
0046 #define GAUDI_FUNCTIONAL_CONSTRUCTOR_USES_TUPLE
0047
0048 namespace Gaudi::Functional::details {
0049
0050
0051 namespace zip {
0052
0053
0054 template <typename OS, typename Arg>
0055 void printSizes( OS& out, Arg&& arg ) {
0056 out << "SizeOf'" << System::typeinfoName( typeid( Arg ) ) << "'=" << std::forward<Arg>( arg ).size();
0057 }
0058
0059
0060 template <typename OS, typename Arg, typename... Args>
0061 void printSizes( OS& out, Arg&& arg, Args&&... args ) {
0062 printSizes( out, arg );
0063 out << ", ";
0064 printSizes( out, args... );
0065 }
0066
0067
0068 template <typename A>
0069 inline bool check_sizes( const A& ) noexcept {
0070 return true;
0071 }
0072
0073
0074 template <typename A, typename B>
0075 inline bool check_sizes( const A& a, const B& b ) noexcept {
0076 return a.size() == b.size();
0077 }
0078
0079
0080 template <typename A, typename B, typename... C>
0081 inline bool check_sizes( const A& a, const B& b, const C&... c ) noexcept {
0082 return ( check_sizes( a, b ) && check_sizes( b, c... ) );
0083 }
0084
0085
0086 template <typename... Args>
0087 inline decltype( auto ) verifySizes( Args&... args ) {
0088 if ( !check_sizes( args... ) ) {
0089 std::ostringstream mess;
0090 mess << "Zipped containers have different sizes : ";
0091 printSizes( mess, args... );
0092 throw GaudiException( mess.str(), "Gaudi::Functional::details::zip::verifySizes", StatusCode::FAILURE );
0093 }
0094 }
0095
0096
0097 template <typename... Args>
0098 inline decltype( auto ) range( Args&&... args ) {
0099 #ifndef NDEBUG
0100 verifySizes( args... );
0101 #endif
0102 return ranges::views::zip( std::forward<Args>( args )... );
0103 }
0104
0105
0106 template <typename... Args>
0107 inline decltype( auto ) const_range( Args&&... args ) {
0108 #ifndef NDEBUG
0109 verifySizes( args... );
0110 #endif
0111 return ranges::views::const_( ranges::views::zip( std::forward<Args>( args )... ) );
0112 }
0113 }
0114
0115 inline std::vector<DataObjID> to_DataObjID( const std::vector<std::string>& in ) {
0116 std::vector<DataObjID> out;
0117 out.reserve( in.size() );
0118 std::transform( in.begin(), in.end(), std::back_inserter( out ),
0119 []( const std::string& i ) { return DataObjID{ i }; } );
0120 return out;
0121 }
0122
0123
0124 namespace details2 {
0125 template <typename T>
0126 using is_optional_ = decltype( std::declval<T>().has_value(), std::declval<T>().value() );
0127
0128 template <typename T>
0129 using value_type_of_t = typename T::value_type;
0130
0131 }
0132 template <typename Arg>
0133 constexpr bool is_optional_v = Gaudi::cpp17::is_detected_v<details2::is_optional_, Arg>;
0134
0135 template <typename Arg>
0136 using require_is_optional = std::enable_if_t<is_optional_v<Arg>>;
0137
0138 template <typename Arg>
0139 using require_is_not_optional = std::enable_if_t<!is_optional_v<Arg>>;
0140
0141 template <typename T>
0142 using remove_optional_t =
0143 std::conditional_t<is_optional_v<T>, Gaudi::cpp17::detected_t<details2::value_type_of_t, T>, T>;
0144
0145 constexpr struct invoke_optionally_t {
0146 template <typename F, typename Arg, typename = require_is_not_optional<Arg>>
0147 decltype( auto ) operator()( F&& f, Arg&& arg ) const {
0148 return std::invoke( std::forward<F>( f ), std::forward<Arg>( arg ) );
0149 }
0150 template <typename F, typename Arg, typename = require_is_optional<Arg>>
0151 void operator()( F&& f, Arg&& arg ) const {
0152 if ( arg ) std::invoke( std::forward<F>( f ), *std::forward<Arg>( arg ) );
0153 }
0154 } invoke_optionally{};
0155
0156
0157 template <typename Value, std::size_t... I>
0158 auto get_values_helper( std::index_sequence<I...> ) {
0159 return std::make_tuple( ( (void)I, Value{} )... );
0160 }
0161
0162 template <typename Value, auto N>
0163 using RepeatValues_ = decltype( get_values_helper<Value>( std::make_index_sequence<N>() ) );
0164
0165
0166
0167 template <typename Out1, typename Out2,
0168 typename = std::enable_if_t<std::is_constructible_v<Out1, Out2> && std::is_base_of_v<DataObject, Out1>>>
0169 auto put( const DataObjectHandle<Out1>& out_handle, Out2&& out ) {
0170 return out_handle.put( std::make_unique<Out1>( std::forward<Out2>( out ) ) );
0171 }
0172
0173 template <typename Out1, typename Out2, typename = std::enable_if_t<std::is_constructible_v<Out1, Out2>>>
0174 auto put( const DataObjectHandle<AnyDataWrapper<Out1>>& out_handle, Out2&& out ) {
0175 return out_handle.put( std::forward<Out2>( out ) );
0176 }
0177
0178
0179 template <typename OutHandle, typename OptOut, typename = require_is_optional<OptOut>>
0180 void put( const OutHandle& out_handle, OptOut&& out ) {
0181 if ( out ) put( out_handle, *std::forward<OptOut>( out ) );
0182 }
0183
0184
0185
0186
0187
0188
0189 constexpr struct insert_t {
0190
0191 template <typename Container>
0192 using c_remove_ptr_t = std::remove_pointer_t<typename Container::value_type>;
0193
0194 template <typename Container, typename Value>
0195 auto operator()( Container& c, Value&& v ) const -> decltype( c.push_back( v ) ) {
0196 return c.push_back( std::forward<Value>( v ) );
0197 }
0198
0199 template <typename Container, typename Value>
0200 auto operator()( Container& c, Value&& v ) const -> decltype( c.insert( v ) ) {
0201 return c.insert( std::forward<Value>( v ) );
0202 }
0203
0204
0205 template <typename Container, typename Value,
0206 typename = std::enable_if_t<std::is_pointer_v<typename Container::value_type>>,
0207 typename = std::enable_if_t<std::is_convertible_v<Value, c_remove_ptr_t<Container>>>>
0208 auto operator()( Container& c, Value&& v ) const {
0209 return operator()( c, new c_remove_ptr_t<Container>{ std::forward<Value>( v ) } );
0210 }
0211
0212 } insert{};
0213
0214
0215
0216 constexpr struct deref_t {
0217 template <typename In, typename = std::enable_if_t<!std::is_pointer_v<In>>>
0218 const In& operator()( const In& in ) const {
0219 return in;
0220 }
0221
0222 template <typename In, typename = std::enable_if_t<!std::is_pointer_v<std::decay_t<In>>>>
0223 In operator()( In&& in ) const {
0224 return std::forward<In>( in );
0225 }
0226
0227 template <typename In>
0228 const In& operator()( const In* in ) const {
0229 assert( in != nullptr );
0230 return *in;
0231 }
0232 } deref{};
0233
0234
0235
0236 namespace details2 {
0237 template <typename T>
0238 struct is_gaudi_range : std::false_type {};
0239
0240 template <typename T, typename IT>
0241 struct is_gaudi_range<Gaudi::Range_<T, IT>> : std::true_type {};
0242
0243 template <typename T, typename IT>
0244 struct is_gaudi_range<Gaudi::NamedRange_<T, IT>> : std::true_type {};
0245
0246 template <typename T>
0247 constexpr static bool is_gaudi_range_v = is_gaudi_range<T>::value;
0248
0249 template <typename Container, typename Value>
0250 void push_back( Container& c, const Value& v, std::true_type ) {
0251 c.push_back( v );
0252 }
0253 template <typename Container, typename Value>
0254 void push_back( Container& c, const Value& v, std::false_type ) {
0255 c.push_back( &v );
0256 }
0257
0258 template <typename In>
0259 struct get_from_handle {
0260 template <template <typename> class Handle, typename I, typename = std::enable_if_t<std::is_convertible_v<I, In>>>
0261 auto operator()( const Handle<I>& h ) -> const In& {
0262 return *h.get();
0263 }
0264 template <template <typename> class Handle, typename I, typename IT>
0265 auto operator()( const Handle<Gaudi::Range_<I, IT>>& h ) -> const In {
0266 return h.get();
0267 }
0268 template <template <typename> class Handle, typename I, typename IT>
0269 auto operator()( const Handle<Gaudi::NamedRange_<I, IT>>& h ) -> const In {
0270 return h.get();
0271 }
0272 template <template <typename> class Handle, typename I,
0273 typename = std::enable_if_t<std::is_convertible_v<I*, In>>>
0274 auto operator()( const Handle<I>& h ) -> const In {
0275 return h.getIfExists();
0276 }
0277 };
0278
0279 template <typename T>
0280 T* deref_if( T* const t, std::false_type ) {
0281 return t;
0282 }
0283 template <typename T>
0284 T& deref_if( T* const t, std::true_type ) {
0285 return *t;
0286 }
0287 }
0288
0289 template <typename Container>
0290 class vector_of_const_ {
0291 static constexpr bool is_pointer = std::is_pointer_v<Container>;
0292 static constexpr bool is_range = details2::is_gaudi_range_v<Container>;
0293 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
0294 using ptr_t = std::add_pointer_t<val_t>;
0295 using ref_t = std::add_lvalue_reference_t<val_t>;
0296 using ContainerVector = std::vector<std::conditional_t<is_range, std::remove_const_t<val_t>, ptr_t>>;
0297 ContainerVector m_containers;
0298
0299 public:
0300 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
0301 using size_type = typename ContainerVector::size_type;
0302 class iterator {
0303 using it_t = typename ContainerVector::const_iterator;
0304 it_t m_i;
0305 friend class vector_of_const_;
0306 iterator( it_t iter ) : m_i( iter ) {}
0307 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
0308
0309 public:
0310 using iterator_category = typename it_t::iterator_category;
0311 using value_type = typename it_t::iterator_category;
0312 using reference = typename it_t::reference;
0313 using pointer = typename it_t::pointer;
0314 using difference_type = typename it_t::difference_type;
0315
0316 friend bool operator!=( const iterator& lhs, const iterator& rhs ) { return lhs.m_i != rhs.m_i; }
0317 friend bool operator==( const iterator& lhs, const iterator& rhs ) { return lhs.m_i == rhs.m_i; }
0318 friend auto operator-( const iterator& lhs, const iterator& rhs ) { return lhs.m_i - rhs.m_i; }
0319 ret_t operator*() const {
0320 if constexpr ( is_range ) {
0321 return *m_i;
0322 } else {
0323 return details2::deref_if( *m_i, std::bool_constant<!is_pointer>{} );
0324 }
0325 }
0326 iterator& operator++() {
0327 ++m_i;
0328 return *this;
0329 }
0330 iterator& operator--() {
0331 --m_i;
0332 return *this;
0333 }
0334 bool is_null() const { return !*m_i; }
0335 explicit operator bool() const { return !is_null(); }
0336 };
0337 vector_of_const_() = default;
0338 void reserve( size_type size ) { m_containers.reserve( size ); }
0339 template <typename T>
0340 void push_back( T&& container ) {
0341 details2::push_back( m_containers, std::forward<T>( container ),
0342 std::bool_constant < is_pointer || is_range > {} );
0343 }
0344 iterator begin() const { return m_containers.begin(); }
0345 iterator end() const { return m_containers.end(); }
0346 size_type size() const { return m_containers.size(); }
0347
0348 template <typename X = Container>
0349 std::enable_if_t<!std::is_pointer_v<X>, ref_t> front() const {
0350 return *m_containers.front();
0351 }
0352 template <typename X = Container>
0353 std::enable_if_t<std::is_pointer_v<X>, ptr_t> front() const {
0354 return m_containers.front();
0355 }
0356
0357 template <typename X = Container>
0358 std::enable_if_t<!std::is_pointer_v<X>, ref_t> back() const {
0359 return *m_containers.back();
0360 }
0361 template <typename X = Container>
0362 std::enable_if_t<std::is_pointer_v<X>, ptr_t> back() const {
0363 return m_containers.back();
0364 }
0365
0366 template <typename X = Container>
0367 std::enable_if_t<!std::is_pointer_v<X>, ref_t> operator[]( size_type i ) const {
0368 return *m_containers[i];
0369 }
0370 template <typename X = Container>
0371 std::enable_if_t<std::is_pointer_v<X>, ptr_t> operator[]( size_type i ) const {
0372 return m_containers[i];
0373 }
0374
0375 template <typename X = Container>
0376 std::enable_if_t<!std::is_pointer_v<X>, ref_t> at( size_type i ) const {
0377 return *m_containers[i];
0378 }
0379 template <typename X = Container>
0380 std::enable_if_t<std::is_pointer_v<X>, ptr_t> at( size_type i ) const {
0381 return m_containers[i];
0382 }
0383
0384 bool is_null( size_type i ) const { return !m_containers[i]; }
0385 };
0386
0387
0388 namespace detail2 {
0389 template <typename Tr>
0390 using BaseClass_t = typename Tr::BaseClass;
0391 template <typename Tr, typename T>
0392 using OutputHandle_t = typename Tr::template OutputHandle<T>;
0393 template <typename Tr, typename T>
0394 using InputHandle_t = typename Tr::template InputHandle<T>;
0395
0396 template <typename T>
0397 constexpr auto is_tool_v = std::is_base_of_v<IAlgTool, std::decay_t<T>>;
0398
0399 template <typename T>
0400 using ToolHandle_t = ToolHandle<Gaudi::Interface::Bind::IBinder<std::decay_t<T>>>;
0401
0402 template <typename T>
0403 using DefaultInputHandle = std::conditional_t<is_tool_v<T>, ToolHandle_t<T>, DataObjectReadHandle<T>>;
0404 }
0405
0406
0407
0408
0409 template <typename Tr, typename Base = Gaudi::Algorithm>
0410 using BaseClass_t = Gaudi::cpp17::detected_or_t<Base, detail2::BaseClass_t, Tr>;
0411
0412
0413
0414
0415
0416 template <typename Tr, typename T>
0417 using OutputHandle_t = Gaudi::cpp17::detected_or_t<DataObjectWriteHandle<T>, detail2::OutputHandle_t, Tr, T>;
0418 template <typename Tr, typename T>
0419 using InputHandle_t = Gaudi::cpp17::detected_or_t<detail2::DefaultInputHandle<T>, detail2::InputHandle_t, Tr, T>;
0420
0421 template <typename Traits>
0422 inline constexpr bool isLegacy =
0423 std::is_base_of_v<Gaudi::details::LegacyAlgorithmAdapter, details::BaseClass_t<Traits>>;
0424
0425
0426 #define GAUDI_FUNCTIONAL_MAKE_VECTOR_OF_HANDLES_USES_DATAOBJID
0427
0428 template <typename Handles>
0429 Handles make_vector_of_handles( IDataHandleHolder* owner, const std::vector<DataObjID>& init ) {
0430 Handles handles;
0431 handles.reserve( init.size() );
0432 std::transform( init.begin(), init.end(), std::back_inserter( handles ),
0433 [&]( const auto& loc ) -> typename Handles::value_type {
0434 return { loc, owner };
0435 } );
0436 return handles;
0437 }
0438
0439 template <typename Handle, typename Algo>
0440 auto get( const Handle& handle, const Algo&, const EventContext& )
0441 -> decltype( details::deref( handle.get() ) )
0442 {
0443 return details::deref( handle.get() );
0444 }
0445
0446 template <typename IFace, typename Algo>
0447 auto get( const ToolHandle<Gaudi::Interface::Bind::IBinder<IFace>>& handle, const Algo&, const EventContext& ctx ) {
0448 return handle.bind( ctx );
0449 }
0450
0451 template <typename Handle>
0452 auto getKey( const Handle& h ) -> decltype( h.objKey() ) {
0453 return h.objKey();
0454 }
0455
0456
0457
0458 template <typename... In>
0459 struct filter_evtcontext_t {
0460 using type = std::tuple<In...>;
0461
0462 static_assert( !std::disjunction_v<std::is_same<EventContext, In>...>,
0463 "EventContext can only appear as first argument" );
0464
0465 template <typename Algorithm, typename Handles>
0466 static auto apply( const Algorithm& algo, Handles& handles ) {
0467 return std::apply(
0468 [&]( const auto&... handle ) { return algo( get( handle, algo, Gaudi::Hive::currentContext() )... ); },
0469 handles );
0470 }
0471 template <typename Algorithm, typename Handles>
0472 static auto apply( const Algorithm& algo, const EventContext& ctx, Handles& handles ) {
0473 return std::apply( [&]( const auto&... handle ) { return algo( get( handle, algo, ctx )... ); }, handles );
0474 }
0475 };
0476
0477
0478 template <typename... In>
0479 struct filter_evtcontext_t<EventContext, In...> {
0480 using type = std::tuple<In...>;
0481
0482 static_assert( !std::disjunction_v<std::is_same<EventContext, In>...>,
0483 "EventContext can only appear as first argument" );
0484
0485 template <typename Algorithm, typename Handles>
0486 static auto apply( const Algorithm& algo, const EventContext& ctx, Handles& handles ) {
0487 return std::apply( [&]( const auto&... handle ) { return algo( ctx, get( handle, algo, ctx )... ); }, handles );
0488 }
0489
0490 template <typename Algorithm, typename Handles>
0491 static auto apply( const Algorithm& algo, Handles& handles ) {
0492 return apply( algo, Gaudi::Hive::currentContext(), handles );
0493 }
0494 };
0495
0496 template <typename... In>
0497 using filter_evtcontext = typename filter_evtcontext_t<In...>::type;
0498
0499 template <typename OutputSpec, typename InputSpec, typename Traits_>
0500 class DataHandleMixin;
0501
0502 template <typename Out, typename In, typename Tr>
0503 void updateHandleLocation( DataHandleMixin<Out, In, Tr>& parent, const std::string& prop,
0504 const std::string& newLoc ) {
0505 auto sc = parent.setProperty( prop, newLoc );
0506 if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + newLoc, sc );
0507 }
0508
0509 template <typename Out, typename In, typename Tr>
0510 void updateHandleLocations( DataHandleMixin<Out, In, Tr>& parent, const std::string& prop,
0511 const std::vector<std::string>& newLocs ) {
0512 std::ostringstream ss;
0513 GaudiUtils::details::ostream_joiner( ss << '[', newLocs, ", ", []( std::ostream& os, const auto& i ) -> auto& {
0514 return os << "'" << i << "'";
0515 } ) << ']';
0516 auto sc = parent.setProperty( prop, ss.str() );
0517 if ( sc.isFailure() ) throw GaudiException( "Could not set Property", prop + " -> " + ss.str(), sc );
0518 }
0519
0520 template <typename... Out, typename... In, typename Traits_>
0521 class DataHandleMixin<std::tuple<Out...>, std::tuple<In...>, Traits_> : public BaseClass_t<Traits_> {
0522 static_assert( std::is_base_of_v<Algorithm, BaseClass_t<Traits_>>, "BaseClass must inherit from Algorithm" );
0523
0524 template <typename IArgs, typename OArgs, std::size_t... I, std::size_t... J>
0525 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, const IArgs& inputs, std::index_sequence<I...>,
0526 const OArgs& outputs, std::index_sequence<J...> )
0527 : BaseClass_t<Traits_>( std::move( name ), pSvcLocator )
0528 , m_inputs( std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( inputs ) )... )
0529 , m_outputs( std::tuple_cat( std::forward_as_tuple( this ), std::get<J>( outputs ) )... ) {
0530
0531 this->setProperty( "Cardinality", 0 ).ignore();
0532 }
0533
0534 public:
0535 constexpr static std::size_t N_in = sizeof...( In );
0536 constexpr static std::size_t N_out = sizeof...( Out );
0537
0538 using KeyValue = std::pair<std::string, std::string>;
0539 using KeyValues = std::pair<std::string, std::vector<std::string>>;
0540
0541
0542 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, RepeatValues_<KeyValue, N_in> const& inputs,
0543 RepeatValues_<KeyValue, N_out> const& outputs )
0544 : DataHandleMixin( std::move( name ), pSvcLocator, inputs, std::index_sequence_for<In...>{}, outputs,
0545 std::index_sequence_for<Out...>{} ) {}
0546
0547
0548
0549 DataHandleMixin( std::string name, ISvcLocator* locator, const KeyValue& input, const KeyValue& output )
0550 : DataHandleMixin( std::move( name ), locator, std::forward_as_tuple( input ),
0551 std::forward_as_tuple( output ) ) {}
0552
0553 DataHandleMixin( std::string name, ISvcLocator* locator, const KeyValue& input,
0554 RepeatValues_<KeyValue, N_out> const& outputs )
0555 : DataHandleMixin( std::move( name ), locator, std::forward_as_tuple( input ), outputs ) {}
0556
0557 DataHandleMixin( std::string name, ISvcLocator* locator, RepeatValues_<KeyValue, N_in> const& inputs,
0558 const KeyValue& output )
0559 : DataHandleMixin( std::move( name ), locator, inputs, std::forward_as_tuple( output ) ) {}
0560
0561 template <std::size_t N = 0>
0562 decltype( auto ) inputLocation() const {
0563 return getKey( std::get<N>( m_inputs ) );
0564 }
0565 template <typename T>
0566 decltype( auto ) inputLocation() const {
0567 return getKey( std::get<details::InputHandle_t<Traits_, std::decay_t<T>>>( m_inputs ) );
0568 }
0569 constexpr unsigned int inputLocationSize() const { return N_in; }
0570
0571 template <std::size_t N = 0>
0572 decltype( auto ) outputLocation() const {
0573 return getKey( std::get<N>( m_outputs ) );
0574 }
0575 template <typename T>
0576 decltype( auto ) outputLocation() const {
0577 return getKey( std::get<details::OutputHandle_t<Traits_, std::decay_t<T>>>( m_outputs ) );
0578 }
0579 constexpr unsigned int outputLocationSize() const { return N_out; }
0580
0581 protected:
0582 bool isReEntrant() const override { return true; }
0583
0584 std::tuple<details::InputHandle_t<Traits_, In>...> m_inputs;
0585 std::tuple<details::OutputHandle_t<Traits_, Out>...> m_outputs;
0586 };
0587
0588 template <typename Traits_>
0589 class DataHandleMixin<std::tuple<>, std::tuple<>, Traits_> : public BaseClass_t<Traits_> {
0590 static_assert( std::is_base_of_v<Algorithm, BaseClass_t<Traits_>>, "BaseClass must inherit from Algorithm" );
0591
0592 public:
0593 using KeyValue = std::pair<std::string, std::string>;
0594 using KeyValues = std::pair<std::string, std::vector<std::string>>;
0595 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, std::tuple<> = {}, std::tuple<> = {} )
0596 : BaseClass_t<Traits_>( std::move( name ), pSvcLocator ) {
0597
0598 this->setProperty( "Cardinality", 0 ).ignore();
0599 }
0600
0601 protected:
0602 bool isReEntrant() const override { return true; }
0603
0604 std::tuple<> m_inputs;
0605 };
0606
0607 template <typename... In, typename Traits_>
0608 class DataHandleMixin<std::tuple<>, std::tuple<In...>, Traits_> : public BaseClass_t<Traits_> {
0609 static_assert( std::is_base_of_v<Algorithm, BaseClass_t<Traits_>>, "BaseClass must inherit from Algorithm" );
0610
0611 template <typename IArgs, std::size_t... I>
0612 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, const IArgs& inputs, std::index_sequence<I...> )
0613 : BaseClass_t<Traits_>( std::move( name ), pSvcLocator )
0614 , m_inputs( std::tuple_cat( std::forward_as_tuple( this ), std::get<I>( inputs ) )... ) {
0615
0616 this->setProperty( "Cardinality", 0 ).ignore();
0617 }
0618
0619 public:
0620 using KeyValue = std::pair<std::string, std::string>;
0621 using KeyValues = std::pair<std::string, std::vector<std::string>>;
0622 constexpr static std::size_t N_in = sizeof...( In );
0623
0624
0625 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, RepeatValues_<KeyValue, N_in> const& inputs )
0626 : DataHandleMixin( std::move( name ), pSvcLocator, inputs, std::index_sequence_for<In...>{} ) {}
0627
0628
0629
0630 DataHandleMixin( std::string name, ISvcLocator* locator, const KeyValue& input )
0631 : DataHandleMixin( std::move( name ), locator, std::forward_as_tuple( input ) ) {}
0632
0633 template <std::size_t N = 0>
0634 decltype( auto ) inputLocation() const {
0635 return getKey( std::get<N>( m_inputs ) );
0636 }
0637 template <typename T>
0638 decltype( auto ) inputLocation() const {
0639 return getKey( std::get<details::InputHandle_t<Traits_, std::decay_t<T>>>( m_inputs ) );
0640 }
0641 constexpr unsigned int inputLocationSize() const { return N_in; }
0642
0643 protected:
0644 bool isReEntrant() const override { return true; }
0645
0646 std::tuple<details::InputHandle_t<Traits_, In>...> m_inputs;
0647 };
0648
0649 template <typename Traits_>
0650 class DataHandleMixin<std::tuple<void>, std::tuple<>, Traits_>
0651 : public DataHandleMixin<std::tuple<>, std::tuple<>, Traits_> {
0652 public:
0653 using DataHandleMixin<std::tuple<>, std::tuple<>, Traits_>::DataHandleMixin;
0654 };
0655
0656 template <typename... Out, typename Traits_>
0657 class DataHandleMixin<std::tuple<Out...>, std::tuple<>, Traits_> : public BaseClass_t<Traits_> {
0658 static_assert( std::is_base_of_v<Algorithm, BaseClass_t<Traits_>>, "BaseClass must inherit from Algorithm" );
0659
0660 template <typename OArgs, std::size_t... J>
0661 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, const OArgs& outputs, std::index_sequence<J...> )
0662 : BaseClass_t<Traits_>( std::move( name ), pSvcLocator )
0663 , m_outputs( std::tuple_cat( std::forward_as_tuple( this ), std::get<J>( outputs ) )... ) {
0664
0665 this->setProperty( "Cardinality", 0 ).ignore();
0666 }
0667
0668 public:
0669 constexpr static std::size_t N_out = sizeof...( Out );
0670 using KeyValue = std::pair<std::string, std::string>;
0671 using KeyValues = std::pair<std::string, std::vector<std::string>>;
0672
0673
0674 DataHandleMixin( std::string name, ISvcLocator* pSvcLocator, RepeatValues_<KeyValue, N_out> const& outputs )
0675 : DataHandleMixin( std::move( name ), pSvcLocator, outputs, std::index_sequence_for<Out...>{} ) {}
0676
0677
0678 DataHandleMixin( std::string name, ISvcLocator* locator, const KeyValue& output )
0679 : DataHandleMixin( std::move( name ), locator, std::forward_as_tuple( output ) ) {}
0680
0681 template <std::size_t N = 0>
0682 decltype( auto ) outputLocation() const {
0683 return getKey( std::get<N>( m_outputs ) );
0684 }
0685 constexpr unsigned int outputLocationSize() const { return N_out; }
0686
0687 protected:
0688 bool isReEntrant() const override { return true; }
0689
0690 std::tuple<details::OutputHandle_t<Traits_, Out>...> m_outputs;
0691 };
0692
0693
0694 template <typename Fun, typename Container, typename... Args>
0695 constexpr void applyPostProcessing( const Fun&, Container&, Args... ) {
0696 static_assert( sizeof...( Args ) == 0, "Args should not be used!" );
0697 }
0698
0699 template <typename Fun, typename Container>
0700 auto applyPostProcessing( const Fun& fun, Container& c ) -> decltype( fun.postprocess( c ), void() ) {
0701 fun.postprocess( c );
0702 }
0703
0704 }