Go to the documentation of this file.
11 #ifndef FUNCTIONAL_DETAILS_H
12 #define FUNCTIONAL_DETAILS_H
17 #include <type_traits>
28 #include <range/v3/version.hpp>
29 #include <range/v3/view/const.hpp>
30 #include <range/v3/view/zip.hpp>
32 #if RANGE_V3_VERSION < 900
34 using namespace ranges::view;
38 #if defined( __clang__ ) && ( __clang_major__ < 11 ) || defined( __APPLE__ ) && ( __clang_major__ < 12 )
39 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN \
40 _Pragma( "clang diagnostic push" ) _Pragma( "clang diagnostic ignored \"-Wunused-lambda-capture\"" )
41 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END _Pragma( "clang diagnostic pop" )
43 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN
44 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
53 template <
typename OS,
typename Arg>
59 template <
typename OS,
typename Arg,
typename... Args>
73 template <
typename A,
typename B>
75 return a.size() == b.size();
79 template <
typename A,
typename B,
typename... C>
80 inline bool check_sizes(
const A& a,
const B& b,
const C&...
c ) noexcept {
85 template <
typename... Args>
89 mess <<
"Zipped containers have different sizes : ";
96 template <
typename... Args>
101 return ranges::views::zip( std::forward<Args>(
args )... );
105 template <
typename... Args>
110 return ranges::views::const_( ranges::views::zip( std::forward<Args>(
args )... ) );
118 template <
typename T>
119 using is_optional_ = decltype(
bool{std::declval<T>()}, std::declval<T>().value() );
121 template <
typename Arg>
122 constexpr
bool is_optional_v = Gaudi::cpp17::is_detected_v<details2::is_optional_, Arg>;
124 template <
typename Arg>
127 template <
typename Arg>
130 template <
typename T>
134 template <
typename F,
typename Arg,
typename = require_is_not_optional<Arg>>
135 decltype(
auto ) operator()( F&& f, Arg&& arg )
const {
136 return std::invoke( std::forward<F>( f ), std::forward<Arg>( arg ) );
138 template <
typename F,
typename Arg,
typename = require_is_optional<Arg>>
140 if ( arg ) std::invoke( std::forward<F>( f ), *std::forward<Arg>( arg ) );
145 template <
typename Out1,
typename Out2,
146 typename = std::enable_if_t<std::is_constructible_v<Out1, Out2> && std::is_base_of_v<DataObject, Out1>>>
148 return out_handle.
put( std::make_unique<Out1>( std::forward<Out2>(
out ) ) );
151 template <
typename Out1,
typename Out2,
typename = std::enable_if_t<std::is_constructible_v<Out1, Out2>>>
153 return out_handle.put( std::forward<Out2>(
out ) );
157 template <
typename OutHandle,
typename OptOut,
typename = require_is_optional<OptOut>>
158 void put(
const OutHandle& out_handle, OptOut&&
out ) {
159 if (
out )
put( out_handle, *std::forward<OptOut>(
out ) );
168 template <
typename Container>
171 template <
typename Container,
typename Value>
172 auto operator()( Container&
c, Value&&
v )
const -> decltype(
c.push_back(
v ) ) {
173 return c.push_back( std::forward<Value>(
v ) );
176 template <
typename Container,
typename Value>
178 return c.insert( std::forward<Value>(
v ) );
182 template <
typename Container,
typename Value,
183 typename = std::enable_if_t<std::is_pointer_v<typename Container::value_type>>,
184 typename = std::enable_if_t<std::is_convertible_v<Value, c_remove_ptr_t<Container>>>>
194 template <
typename In,
typename = std::enable_if_t<!std::is_po
inter_v<In>>>
199 template <
typename In,
typename = std::enable_if_t<!std::is_po
inter_v<std::decay_t<In>>>>
201 return std::forward<In>( in );
204 template <
typename In>
206 assert( in !=
nullptr );
214 template <
typename T>
217 template <
typename T,
typename IT>
220 template <
typename T,
typename IT>
223 template <
typename T>
226 template <
typename Container,
typename Value>
230 template <
typename Container,
typename Value>
235 template <
typename In>
237 template <
template <
typename>
class Handle,
typename I,
typename = std::enable_if_t<std::is_convertible_v<I, In>>>
241 template <
template <
typename>
class Handle,
typename I,
typename IT>
245 template <
template <
typename>
class Handle,
typename I,
typename IT>
249 template <
template <
typename>
class Handle,
typename I,
250 typename = std::enable_if_t<std::is_convertible_v<I*, In>>>
252 return h.getIfExists();
256 template <
typename T>
260 template <
typename T>
266 template <
typename Container>
268 static constexpr
bool is_pointer = std::is_pointer_v<Container>;
269 static constexpr
bool is_range = details2::is_gaudi_range_v<Container>;
270 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
271 using ptr_t = std::add_pointer_t<val_t>;
272 using ref_t = std::add_lvalue_reference_t<val_t>;
277 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
280 using it_t =
typename ContainerVector::const_iterator;
284 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
297 if constexpr ( is_range ) {
312 explicit operator bool()
const {
return !is_null(); }
316 template <
typename T>
319 std::bool_constant < is_pointer or is_range > {} );
325 template <
typename X = Container>
327 return *m_containers[i];
330 template <
typename X = Container>
332 return m_containers[i];
335 template <
typename X = Container>
337 return *m_containers[i];
340 template <
typename X = Container>
342 return m_containers[i];
350 template <
typename Tr>
352 template <
typename Tr,
typename T>
354 template <
typename Tr,
typename T>
361 template <
typename Tr>
367 template <
typename Tr,
typename T>
369 template <
typename Tr,
typename T>
372 template <
typename Traits>
374 std::is_base_of_v<Gaudi::details::LegacyAlgorithmAdapter, details::BaseClass_t<Traits>>;
378 template <
typename Handles>
381 handles.reserve( init.
size() );
390 template <
typename Handle,
typename Algo>
397 template <
typename Handle>
398 auto getKey(
const Handle&
h ) -> decltype(
h.objKey() ) {
404 template <
typename... In>
409 "EventContext can only appear as first argument" );
411 template <
typename Algorithm,
typename Handles>
417 template <
typename Algorithm,
typename Handles>
419 return std::apply( [&](
const auto&... handle ) {
return algo(
get( handle, algo,
ctx )... ); }, handles );
424 template <
typename... In>
429 "EventContext can only appear as first argument" );
431 template <
typename Algorithm,
typename Handles>
433 return std::apply( [&](
const auto&... handle ) {
return algo(
ctx,
get( handle, algo,
ctx )... ); }, handles );
436 template <
typename Algorithm,
typename Handles>
442 template <
typename... In>
445 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
448 template <
typename Out,
typename In,
typename Tr>
451 auto sc = parent.setProperty( prop, newLoc );
452 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + newLoc, sc );
455 template <
typename Out,
typename In,
typename Tr>
460 ss <<
'[', newLocs,
", ", [](
std::ostream & os,
const auto& i ) ->
auto& {
return os <<
"'" << i <<
"'"; } )
462 auto sc = parent.setProperty( prop, ss.
str() );
463 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + ss.
str(), sc );
466 template <
typename... Out,
typename... In,
typename Traits_>
472 const OArgs& outputs, std::index_sequence<J...> )
474 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... )
475 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
491 std::index_sequence_for<Out...>{} ) {}
507 template <std::
size_t N = 0>
508 decltype(
auto ) inputLocation()
const {
509 return getKey( std::get<N>( m_inputs ) );
511 template <
typename T>
512 decltype(
auto ) inputLocation()
const {
517 template <std::
size_t N = 0>
518 decltype(
auto ) outputLocation()
const {
519 return getKey( std::get<N>( m_outputs ) );
521 template <
typename T>
522 decltype(
auto ) outputLocation()
const {
534 template <
typename Traits_>
553 template <
typename... In,
typename Traits_>
560 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... ) {
579 template <std::
size_t N = 0>
580 decltype(
auto ) inputLocation()
const {
581 return getKey( std::get<N>( m_inputs ) );
583 template <
typename T>
584 decltype(
auto ) inputLocation()
const {
595 template <
typename Traits_>
602 template <
typename... Out,
typename Traits_>
609 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
627 template <std::
size_t N = 0>
628 decltype(
auto ) outputLocation()
const {
629 return getKey( std::get<N>( m_outputs ) );
640 template <
typename Fun,
typename Container,
typename... Args>
642 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
645 template <
typename Fun,
typename Container>
647 fun.postprocess(
c );
typename Tr::BaseClass BaseClass_t
decltype(bool{std::declval< T >()}, std::declval< T >().value()) is_optional_
auto operator()(Container &c, Value &&v) const
std::enable_if_t< std::is_pointer_v< X >, ptr_t > operator[](size_type i) const
std::add_const_t< std::remove_pointer_t< Container > > val_t
const In & operator()(const In *in) const
DataHandleMixin(std::string name, ISvcLocator *locator, const std::array< KeyValue, N_in > &inputs, const KeyValue &output)
constexpr auto size(const T &, Args &&...) noexcept
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input, const KeyValue &output)
std::enable_if_t<!is_optional_v< Arg > > require_is_not_optional
GAUDI_API const EventContext & currentContext()
bool isReEntrant() const override
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &output)
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init)
constexpr struct Gaudi::Functional::details::invoke_optionally_t invoke_optionally
bool isReEntrant() const override
auto operator()(Container &c, Value &&v) const -> decltype(c.push_back(v))
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >)
T back_inserter(T... args)
ContainerVector m_containers
auto operator()(const Handle< I > &h) -> const In &
typename it_t::iterator_category iterator_category
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
void reserve(size_type size)
constexpr unsigned int outputLocationSize() const
bool isReEntrant() const override
typename ContainerVector::size_type size_type
decltype(auto) const_range(Args &&... args)
Zips multiple containers together to form a single const range.
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs, const std::array< KeyValue, N_out > &outputs)
std::enable_if_t<!std::is_pointer_v< X >, ref_t > operator[](size_type i) const
friend auto operator-(const iterator &lhs, const iterator &rhs)
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >, const OArgs &outputs, std::index_sequence< J... >)
In operator()(In &&in) const
auto operator()(const Handle< Gaudi::Range_< I, IT >> &h) -> const In
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
static auto apply(const Algorithm &algo, Handles &handles)
std::remove_pointer_t< typename Container::value_type > c_remove_ptr_t
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input, const std::array< KeyValue, N_out > &outputs)
std::enable_if_t<!std::is_pointer_v< X >, ref_t > at(size_type i) const
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
constexpr unsigned int inputLocationSize() const
bool check_sizes(const A &a, const B &b, const C &... c) noexcept
Compare sizes of 3 or more containers.
void operator()(F &&f, Arg &&arg) const
static auto apply(const Algorithm &algo, const EventContext &ctx, Handles &handles)
typename Tr::template InputHandle< T > InputHandle_t
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const OArgs &outputs, std::index_sequence< J... >)
std::conditional_t< is_pointer, ptr_t, val_t > value_type
typename details::detector< Default, void, Op, Args... >::type detected_or_t
Base class from which all concrete algorithm classes should be derived.
auto applyPostProcessing(const Fun &fun, Container &c) -> decltype(fun.postprocess(c), void())
Gaudi::cpp17::detected_or_t< DataObjectReadHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
constexpr unsigned int inputLocationSize() const
void put(const OutHandle &out_handle, OptOut &&out)
static auto apply(const Algorithm &algo, Handles &handles)
typename Tr::template OutputHandle< T > OutputHandle_t
constexpr struct Gaudi::Functional::details::deref_t deref
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
std::enable_if_t< std::is_pointer_v< X >, ptr_t > at(size_type i) const
std::enable_if_t< is_optional_v< Arg > > require_is_optional
void push_back(T &&container)
void updateHandleLocation(DataHandleMixin< Out, In, Tr > &parent, const std::string &prop, const std::string &newLoc)
Header file for std:chrono::duration-based Counters.
friend bool operator==(const iterator &lhs, const iterator &rhs)
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
bool isReEntrant() const override
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator)
const In & operator()(const In &in) const
T * put(std::unique_ptr< T > object) const
Register object in transient store.
decltype(auto) verifySizes(Args &... args)
Verify the data container sizes have the same sizes.
static auto apply(const Algorithm &algo, const EventContext &ctx, Handles &handles)
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
friend bool operator!=(const iterator &lhs, const iterator &rhs)
std::conditional_t< is_optional_v< T >, typename T::value_type, T > remove_optional_t
typename it_t::difference_type difference_type
constexpr bool is_optional_v
Gaudi::cpp17::detected_or_t< GaudiAlgorithm, detail2::BaseClass_t, Tr > BaseClass_t
void push_back(Container &c, const Value &v, std::false_type)
T & deref_if(T *const t, std::true_type)
constexpr unsigned int outputLocationSize() const
typename it_t::iterator_category value_type
typename it_t::pointer pointer
typename ContainerVector::const_iterator it_t
void updateHandleLocations(DataHandleMixin< Out, In, Tr > &parent, const std::string &prop, const std::vector< std::string > &newLocs)
auto operator()(Container &c, Value &&v) const -> decltype(c.insert(v))
std::add_lvalue_reference_t< val_t > ref_t
typename it_t::reference reference
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_out > &outputs)
auto operator()(const Handle< Gaudi::NamedRange_< I, IT >> &h) -> const In
void printSizes(OS &out, Arg &&arg, Args &&... args)
Print the parameters.
constexpr static const auto FAILURE
std::conditional_t< is_pointer, ptr_t, ref_t > ret_t
constexpr struct Gaudi::Functional::details::insert_t insert
auto operator()(const Handle< I > &h) -> const In
Gaudi::cpp17::detected_or_t< DataObjectWriteHandle< T >, detail2::OutputHandle_t, Tr, T > OutputHandle_t
typename filter_evtcontext_t< In... >::type filter_evtcontext
vector_of_const_()=default
std::add_pointer_t< val_t > ptr_t
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input)
auto getKey(const Handle &h) -> decltype(h.objKey())
bool is_null(size_type i) const