1 #ifndef FUNCTIONAL_DETAILS_H 2 #define FUNCTIONAL_DETAILS_H 19 #include "boost/optional.hpp" 22 #include <range/v3/view/const.hpp> 23 #include <range/v3/view/zip.hpp> 37 template <
typename OS,
typename Arg>
44 template <
typename OS,
typename Arg,
typename... Args>
60 template <
typename A,
typename B>
63 return a.size() == b.size();
67 template <
typename A,
typename B,
typename... C>
68 inline bool check_sizes(
const A& a,
const B& b,
const C&...
c ) noexcept
74 template <
typename... Args>
79 mess <<
"Zipped containers have different sizes : ";
86 template <
typename... Args>
92 return ranges::view::zip( std::forward<Args>( args )... );
96 template <
typename... Args>
102 return ranges::view::const_( ranges::view::zip( std::forward<Args>( args )... ) );
106 #if __cplusplus < 201703L 108 template <
typename T>
109 constexpr std::add_const_t<T>&
as_const( T& t ) noexcept
114 template <
typename T>
123 template <
class B1,
class... Bn>
124 struct disjunction<B1, Bn...> : std::conditional_t<bool( B1::value ), B1, disjunction<Bn...>> {
129 using std::disjunction;
133 template <typename Out1, typename Out2, typename = std::enable_if_t<std::is_constructible<Out1, Out2>::value &&
137 return out_handle.
put( std::make_unique<Out1>( std::forward<Out2>( out ) ) );
140 template <typename Out1, typename Out2, typename = std::enable_if_t<std::is_constructible<Out1, Out2>::value>>
143 out_handle.put( std::forward<Out2>( out ) );
147 template <
typename OutHandle,
typename Out>
148 void put( OutHandle& out_handle, boost::optional<Out>&& out )
159 template <
typename Container>
162 template <
typename Container,
typename Value>
165 return c.push_back( std::forward<Value>( v ) );
168 template <
typename Container,
typename Value>
171 return c.insert( std::forward<Value>( v ) );
175 template <
typename Container,
176 typename = std::enable_if_t<std::is_pointer<typename Container::value_type>::value>>
182 template <
typename Container,
typename Value>
192 template <typename In, typename = std::enable_if_t<!std::is_pointer<In>::value>>
198 template <
typename In>
201 assert( in !=
nullptr );
210 template <
typename T>
214 template <
typename T>
220 template <
typename T>
222 template <
typename T>
225 template <
typename T>
234 template <
typename Container,
typename Value>
239 template <
typename Container,
typename Value>
245 template <
typename In>
247 template <
template <
typename>
class Handle,
typename I,
248 typename = std::enable_if_t<std::is_convertible<I, In>::value>>
253 template <
template <
typename>
class Handle,
typename I,
254 typename = std::enable_if_t<std::is_convertible<I*, In>::value>>
257 return h.getIfExists();
261 template <
typename T>
266 template <
typename T>
273 template <
typename Container>
277 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
278 using ptr_t = std::add_pointer_t<val_t>;
279 using ref_t = std::add_lvalue_reference_t<val_t>;
284 using value_type = std::conditional_t<is_optional, ptr_t, val_t>;
288 typename ContainerVector::const_iterator
m_i;
290 iterator(
typename ContainerVector::const_iterator iter ) : m_i( iter ) {}
291 using ret_t = std::conditional_t<is_optional, ptr_t, ref_t>;
307 explicit operator bool()
const {
return !is_null(); }
311 template <
typename T>
324 return *m_containers[i];
332 template <
typename Tr>
334 template <
typename Tr,
typename T>
336 template <
typename Tr,
typename T>
343 template <
typename Tr>
344 using BaseClass_t = Gaudi::cpp17::detected_or_t<GaudiAlgorithm, detail2::BaseClass_t, Tr>;
349 template <
typename Tr,
typename T>
351 template <
typename Tr,
typename T>
356 template <
typename Handles>
360 handles.reserve( init.
size() );
362 [&](
const std::string& loc ) ->
typename Handles::value_type {
370 template <
typename... In>
375 "EventContext can only appear as first argument" );
377 template <
typename Algorithm,
typename Handles>
386 template <
typename... In>
391 "EventContext can only appear as first argument" );
393 template <
typename Algorithm,
typename Handles>
397 [&](
const auto&... handle ) {
404 template <
typename... In>
407 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
410 template <
typename... Out,
typename... In,
typename Traits_>
414 "BaseClass must inherit from Algorithm" );
418 std::index_sequence<I...>,
const OArgs& outputs, std::index_sequence<J...> )
421 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... )
435 :
DataHandleMixin( name, pSvcLocator, inputs,
std::index_sequence_for<In...>{}, outputs,
436 std::index_sequence_for<Out...>{} )
459 template <std::
size_t N = 0>
462 return std::get<N>(
m_inputs ).objKey();
466 template <std::
size_t N = 0>
469 return std::get<N>( m_outputs ).objKey();
478 template <
typename Traits_>
482 "BaseClass must inherit from Algorithm" );
495 template <
typename... In,
typename Traits_>
499 "BaseClass must inherit from Algorithm" );
503 std::index_sequence<I...> )
528 template <std::
size_t N = 0>
531 return std::get<N>(
m_inputs ).objKey();
539 template <
typename... Out,
typename Traits_>
543 "BaseClass must inherit from Algorithm" );
547 std::index_sequence<J...> )
549 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... )
571 template <std::
size_t N = 0>
574 return std::get<N>( m_outputs ).objKey();
583 template <
typename Fun,
typename Container,
typename... Args>
586 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
589 template <
typename Fun,
typename Container>
592 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
typename Tr::BaseClass BaseClass_t
constexpr static const auto FAILURE
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
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
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))
const std::string & inputLocation() const
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)
const Container & operator[](size_type i) const
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
std::conditional_t< is_optional, ptr_t, val_t > value_type
constexpr unsigned int inputLocationSize() const
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
typename Tr::template OutputHandle< T > OutputHandle_t
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.
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.
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.
std::conditional_t< is_optional, ptr_t, ref_t > ret_t
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
void operator()(Container &c, boost::optional< Value > &&v) const
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)
const Container & at(size_type i) const
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
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