1 #ifndef FUNCTIONAL_DETAILS_H 2 #define FUNCTIONAL_DETAILS_H 20 #include "boost/optional.hpp" 23 #include <range/v3/view/const.hpp> 24 #include <range/v3/view/zip.hpp> 38 template <
typename OS,
typename Arg>
45 template <
typename OS,
typename Arg,
typename... Args>
61 template <
typename A,
typename B>
64 return a.size() == b.size();
68 template <
typename A,
typename B,
typename... C>
69 inline bool check_sizes(
const A& a,
const B& b,
const C&...
c ) noexcept
75 template <
typename... Args>
80 mess <<
"Zipped containers have different sizes : ";
87 template <
typename... Args>
93 return ranges::view::zip( std::forward<Args>( args )... );
97 template <
typename... Args>
103 return ranges::view::const_( ranges::view::zip( std::forward<Args>( args )... ) );
107 #if __cplusplus < 201703L 109 template <
typename T>
110 constexpr std::add_const_t<T>&
as_const( T& t ) noexcept
115 template <
typename T>
124 template <
class B1,
class... Bn>
125 struct disjunction<B1, Bn...> : std::conditional_t<bool( B1::value ), B1, disjunction<Bn...>> {
130 using std::disjunction;
137 template <
typename T>
138 using is_optional_ = decltype(
bool( std::declval<T>() ), std::declval<T>().value() );
140 template <
typename Arg>
141 using is_optional =
typename Gaudi::cpp17::is_detected<details2::is_optional_, Arg>;
143 template <
typename Arg>
146 template <
typename Arg>
151 template <
typename T,
typename =
void>
156 template <
typename T>
158 using type =
typename T::value_type;
162 template <
typename T>
166 template <
typename F,
typename Arg,
typename = require_is_not_optional<Arg>>
167 decltype(
auto )
operator()( F&& f, Arg&& arg )
const 169 return Gaudi::invoke( std::forward<F>( f ), std::forward<Arg>( arg ) );
171 template <
typename F,
typename Arg,
typename = require_is_optional<Arg>>
174 if ( arg )
Gaudi::invoke( std::forward<F>( f ), *std::forward<Arg>( arg ) );
179 template <typename Out1, typename Out2, typename = std::enable_if_t<std::is_constructible<Out1, Out2>::value &&
183 return out_handle.
put( std::make_unique<Out1>( std::forward<Out2>( out ) ) );
186 template <typename Out1, typename Out2, typename = std::enable_if_t<std::is_constructible<Out1, Out2>::value>>
189 out_handle.put( std::forward<Out2>( out ) );
193 template <
typename OutHandle,
typename OptOut,
typename = require_is_optional<OptOut>>
194 void put( OutHandle& out_handle, OptOut&& out )
196 if ( out )
put( out_handle, *std::forward<OptOut>( out ) );
205 template <
typename Container>
208 template <
typename Container,
typename Value>
211 return c.push_back( std::forward<Value>( v ) );
214 template <
typename Container,
typename Value>
217 return c.insert( std::forward<Value>( v ) );
221 template <
typename Container,
222 typename = std::enable_if_t<std::is_pointer<typename Container::value_type>::value>>
233 template <typename In, typename = std::enable_if_t<!std::is_pointer<In>::value>>
239 template <
typename In>
242 assert( in !=
nullptr );
251 template <
typename Container,
typename Value>
256 template <
typename Container,
typename Value>
262 template <
typename In>
264 template <
template <
typename>
class Handle,
typename I,
265 typename = std::enable_if_t<std::is_convertible<I, In>::value>>
270 template <
template <
typename>
class Handle,
typename I,
271 typename = std::enable_if_t<std::is_convertible<I*, In>::value>>
274 return h.getIfExists();
278 template <
typename T>
283 template <
typename T>
290 template <
typename Container>
294 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
295 using ptr_t = std::add_pointer_t<val_t>;
296 using ref_t = std::add_lvalue_reference_t<val_t>;
301 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
305 typename ContainerVector::const_iterator
m_i;
307 iterator(
typename ContainerVector::const_iterator iter ) : m_i( iter ) {}
308 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
324 explicit operator bool()
const {
return !is_null(); }
328 template <
typename T>
337 template <
typename X = Container>
340 return *m_containers[i];
343 template <
typename X = Container>
346 return m_containers[i];
349 template <
typename X = Container>
352 return *m_containers[i];
355 template <
typename X = Container>
358 return m_containers[i];
367 template <
typename Tr>
369 template <
typename Tr,
typename T>
371 template <
typename Tr,
typename T>
378 template <
typename Tr>
379 using BaseClass_t = Gaudi::cpp17::detected_or_t<GaudiAlgorithm, detail2::BaseClass_t, Tr>;
384 template <
typename Tr,
typename T>
386 template <
typename Tr,
typename T>
391 template <
typename Handles>
395 handles.reserve( init.
size() );
397 [&](
const std::string& loc ) ->
typename Handles::value_type {
405 template <
typename... In>
410 "EventContext can only appear as first argument" );
412 template <
typename Algorithm,
typename Handles>
421 template <
typename... In>
426 "EventContext can only appear as first argument" );
428 template <
typename Algorithm,
typename Handles>
432 [&](
const auto&... handle ) {
439 template <
typename... In>
442 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
445 template <
typename... Out,
typename... In,
typename Traits_>
449 "BaseClass must inherit from Algorithm" );
453 std::index_sequence<I...>,
const OArgs& outputs, std::index_sequence<J...> )
456 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... )
470 :
DataHandleMixin( name, pSvcLocator, inputs,
std::index_sequence_for<In...>{}, outputs,
471 std::index_sequence_for<Out...>{} )
494 template <std::
size_t N = 0>
497 return std::get<N>(
m_inputs ).objKey();
501 template <std::
size_t N = 0>
504 return std::get<N>( m_outputs ).objKey();
513 template <
typename Traits_>
517 "BaseClass must inherit from Algorithm" );
530 template <
typename... In,
typename Traits_>
534 "BaseClass must inherit from Algorithm" );
538 std::index_sequence<I...> )
563 template <std::
size_t N = 0>
566 return std::get<N>(
m_inputs ).objKey();
574 template <
typename... Out,
typename Traits_>
578 "BaseClass must inherit from Algorithm" );
582 std::index_sequence<J...> )
584 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... )
606 template <std::
size_t N = 0>
609 return std::get<N>( m_outputs ).objKey();
618 template <
typename Fun,
typename Container,
typename... Args>
621 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
624 template <
typename Fun,
typename Container>
627 fun.postprocess(
c );
typename Tr::template InputHandle< T > InputHandle_t
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_out > &outputs)
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs)
auto operator()(Container &c, Value &&v) const -> decltype(c.insert(v))
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
std::enable_if_t< std::is_pointer< X >::value, ptr_t > at(size_type i) const
typename Tr::BaseClass BaseClass_t
constexpr static const auto FAILURE
std::enable_if_t<!std::is_pointer< X >::value, ref_t > operator[](size_type i) const
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >, const OArgs &outputs, std::index_sequence< J... >)
const In & operator()(const In &in) const
Define general base for Gaudi exception.
DataHandleMixin(const std::string &name, ISvcLocator *locator, const std::array< KeyValue, N_in > &inputs, const KeyValue &output)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
void reserve(size_type size)
constexpr unsigned int inputLocationSize() const
friend bool operator!=(const iterator &lhs, const iterator &rhs)
void as_const(T &&t)=delete
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
auto operator()(Container &c, c_remove_ptr_t< Container > &&v) const
Gaudi::cpp17::detected_or_t< DataObjectReadHandle< T >, detail2::InputHandle_t, Tr, T > InputHandle_t
void printSizes(OS &out, Arg &&arg)
Print the parameter.
constexpr unsigned int outputLocationSize() const
const std::string & outputLocation() const
std::enable_if_t<!std::is_pointer< X >::value, ref_t > at(size_type i) const
void operator()(F &&f, Arg &&arg) const
ContainerVector::const_iterator m_i
constexpr struct Gaudi::Functional::details::insert_t insert
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const std::array< KeyValue, N_in > &inputs, const std::array< KeyValue, N_out > &outputs)
Header file for class GaudiAlgorithm.
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &input, const KeyValue &output)
std::add_const_t< std::remove_pointer_t< Container >> val_t
decltype(bool(std::declval< T >()), std::declval< T >().value()) is_optional_
typename Gaudi::cpp17::is_detected< details2::is_optional_, Arg > is_optional
bool is_null(size_type i) const
class MergingTransformer< Out(const vector_of_const_< In > void
decltype(auto) constexpr apply(F &&f, Tuple &&t) noexcept(noexcept( detail::apply_impl(std::forward< F >(f), std::forward< Tuple >(t), std::make_index_sequence< std::tuple_size< std::remove_reference_t< Tuple >>::value >{})))
typename filter_evtcontext_t< In... >::type filter_evtcontext
auto operator()(Container &c, Value &&v) const -> decltype(c.push_back(v))
typename T::value_type type
const std::string & inputLocation() const
std::enable_if_t<!is_optional< Arg >::value > require_is_not_optional
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const OArgs &outputs, std::index_sequence< J... >)
void push_back(Container &c, const Value &v, std::true_type)
std::remove_pointer_t< typename Container::value_type > c_remove_ptr_t
iterator(typename ContainerVector::const_iterator iter)
std::add_lvalue_reference_t< val_t > ref_t
This class represents an entry point to all the event specific data.
T * deref_if(T *const t, std::false_type)
constexpr struct Gaudi::Functional::details::deref_t deref
constexpr auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
constexpr unsigned int outputLocationSize() const
constexpr unsigned int inputLocationSize() const
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
constexpr struct Gaudi::Functional::details::invoke_optionally_t invoke_optionally
typename Tr::template OutputHandle< T > OutputHandle_t
Entity which holds DataHandles and can track the associated data dependencies for the Scheduler...
ContainerVector m_containers
const std::string & inputLocation() const
constexpr void applyPostProcessing(const Fun &, Container &, Args...)
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &input, const std::array< KeyValue, N_out > &outputs)
const std::string & outputLocation() const
auto operator()(const Handle< I > &h) -> const In &
static auto apply(const Algorithm &algo, Handles &handles)
typename details2::remove_optional< T >::type remove_optional_t
GAUDI_API const EventContext & currentContext()
auto operator()(const Handle< I > &h) -> const In
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &output)
static auto apply(const Algorithm &algo, Handles &handles)
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
std::conditional_t< is_pointer, ptr_t, ref_t > ret_t
std::conditional_t< is_pointer, ptr_t, val_t > value_type
std::enable_if_t< std::is_pointer< X >::value, ptr_t > operator[](size_type i) const
decltype(auto) verifySizes(Args &...args)
Verify the data container sizes have the same sizes.
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator)
constexpr std::add_const_t< T > & as_const(T &t) noexcept
Base class from which all concrete algorithm classes should be derived.
std::enable_if_t< is_optional< Arg >::value > require_is_optional
T * put(std::unique_ptr< T > object)
Register object in transient store.
std::vector< InputHandle_t< In > > m_inputs
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
bool check_sizes(const A &) noexcept
Resolve case there is only one container in the range.
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
void push_back(T &&container)
Gaudi::cpp17::detected_or_t< DataObjectWriteHandle< T >, detail2::OutputHandle_t, Tr, T > OutputHandle_t
T back_inserter(T...args)
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
double fun(const std::vector< double > &x)
DataHandleMixin(const std::string &name, ISvcLocator *locator, const KeyValue &input)
struct[[deprecated("use MergingTransformer instead")]] Traits_
std::add_pointer_t< val_t > ptr_t
auto invoke(F &&f, ArgTypes &&...args) noexcept(noexcept(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))) -> decltype(detail2::INVOKE(std::forward< F >(f), std::forward< ArgTypes >(args)...))
const In & operator()(const In *in) const
decltype(auto) const_range(Args &&...args)
Zips multiple containers together to form a single const range.
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< std::string > &init)
std::tuple< details::InputHandle_t< Traits_, In >... > m_inputs
T & deref_if(T *const t, std::true_type)
Helper functions to set/get the application return code.
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
Gaudi::cpp17::detected_or_t< GaudiAlgorithm, detail2::BaseClass_t, Tr > BaseClass_t
Out1 * put(DataObjectHandle< Out1 > &out_handle, Out2 &&out)
void push_back(Container &c, const Value &v, std::false_type)
DataHandleMixin(const std::string &name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >)
typename ContainerVector::size_type size_type