Go to the documentation of this file.
11 #ifndef FUNCTIONAL_DETAILS_H
12 #define FUNCTIONAL_DETAILS_H
17 #include <type_traits>
29 #include <range/v3/version.hpp>
30 #include <range/v3/view/const.hpp>
31 #include <range/v3/view/zip.hpp>
33 #if RANGE_V3_VERSION < 900
35 using namespace ranges::view;
39 #if defined( __clang__ ) && ( __clang_major__ < 11 ) || defined( __APPLE__ ) && ( __clang_major__ < 12 )
40 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN \
41 _Pragma( "clang diagnostic push" ) _Pragma( "clang diagnostic ignored \"-Wunused-lambda-capture\"" )
42 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END _Pragma( "clang diagnostic pop" )
44 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN
45 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
50 #define GAUDI_FUNCTIONAL_CONSTRUCTOR_USES_TUPLE
58 template <
typename OS,
typename Arg>
64 template <
typename OS,
typename Arg,
typename... Args>
78 template <
typename A,
typename B>
80 return a.size() == b.size();
84 template <
typename A,
typename B,
typename... C>
85 inline bool check_sizes(
const A& a,
const B& b,
const C&...
c ) noexcept {
90 template <
typename... Args>
94 mess <<
"Zipped containers have different sizes : ";
101 template <
typename... Args>
106 return ranges::views::zip( std::forward<Args>(
args )... );
110 template <
typename... Args>
115 return ranges::views::const_( ranges::views::zip( std::forward<Args>(
args )... ) );
123 template <
typename T>
124 using is_optional_ = decltype(
bool{ std::declval<T>() }, std::declval<T>().value() );
126 template <
typename Arg>
127 constexpr
bool is_optional_v = Gaudi::cpp17::is_detected_v<details2::is_optional_, Arg>;
129 template <
typename Arg>
132 template <
typename Arg>
135 template <
typename T>
139 template <
typename F,
typename Arg,
typename = require_is_not_optional<Arg>>
140 decltype(
auto ) operator()( F&& f, Arg&& arg )
const {
141 return std::invoke( std::forward<F>( f ), std::forward<Arg>( arg ) );
143 template <
typename F,
typename Arg,
typename = require_is_optional<Arg>>
145 if ( arg ) std::invoke( std::forward<F>( f ), *std::forward<Arg>( arg ) );
155 template <
typename Value, auto N>
156 using RepeatValues_ = decltype( get_values_helper<Value>( std::make_index_sequence<N>() ) );
160 template <
typename Out1,
typename Out2,
161 typename = std::enable_if_t<std::is_constructible_v<Out1, Out2> && std::is_base_of_v<DataObject, Out1>>>
163 return out_handle.
put( std::make_unique<Out1>( std::forward<Out2>(
out ) ) );
166 template <
typename Out1,
typename Out2,
typename = std::enable_if_t<std::is_constructible_v<Out1, Out2>>>
168 return out_handle.put( std::forward<Out2>(
out ) );
172 template <
typename OutHandle,
typename OptOut,
typename = require_is_optional<OptOut>>
173 void put(
const OutHandle& out_handle, OptOut&&
out ) {
174 if (
out )
put( out_handle, *std::forward<OptOut>(
out ) );
184 template <
typename Container>
187 template <
typename Container,
typename Value>
188 auto operator()( Container&
c, Value&&
v )
const -> decltype(
c.push_back(
v ) ) {
189 return c.push_back( std::forward<Value>(
v ) );
192 template <
typename Container,
typename Value>
194 return c.insert( std::forward<Value>(
v ) );
198 template <
typename Container,
typename Value,
199 typename = std::enable_if_t<std::is_pointer_v<typename Container::value_type>>,
200 typename = std::enable_if_t<std::is_convertible_v<Value, c_remove_ptr_t<Container>>>>
210 template <
typename In,
typename = std::enable_if_t<!std::is_po
inter_v<In>>>
215 template <
typename In,
typename = std::enable_if_t<!std::is_po
inter_v<std::decay_t<In>>>>
217 return std::forward<In>( in );
220 template <
typename In>
222 assert( in !=
nullptr );
230 template <
typename T>
233 template <
typename T,
typename IT>
236 template <
typename T,
typename IT>
239 template <
typename T>
242 template <
typename Container,
typename Value>
246 template <
typename Container,
typename Value>
251 template <
typename In>
253 template <
template <
typename>
class Handle,
typename I,
typename = std::enable_if_t<std::is_convertible_v<I, In>>>
257 template <
template <
typename>
class Handle,
typename I,
typename IT>
261 template <
template <
typename>
class Handle,
typename I,
typename IT>
265 template <
template <
typename>
class Handle,
typename I,
266 typename = std::enable_if_t<std::is_convertible_v<I*, In>>>
268 return h.getIfExists();
272 template <
typename T>
276 template <
typename T>
282 template <
typename Container>
284 static constexpr
bool is_pointer = std::is_pointer_v<Container>;
285 static constexpr
bool is_range = details2::is_gaudi_range_v<Container>;
286 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
287 using ptr_t = std::add_pointer_t<val_t>;
288 using ref_t = std::add_lvalue_reference_t<val_t>;
293 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
296 using it_t =
typename ContainerVector::const_iterator;
300 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
313 if constexpr ( is_range ) {
328 explicit operator bool()
const {
return !is_null(); }
332 template <
typename T>
335 std::bool_constant < is_pointer or is_range > {} );
341 template <
typename X = Container>
343 return *m_containers[i];
346 template <
typename X = Container>
348 return m_containers[i];
351 template <
typename X = Container>
353 return *m_containers[i];
356 template <
typename X = Container>
358 return m_containers[i];
366 template <
typename Tr>
368 template <
typename Tr,
typename T>
370 template <
typename Tr,
typename T>
373 template <
typename T>
382 template <
typename Tr,
typename Base = GaudiAlgorithm>
389 template <
typename Tr,
typename T>
391 template <
typename Tr,
typename T>
394 template <
typename Traits>
396 std::is_base_of_v<Gaudi::details::LegacyAlgorithmAdapter, details::BaseClass_t<Traits>>;
400 template <
typename Handles>
403 handles.reserve( init.
size() );
405 [&](
const std::string& loc ) ->
typename Handles::value_type {
406 return { loc, owner };
411 template <
typename Handle,
typename Algo>
418 template <
typename IFace,
typename Algo>
420 return handle.bind(
ctx );
423 template <
typename Handle>
424 auto getKey(
const Handle&
h ) -> decltype(
h.objKey() ) {
430 template <
typename... In>
435 "EventContext can only appear as first argument" );
437 template <
typename Algorithm,
typename Handles>
443 template <
typename Algorithm,
typename Handles>
445 return std::apply( [&](
const auto&... handle ) {
return algo(
get( handle, algo,
ctx )... ); }, handles );
450 template <
typename... In>
455 "EventContext can only appear as first argument" );
457 template <
typename Algorithm,
typename Handles>
459 return std::apply( [&](
const auto&... handle ) {
return algo(
ctx,
get( handle, algo,
ctx )... ); }, handles );
462 template <
typename Algorithm,
typename Handles>
468 template <
typename... In>
471 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
474 template <
typename Out,
typename In,
typename Tr>
477 auto sc = parent.setProperty( prop, newLoc );
478 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + newLoc, sc );
481 template <
typename Out,
typename In,
typename Tr>
486 ss <<
'[', newLocs,
", ", [](
std::ostream & os,
const auto& i ) ->
auto& {
return os <<
"'" << i <<
"'"; } )
488 auto sc = parent.setProperty( prop, ss.
str() );
489 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + ss.
str(), sc );
492 template <
typename... Out,
typename... In,
typename Traits_>
498 const OArgs& outputs, std::index_sequence<J...> )
500 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... )
501 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
517 std::index_sequence_for<Out...>{} ) {}
533 template <std::
size_t N = 0>
534 decltype(
auto ) inputLocation()
const {
535 return getKey( std::get<N>( m_inputs ) );
537 template <
typename T>
538 decltype(
auto ) inputLocation()
const {
543 template <std::
size_t N = 0>
544 decltype(
auto ) outputLocation()
const {
545 return getKey( std::get<N>( m_outputs ) );
547 template <
typename T>
548 decltype(
auto ) outputLocation()
const {
560 template <
typename Traits_>
579 template <
typename... In,
typename Traits_>
586 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... ) {
605 template <std::
size_t N = 0>
606 decltype(
auto ) inputLocation()
const {
607 return getKey( std::get<N>( m_inputs ) );
609 template <
typename T>
610 decltype(
auto ) inputLocation()
const {
621 template <
typename Traits_>
628 template <
typename... Out,
typename Traits_>
635 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
653 template <std::
size_t N = 0>
654 decltype(
auto ) outputLocation()
const {
655 return getKey( std::get<N>( m_outputs ) );
666 template <
typename Fun,
typename Container,
typename... Args>
668 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
671 template <
typename Fun,
typename Container>
673 fun.postprocess(
c );
typename Tr::BaseClass BaseClass_t
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
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)
auto get(const ToolHandle< Gaudi::Interface::Bind::IBinder< IFace >> &handle, const Algo &, const EventContext &ctx)
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)
Gaudi::cpp17::detected_or_t< detail2::DefaultInputHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, RepeatValues_< KeyValue, N_out > const &outputs)
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))
std::conditional_t< std::is_base_of_v< IAlgTool, T >, ToolHandle< Gaudi::Interface::Bind::IBinder< T > >, DataObjectReadHandle< T > > DefaultInputHandle
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 *locator, RepeatValues_< KeyValue, N_in > const &inputs, const KeyValue &output)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
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... >)
auto get_values_helper(std::index_sequence< I... >)
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 *pSvcLocator, RepeatValues_< KeyValue, N_in > const &inputs, RepeatValues_< KeyValue, N_out > const &outputs)
std::enable_if_t<!std::is_pointer_v< X >, ref_t > at(size_type i) const
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())
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
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)
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
void push_back(Container &c, const Value &v, std::false_type)
T & deref_if(T *const t, std::true_type)
decltype(get_values_helper< Value >(std::make_index_sequence< N >())) RepeatValues_
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
auto operator()(const Handle< Gaudi::NamedRange_< I, IT >> &h) -> const In
Gaudi::cpp17::detected_or_t< Base, detail2::BaseClass_t, Tr > BaseClass_t
void printSizes(OS &out, Arg &&arg, Args &&... args)
Print the parameters.
constexpr static const auto FAILURE
decltype(bool{ std::declval< T >() }, std::declval< T >().value()) is_optional_
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, std::tuple<>={}, std::tuple<>={})
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
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, RepeatValues_< KeyValue, N_in > const &inputs)
vector_of_const_()=default
std::add_pointer_t< val_t > ptr_t
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input, RepeatValues_< KeyValue, N_out > const &outputs)
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