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__ < 9 ) || 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 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>
177 auto operator()( Container&
c, Value&& v )
const -> decltype(
c.insert( v ) ) {
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 Container,
typename Value>
218 template <
typename Container,
typename Value>
223 template <
typename In>
225 template <
template <
typename>
class Handle,
typename I,
typename = std::enable_if_t<std::is_convertible_v<I, In>>>
229 template <
template <
typename>
class Handle,
typename I,
230 typename = std::enable_if_t<std::is_convertible_v<I*, In>>>
232 return h.getIfExists();
236 template <
typename T>
240 template <
typename T>
246 template <
typename Container>
248 static constexpr
bool is_pointer = std::is_pointer_v<Container>;
249 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
250 using ptr_t = std::add_pointer_t<val_t>;
251 using ref_t = std::add_lvalue_reference_t<val_t>;
256 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
259 using it_t =
typename ContainerVector::const_iterator;
263 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
285 explicit operator bool()
const {
return !is_null(); }
289 template <
typename T>
291 details2::push_back( m_containers, std::forward<T>( container ), std::bool_constant<is_pointer>{} );
297 template <
typename X = Container>
299 return *m_containers[i];
302 template <
typename X = Container>
304 return m_containers[i];
307 template <
typename X = Container>
309 return *m_containers[i];
312 template <
typename X = Container>
314 return m_containers[i];
322 template <
typename Tr>
324 template <
typename Tr,
typename T>
326 template <
typename Tr,
typename T>
333 template <
typename Tr>
334 using BaseClass_t = Gaudi::cpp17::detected_or_t<GaudiAlgorithm, detail2::BaseClass_t, Tr>;
339 template <
typename Tr,
typename T>
341 template <
typename Tr,
typename T>
344 template <
typename Traits>
346 std::is_base_of_v<Gaudi::details::LegacyAlgorithmAdapter, details::BaseClass_t<Traits>>;
350 template <
typename Handles>
353 handles.reserve( init.
size() );
362 template <
typename Handle,
typename Algo>
369 template <
typename Handle>
370 auto getKey(
const Handle& h ) -> decltype( h.objKey() ) {
376 template <
typename... In>
381 "EventContext can only appear as first argument" );
383 template <
typename Algorithm,
typename Handles>
389 template <
typename Algorithm,
typename Handles>
391 return std::apply( [&](
const auto&... handle ) {
return algo(
get( handle, algo,
ctx )... ); }, handles );
396 template <
typename... In>
401 "EventContext can only appear as first argument" );
403 template <
typename Algorithm,
typename Handles>
405 return std::apply( [&](
const auto&... handle ) {
return algo(
ctx,
get( handle, algo,
ctx )... ); }, handles );
408 template <
typename Algorithm,
typename Handles>
414 template <
typename... In>
417 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
420 template <
typename Out,
typename In,
typename Tr>
424 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + newLoc, sc );
427 template <
typename Out,
typename In,
typename Tr>
432 ss <<
'[', newLocs,
", ", [](
std::ostream & os,
const auto& i ) ->
auto& {
return os <<
"'" << i <<
"'"; } )
435 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + ss.
str(), sc );
438 template <
typename... Out,
typename... In,
typename Traits_>
444 const OArgs& outputs, std::index_sequence<J...> )
446 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... )
447 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
463 std::index_sequence_for<Out...>{} ) {}
479 template <std::
size_t N = 0>
480 decltype(
auto ) inputLocation()
const {
481 return getKey( std::get<N>( m_inputs ) );
483 template <
typename T>
484 decltype(
auto ) inputLocation()
const {
489 template <std::
size_t N = 0>
490 decltype(
auto ) outputLocation()
const {
491 return getKey( std::get<N>( m_outputs ) );
493 template <
typename T>
494 decltype(
auto ) outputLocation()
const {
506 template <
typename Traits_>
523 template <
typename... In,
typename Traits_>
530 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... ) {
549 template <std::
size_t N = 0>
550 decltype(
auto ) inputLocation()
const {
551 return getKey( std::get<N>( m_inputs ) );
553 template <
typename T>
554 decltype(
auto ) inputLocation()
const {
565 template <
typename... Out,
typename Traits_>
572 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
590 template <std::
size_t N = 0>
591 decltype(
auto ) outputLocation()
const {
592 return getKey( std::get<N>( m_outputs ) );
603 template <
typename Fun,
typename Container,
typename... Args>
605 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
608 template <
typename Fun,
typename Container>
610 fun.postprocess(
c );
auto operator()(Container &c, Value &&v) const -> decltype(c.insert(v))
auto operator()(Container &c, Value &&v) const
bool check_sizes(const A &a, const B &b, const C &... c) noexcept
Compare sizes of 3 or more containers.
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs, const std::array< KeyValue, N_out > &outputs)
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >)
constexpr auto size(const T &, Args &&...) noexcept
auto applyPostProcessing(const Fun &fun, Container &c) -> decltype(fun.postprocess(c), void())
Gaudi::cpp17::detected_or_t< DataObjectWriteHandle< T >, detail2::OutputHandle_t, Tr, T > OutputHandle_t
void printSizes(OS &out, Arg &&arg, Args &&... args)
Print the parameters.
std::add_const_t< std::remove_pointer_t< Container > > val_t
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
bool isReEntrant() const override
StatusCode setProperty(const Gaudi::Details::PropertyBase &p) override
set the property form another property
void push_back(T &&container)
bool isReEntrant() const override
void operator()(F &&f, Arg &&arg) const
decltype(bool{std::declval< T >()}, std::declval< T >().value()) is_optional_
std::enable_if_t< is_optional_v< Arg > > require_is_optional
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
void reserve(size_type size)
std::add_lvalue_reference_t< val_t > ref_t
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input)
typename Tr::BaseClass BaseClass_t
Header file for class GaudiAlgorithm.
constexpr unsigned int inputLocationSize() const
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_out > &outputs)
T * put(std::unique_ptr< T > object) const
Register object in transient store.
typename it_t::pointer pointer
typename it_t::reference reference
static auto apply(const Algorithm &algo, Handles &handles)
void push_back(Container &c, const Value &v, std::false_type)
auto operator()(const Handle< I > &h) -> const In &
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs)
void put(const OutHandle &out_handle, OptOut &&out)
std::conditional_t< is_optional_v< T >, typename T::value_type, T > remove_optional_t
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
This class represents an entry point to all the event specific data.
typename it_t::iterator_category iterator_category
auto operator *(const std::chrono::duration< Rep1, Period > &lhs, const std::chrono::duration< Rep2, Period > &rhs)
Multiplication of two std::chrono::duration objects with same Period.
typename Tr::template InputHandle< T > InputHandle_t
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator)
constexpr unsigned int inputLocationSize() const
constexpr unsigned int outputLocationSize() const
decltype(auto) verifySizes(Args &... args)
Verify the data container sizes have the same sizes.
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
decltype(auto) const_range(Args &&... args)
Zips multiple containers together to form a single const range.
typename filter_evtcontext_t< In... >::type filter_evtcontext
In operator()(In &&in) const
T & deref_if(T *const t, std::true_type)
bool is_null(size_type i) const
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
typename Tr::template OutputHandle< T > OutputHandle_t
GAUDI_API const EventContext & currentContext()
void updateHandleLocation(DataHandleMixin< Out, In, Tr > &parent, const std::string &prop, const std::string &newLoc)
std::enable_if_t<!is_optional_v< Arg > > require_is_not_optional
std::conditional_t< is_pointer, ptr_t, val_t > value_type
static auto apply(const Algorithm &algo, Handles &handles)
Stream & ostream_joiner(Stream &os, Iterator first, Iterator last, Separator sep, OutputElement output=OutputElement{})
friend bool operator==(const iterator &lhs, const iterator &rhs)
std::enable_if_t<!std::is_pointer_v< X >, ref_t > at(size_type i) const
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input, const KeyValue &output)
static auto apply(const Algorithm &algo, const EventContext &ctx, Handles &handles)
typename it_t::difference_type difference_type
Alias for backward compatibility.
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const OArgs &outputs, std::index_sequence< J... >)
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
std::enable_if_t<!std::is_pointer_v< X >, ref_t > operator[](size_type i) const
typename ContainerVector::size_type size_type
std::enable_if_t< std::is_pointer_v< X >, ptr_t > at(size_type i) const
T back_inserter(T... args)
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &output)
constexpr unsigned int outputLocationSize() const
auto operator()(const Handle< I > &h) -> const In
std::enable_if_t< std::is_pointer_v< X >, ptr_t > operator[](size_type i) const
constexpr struct ranges::Gaudi::Functional::details::insert_t insert
void updateHandleLocations(DataHandleMixin< Out, In, Tr > &parent, const std::string &prop, const std::vector< std::string > &newLocs)
std::conditional_t< is_pointer, ptr_t, ref_t > ret_t
std::remove_pointer_t< typename Container::value_type > c_remove_ptr_t
DataHandleMixin(std::string name, ISvcLocator *locator, const std::array< KeyValue, N_in > &inputs, const KeyValue &output)
auto operator()(Container &c, Value &&v) const -> decltype(c.push_back(v))
constexpr static const auto FAILURE
const Gaudi::Algorithm & parent
bool isReEntrant() const override
const In & operator()(const In &in) const
typename it_t::iterator_category value_type
friend auto operator-(const iterator &lhs, const iterator &rhs)
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init)
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
bool isReEntrant() const override
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
constexpr struct ranges::Gaudi::Functional::details::deref_t deref
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &input, const std::array< KeyValue, N_out > &outputs)
auto getKey(const Handle &h) -> decltype(h.objKey())
friend bool operator!=(const iterator &lhs, const iterator &rhs)
constexpr bool is_optional_v
std::add_pointer_t< val_t > ptr_t
const In & operator()(const In *in) const
constexpr struct ranges::Gaudi::Functional::details::invoke_optionally_t invoke_optionally
Gaudi::cpp17::detected_or_t< DataObjectReadHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >, const OArgs &outputs, std::index_sequence< J... >)
static auto apply(const Algorithm &algo, const EventContext &ctx, Handles &handles)
ContainerVector m_containers
typename ContainerVector::const_iterator it_t
Gaudi::cpp17::detected_or_t< GaudiAlgorithm, detail2::BaseClass_t, Tr > BaseClass_t