1 #ifndef FUNCTIONAL_DETAILS_H 2 #define FUNCTIONAL_DETAILS_H 18 #include <range/v3/version.hpp> 19 #include <range/v3/view/const.hpp> 20 #include <range/v3/view/zip.hpp> 22 #if RANGE_V3_VERSION < 900 24 using namespace ranges::view;
28 #if defined( __clang__ ) && ( __clang_major__ < 9 ) 29 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN \ 30 _Pragma( "clang diagnostic push" ) _Pragma( "clang diagnostic ignored \"-Wunused-lambda-capture\"" ) 31 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END _Pragma( "clang diagnostic pop" ) 33 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN 34 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END 43 template <
typename OS,
typename Arg>
49 template <
typename OS,
typename Arg,
typename... Args>
63 template <
typename A,
typename B>
65 return a.size() == b.size();
69 template <
typename A,
typename B,
typename... C>
70 inline bool check_sizes(
const A& a,
const B& b,
const C&...
c ) noexcept {
75 template <
typename... Args>
79 mess <<
"Zipped containers have different sizes : ";
86 template <
typename... Args>
91 return ranges::views::zip( std::forward<Args>(
args )... );
95 template <
typename... Args>
100 return ranges::views::const_( ranges::views::zip( std::forward<Args>(
args )... ) );
108 template <
typename T>
109 using is_optional_ = decltype(
bool{std::declval<T>()}, std::declval<T>().value() );
111 template <
typename Arg>
112 constexpr
bool is_optional_v = Gaudi::cpp17::is_detected_v<details2::is_optional_, Arg>;
114 template <
typename Arg>
117 template <
typename Arg>
120 template <
typename T>
124 template <
typename F,
typename Arg,
typename = require_is_not_optional<Arg>>
125 decltype(
auto ) operator()( F&& f, Arg&& arg )
const {
126 return std::invoke( std::forward<F>( f ), std::forward<Arg>( arg ) );
128 template <
typename F,
typename Arg,
typename = require_is_optional<Arg>>
130 if ( arg ) std::invoke( std::forward<F>( f ), *std::forward<Arg>( arg ) );
135 template <
typename Out1,
typename Out2,
136 typename = std::enable_if_t<std::is_constructible_v<Out1, Out2> && std::is_base_of_v<DataObject, Out1>>>
138 return out_handle.
put( std::make_unique<Out1>( std::forward<Out2>( out ) ) );
141 template <
typename Out1,
typename Out2,
typename = std::enable_if_t<std::is_constructible_v<Out1, Out2>>>
143 out_handle.put( std::forward<Out2>( out ) );
147 template <
typename OutHandle,
typename OptOut,
typename = require_is_optional<OptOut>>
148 void put(
const OutHandle& out_handle, OptOut&& out ) {
149 if ( out )
put( out_handle, *std::forward<OptOut>( out ) );
158 template <
typename Container>
161 template <
typename Container,
typename Value>
162 auto operator()( Container&
c, Value&& v )
const -> decltype(
c.push_back( v ) ) {
163 return c.push_back( std::forward<Value>( v ) );
166 template <
typename Container,
typename Value>
167 auto operator()( Container&
c, Value&& v )
const -> decltype(
c.insert( v ) ) {
168 return c.insert( std::forward<Value>( v ) );
172 template <
typename Container,
typename Value,
173 typename = std::enable_if_t<std::is_pointer_v<typename Container::value_type>>,
174 typename = std::enable_if_t<std::is_convertible_v<Value, c_remove_ptr_t<Container>>>>
184 template <
typename In,
typename = std::enable_if_t<!std::is_po
inter_v<In>>>
189 template <
typename In>
191 assert( in !=
nullptr );
199 template <
typename Container,
typename Value>
203 template <
typename Container,
typename Value>
208 template <
typename In>
210 template <
template <
typename>
class Handle,
typename I,
typename = std::enable_if_t<std::is_convertible_v<I, In>>>
214 template <
template <
typename>
class Handle,
typename I,
215 typename = std::enable_if_t<std::is_convertible_v<I*, In>>>
217 return h.getIfExists();
221 template <
typename T>
225 template <
typename T>
231 template <
typename Container>
233 static constexpr
bool is_pointer = std::is_pointer_v<Container>;
234 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
235 using ptr_t = std::add_pointer_t<val_t>;
236 using ref_t = std::add_lvalue_reference_t<val_t>;
241 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
244 using it_t =
typename ContainerVector::const_iterator;
248 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
270 explicit operator bool()
const {
return !is_null(); }
274 template <
typename T>
276 details2::push_back( m_containers, std::forward<T>( container ), std::bool_constant<is_pointer>{} );
282 template <
typename X = Container>
284 return *m_containers[i];
287 template <
typename X = Container>
289 return m_containers[i];
292 template <
typename X = Container>
294 return *m_containers[i];
297 template <
typename X = Container>
299 return m_containers[i];
307 template <
typename Tr>
309 template <
typename Tr,
typename T>
311 template <
typename Tr,
typename T>
318 template <
typename Tr>
319 using BaseClass_t = Gaudi::cpp17::detected_or_t<GaudiAlgorithm, detail2::BaseClass_t, Tr>;
324 template <
typename Tr,
typename T>
326 template <
typename Tr,
typename T>
329 template <
typename Traits>
331 std::is_base_of_v<Gaudi::details::LegacyAlgorithmAdapter, details::BaseClass_t<Traits>>;
335 template <
typename Handles>
338 handles.reserve( init.
size() );
347 template <
typename Handle,
typename Algo>
354 template <
typename Handle>
355 auto getKey(
const Handle& h ) -> decltype( h.objKey() ) {
361 template <
typename... In>
366 "EventContext can only appear as first argument" );
368 template <
typename Algorithm,
typename Handles>
370 return std::apply( [&](
const auto&... handle ) {
return algo(
details::deref( handle.get() )... ); }, handles );
372 template <
typename Algorithm,
typename Handles>
374 return std::apply( [&](
const auto&... handle ) {
return algo(
get( handle, algo,
ctx )... ); }, handles );
379 template <
typename... In>
384 "EventContext can only appear as first argument" );
386 template <
typename Algorithm,
typename Handles>
389 [&](
const auto&... handle ) {
391 return algo(
ctx,
get( handle, algo,
ctx )... );
396 template <
typename Algorithm,
typename Handles>
398 return std::apply( [&](
const auto&... handle ) {
return algo(
ctx,
get( handle, algo,
ctx )... ); }, handles );
402 template <
typename... In>
405 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
408 template <
typename Out,
typename In,
typename Tr>
411 auto sc = parent.setProperty( prop, newLoc );
412 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + newLoc, sc );
415 template <
typename Out,
typename In,
typename Tr>
420 ss <<
'[', newLocs,
", ", [](
std::ostream & os,
const auto& i ) ->
auto& {
return os <<
"'" << i <<
"'"; } )
422 auto sc = parent.setProperty( prop, ss.
str() );
423 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + ss.
str(), sc );
426 template <
typename... Out,
typename... In,
typename Traits_>
432 const OArgs& outputs, std::index_sequence<J...> )
434 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... )
435 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
450 std::index_sequence_for<Out...>{} ) {}
465 template <std::
size_t N = 0>
466 decltype(
auto ) inputLocation()
const {
467 return getKey( std::get<N>( m_inputs ) );
471 template <std::
size_t N = 0>
472 decltype(
auto ) outputLocation()
const {
473 return getKey( std::get<N>( m_outputs ) );
484 template <
typename Traits_>
499 template <
typename... In,
typename Traits_>
506 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... ) {
524 template <std::
size_t N = 0>
525 decltype(
auto ) inputLocation()
const {
526 return getKey( std::get<N>( m_inputs ) );
537 template <
typename... Out,
typename Traits_>
543 std::index_sequence<J...> )
545 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
562 template <std::
size_t N = 0>
563 decltype(
auto ) outputLocation()
const {
564 return getKey( std::get<N>( m_outputs ) );
575 template <
typename Fun,
typename Container,
typename... Args>
577 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
580 template <
typename Fun,
typename Container>
582 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.
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
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs, const std::array< KeyValue, N_out > &outputs)
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
void push_back(T &&container)
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)
DataHandleMixin(const std::string &name, ISvcLocator *locator, const std::array< KeyValue, N_in > &inputs, const KeyValue &output)
std::add_lvalue_reference_t< val_t > ref_t
typename Tr::BaseClass BaseClass_t
Header file for class GaudiAlgorithm.
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 &
void put(const OutHandle &out_handle, OptOut &&out)
bool isReEntrant() const override
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()))
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator)
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
This class represents an entry point to all the event specific data.
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
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.
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &output)
typename Tr::template InputHandle< T > InputHandle_t
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
constexpr unsigned int inputLocationSize() const
constexpr unsigned int outputLocationSize() const
decltype(auto) verifySizes(Args &... args)
Verify the data container sizes have the same sizes.
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_out > &outputs)
decltype(auto) const_range(Args &&... args)
Zips multiple containers together to form a single const range.
constexpr unsigned int inputLocationSize() const
typename filter_evtcontext_t< In... >::type filter_evtcontext
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >)
T & deref_if(T *const t, std::true_type)
bool is_null(size_type i) const
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
typename Tr::template OutputHandle< T > OutputHandle_t
GAUDI_API const EventContext & currentContext()
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs)
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
constexpr unsigned int outputLocationSize() const
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
static auto apply(const Algorithm &algo, const EventContext &ctx, Handles &handles)
typename it_t::difference_type difference_type
Alias for backward compatibility.
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
bool isReEntrant() const override
T back_inserter(T... args)
auto operator()(const Handle< I > &h) -> const In
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >, const OArgs &outputs, std::index_sequence< J... >)
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)
bool isReEntrant() const override
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &input)
std::conditional_t< is_pointer, ptr_t, ref_t > ret_t
std::remove_pointer_t< typename Container::value_type > c_remove_ptr_t
auto operator()(Container &c, Value &&v) const -> decltype(c.push_back(v))
constexpr static const auto FAILURE
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.
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &input, const KeyValue &output)
constexpr struct ranges::Gaudi::Functional::details::deref_t deref
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const OArgs &outputs, std::index_sequence< J... >)
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
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &input, const std::array< KeyValue, N_out > &outputs)
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
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