Loading [MathJax]/extensions/tex2jax.js
Go to the documentation of this file.
21 #include <range/v3/version.hpp>
22 #include <range/v3/view/const.hpp>
23 #include <range/v3/view/zip.hpp>
25 #include <type_traits>
28 #if RANGE_V3_VERSION < 900
30 using namespace ranges::view;
34 #if defined( __clang__ ) && ( __clang_major__ < 11 ) || defined( __APPLE__ ) && ( __clang_major__ < 12 )
35 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN \
36 _Pragma( "clang diagnostic push" ) _Pragma( "clang diagnostic ignored \"-Wunused-lambda-capture\"" )
37 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END _Pragma( "clang diagnostic pop" )
39 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_BEGIN
40 # define GF_SUPPRESS_SPURIOUS_CLANG_WARNING_END
45 #define GAUDI_FUNCTIONAL_CONSTRUCTOR_USES_TUPLE
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 [](
const std::string& i ) { return DataObjID{ i }; } );
124 template <
typename T>
125 using is_optional_ = decltype( std::declval<T>().has_value(), std::declval<T>().value() );
127 template <
typename T>
131 template <
typename Arg>
132 constexpr
bool is_optional_v = Gaudi::cpp17::is_detected_v<details2::is_optional_, Arg>;
134 template <
typename T>
139 template <
typename F,
typename Arg>
141 decltype( auto ) operator()( F&& f, Arg&& arg )
const {
142 return std::invoke( std::forward<F>( f ), std::forward<Arg>( arg ) );
144 template <
typename F,
typename Arg>
146 void operator()( F&& f, Arg&& arg )
const {
147 if ( arg ) std::invoke( std::forward<F>( f ), *std::forward<Arg>( arg ) );
157 template <
typename Value, auto N>
158 using RepeatValues_ = decltype( get_values_helper<Value>( std::make_index_sequence<N>() ) );
161 template <std::derived_from<DataObject> Out1, std::convertible_to<Out1> Out2>
163 return out_handle.
put( std::make_unique<Out1>( std::forward<Out2>(
out ) ) );
166 template <
typename Out1, std::convertible_to<Out1> Out2>
168 return out_handle.put( std::forward<Out2>(
out ) );
172 template <
typename OutHandle,
typename OptOut>
174 void
put( const OutHandle& out_handle, OptOut&&
out ) {
175 if (
out )
put( out_handle, *std::forward<OptOut>(
out ) );
185 template <
typename Container>
188 template <
typename Container,
typename Value>
190 return c.push_back( std::forward<Value>(
v ) );
193 template <
typename Container,
typename Value>
195 return c.insert( std::forward<Value>(
v ) );
199 template <
typename Container,
typename Value>
200 requires( std::is_pointer_v<typename Container::value_type> &&
202 auto operator()( Container&
c,
Value&&
v )
const {
211 template <
typename In>
213 const In& operator()(
const In& in )
const {
217 template <
typename In>
219 In operator()( In&& in )
const {
220 return std::forward<In>( in );
223 template <
typename In>
225 assert( in !=
nullptr );
233 template <
typename T>
234 constexpr
static bool is_gaudi_range_v =
false;
236 template <
typename T>
237 constexpr
static bool is_gaudi_range_v<Gaudi::Range_<T>> =
true;
239 template <
typename T>
240 constexpr
static bool is_gaudi_range_v<Gaudi::NamedRange_<T>> =
true;
242 template <
typename T>
243 constexpr
static bool is_gaudi_range_v<std::optional<Gaudi::NamedRange_<T>>> =
true;
245 template <
typename Container,
typename Value>
249 template <
typename Container,
typename Value>
254 template <
typename In>
256 template <
template <
typename>
class Handle, std::convertible_to<In> I>
260 template <
template <
typename>
class Handle,
typename I>
264 template <
template <
typename>
class Handle,
typename I>
268 template <
template <
typename>
class Handle,
typename I>
272 template <
template <
typename>
class Handle,
typename I>
274 auto operator()(
const Handle<I>&
h ) ->
const In {
275 return h.getIfExists();
279 template <
typename T>
283 template <
typename T>
289 template <
typename Container>
291 static constexpr
bool is_pointer = std::is_pointer_v<Container>;
292 static constexpr
bool is_range = details2::is_gaudi_range_v<Container>;
293 using val_t = std::add_const_t<std::remove_pointer_t<Container>>;
294 using ptr_t = std::add_pointer_t<val_t>;
295 using ref_t = std::add_lvalue_reference_t<val_t>;
300 using value_type = std::conditional_t<is_pointer, ptr_t, val_t>;
303 using it_t =
typename ContainerVector::const_iterator;
307 using ret_t = std::conditional_t<is_pointer, ptr_t, ref_t>;
320 if constexpr ( is_range ) {
335 explicit operator bool()
const {
return !is_null(); }
339 template <
typename T>
342 std::bool_constant < is_pointer || is_range > {} );
348 template <
typename X = Container>
350 ref_t front()
const {
351 return *m_containers.
front();
354 template <
typename X = Container>
356 ptr_t front()
const {
357 return m_containers.
front();
360 template <
typename X = Container>
363 return *m_containers.
back();
366 template <
typename X = Container>
369 return m_containers.
back();
372 template <
typename X = Container>
375 return *m_containers[i];
378 template <
typename X = Container>
381 return m_containers[i];
384 template <
typename X = Container>
387 return *m_containers[i];
390 template <
typename X = Container>
393 return m_containers[i];
401 template <
typename Tr>
403 template <
typename Tr,
typename T>
405 template <
typename Tr,
typename T>
408 template <
typename T>
409 constexpr
auto is_tool_v = std::is_base_of_v<IAlgTool, std::decay_t<T>>;
411 template <
typename T>
414 template <
typename T>
421 template <
typename Tr,
typename Base = Gaudi::Algorithm>
428 template <
typename Tr,
typename T>
430 template <
typename Tr,
typename T>
433 template <
typename Traits>
435 std::is_base_of_v<Gaudi::details::LegacyAlgorithmAdapter, details::BaseClass_t<Traits>>;
438 #define GAUDI_FUNCTIONAL_MAKE_VECTOR_OF_HANDLES_USES_DATAOBJID
440 template <
typename Handles>
443 handles.reserve( init.
size() );
445 [&](
const auto& loc ) ->
typename Handles::value_type {
446 return { loc, owner };
451 template <
typename Handle,
typename Algo>
458 template <
typename IFace,
typename Algo>
460 return handle.bind(
ctx );
463 template <
typename Handle>
464 auto getKey(
const Handle&
h ) -> decltype(
h.objKey() ) {
470 template <
typename... In>
475 "EventContext can only appear as first argument" );
477 template <
typename Algorithm,
typename Handles>
483 template <
typename Algorithm,
typename Handles>
485 return std::apply( [&](
const auto&... handle ) {
return algo(
get( handle, algo,
ctx )... ); }, handles );
490 template <
typename... In>
495 "EventContext can only appear as first argument" );
497 template <
typename Algorithm,
typename Handles>
499 return std::apply( [&](
const auto&... handle ) {
return algo(
ctx,
get( handle, algo,
ctx )... ); }, handles );
502 template <
typename Algorithm,
typename Handles>
508 template <
typename... In>
511 template <
typename OutputSpec,
typename InputSpec,
typename Traits_>
514 template <
typename Out,
typename In,
typename Tr>
517 auto sc = parent.setProperty( prop, newLoc );
518 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + newLoc, sc );
521 template <
typename Out,
typename In,
typename Tr>
526 return os <<
"'" << i <<
"'";
528 auto sc = parent.setProperty( prop, ss.
str() );
529 if ( sc.isFailure() )
throw GaudiException(
"Could not set Property", prop +
" -> " + ss.
str(), sc );
532 template <
typename... Out,
typename... In,
typename Traits_>
538 const OArgs& outputs, std::index_sequence<J...> )
540 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... )
541 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
557 std::index_sequence_for<Out...>{} ) {}
573 template <std::
size_t N = 0>
574 decltype(
auto ) inputLocation()
const {
575 return getKey( std::get<N>( m_inputs ) );
577 template <
typename T>
578 decltype(
auto ) inputLocation()
const {
583 template <std::
size_t N = 0>
584 decltype(
auto ) outputLocation()
const {
585 return getKey( std::get<N>( m_outputs ) );
587 template <
typename T>
588 decltype(
auto ) outputLocation()
const {
600 template <
typename Traits_>
619 template <
typename... In,
typename Traits_>
626 , m_inputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<I>( inputs ) )... ) {
645 template <std::
size_t N = 0>
646 decltype(
auto ) inputLocation()
const {
647 return getKey( std::get<N>( m_inputs ) );
649 template <
typename T>
650 decltype(
auto ) inputLocation()
const {
661 template <
typename Traits_>
668 template <
typename... Out,
typename Traits_>
675 , m_outputs(
std::tuple_cat(
std::forward_as_tuple( this ),
std::
get<J>( outputs ) )... ) {
693 template <std::
size_t N = 0>
694 decltype(
auto ) outputLocation()
const {
695 return getKey( std::get<N>( m_outputs ) );
706 template <
typename Fun,
typename Container,
typename... Args>
708 static_assert(
sizeof...( Args ) == 0,
"Args should not be used!" );
711 template <
typename Fun,
typename Container>
713 fun.postprocess(
c );
typename Tr::BaseClass BaseClass_t
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)
requires(std::is_pointer_v< X >) ptr_t at(size_type i) const
GAUDI_API const EventContext & currentContext()
bool isReEntrant() const override
DataHandleMixin(std::string name, ISvcLocator *locator, const KeyValue &output)
auto operator()(const Handle< I > &h) -> const In &
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)
auto operator()(const Handle< std::optional< Gaudi::NamedRange_< I >>> &h) -> const In
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))
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, const IArgs &inputs, std::index_sequence< I... >)
requires(!std::is_pointer_v< In >) const In &operator()(const In &in) const
T back_inserter(T... args)
ContainerVector m_containers
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.
requires(std::is_pointer_v< X >) ptr_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... >)
std::vector< DataObjID > to_DataObjID(const std::vector< std::string > &in)
DataObjectHandle.h GaudiKernel/DataObjectHandle.h.
requires(std::is_pointer_v< X >) ptr_t front() const
static auto apply(const Algorithm &algo, Handles &handles)
Handles make_vector_of_handles(IDataHandleHolder *owner, const std::vector< DataObjID > &init)
requires(std::is_pointer_v< X >) ptr_t back() const
std::remove_pointer_t< typename Container::value_type > c_remove_ptr_t
requires(!std::is_pointer_v< std::decay_t< In >>) In operator()(In &&in) const
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, RepeatValues_< KeyValue, N_in > const &inputs, RepeatValues_< KeyValue, N_out > const &outputs)
requires(std::is_convertible_v< I *, In >) auto operator()(const Handle< I > &h) -> const In
auto put(const DataObjectHandle< AnyDataWrapper< Out1 >> &out_handle, Out2 &&out)
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.
static auto apply(const Algorithm &algo, const EventContext &ctx, Handles &handles)
requires(std::is_pointer_v< typename Container::value_type > &&std::is_convertible_v< Value, c_remove_ptr_t< Container >>) auto operator()(Container &c
typename Tr::template InputHandle< T > InputHandle_t
std::conditional_t< is_tool_v< T >, ToolHandle_t< T >, DataObjectReadHandle< T > > DefaultInputHandle
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
requires(!std::is_pointer_v< X >) ref_t operator[](size_type i) const
static auto apply(const Algorithm &algo, Handles &handles)
decltype(std::declval< T >().has_value(), std::declval< T >().value()) is_optional_
requires(!std::is_pointer_v< X >) ref_t back() const
typename Tr::template OutputHandle< T > OutputHandle_t
auto operator()(const Handle< Gaudi::NamedRange_< I >> &h) -> const In
constexpr struct Gaudi::Functional::details::deref_t deref
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
void push_back(T &&container)
auto operator()(const Handle< Gaudi::Range_< I >> &h) -> const In
void updateHandleLocation(DataHandleMixin< Out, In, Tr > &parent, const std::string &prop, const std::string &newLoc)
friend bool operator==(const iterator &lhs, const iterator &rhs)
std::tuple< details::OutputHandle_t< Traits_, Out >... > m_outputs
bool isReEntrant() const override
typename is_detected< Op, Args... >::type detected_t
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)
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
Generator[dict, None, None] reference(request, Optional[Path] reference_path)
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
requires(is_optional_v< OptOut >) void put(const OutHandle &out_handle
requires(is_optional_v< Arg >) void operator()(F &&f
Gaudi::cpp17::detected_or_t< Base, detail2::BaseClass_t, Tr > BaseClass_t
void printSizes(OS &out, Arg &&arg, Args &&... args)
Print the parameters.
typename T::value_type value_type_of_t
constexpr static const auto FAILURE
DataHandleMixin(std::string name, ISvcLocator *pSvcLocator, std::tuple<>={}, std::tuple<>={})
requires(!std::is_pointer_v< X >) ref_t front() const
std::conditional_t< is_pointer, ptr_t, ref_t > ret_t
constexpr struct Gaudi::Functional::details::insert_t insert
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)
requires(!std::is_pointer_v< X >) ref_t at(size_type i) const
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())
std::conditional_t< is_optional_v< T >, Gaudi::cpp17::detected_t< details2::value_type_of_t, T >, T > remove_optional_t
requires(!is_optional_v< Arg >) decltype(auto) operator()(F &&f
bool is_null(size_type i) const