File Helpers.hpp

Defines

ACTS_CHECK_BIT(value, mask)
namespace Acts

Note

This file is foreseen for the Geometry module to replace Extent

Functions

template<typename T, typename U>
T clampValue(U value)

Clamp a numeric value to another type, respecting range of the target type.

Template Parameters
  • T – the target type

  • U – the source type

Parameters

value – the value to clamp

Returns

the clamped value

template<typename T>
std::array<typename T::value_type, 2u> min_max(const T &tseries)

Return min/max from a (optionally) sorted series, obsolete with C++20 (ranges)

Template Parameters

T – a numeric series

Parameters

tseries – is the number series

Returns

[ min, max ] in an array of length 2

template<typename T>
std::tuple<typename T::value_type, ActsScalar> range_medium(const T &tseries)

Return range and medium of a sorted numeric series.

Template Parameters

T – a numeric series

Parameters

tseries – is the number series

Returns

[ range, medium ] in an tuple

template<template<size_t> class Callable, size_t N, size_t NMAX, typename ...Args>
auto template_switch(size_t v, Args&&... args)

Dispatch a call based on a runtime value on a function taking the value at compile time.

This function allows to write a templated functor, which accepts a size_t like parameter at compile time. It is then possible to make a call to the corresponding instance of the functor based on a runtime value. To achieve this, the function essentially created a if cascade between N and NMAX, attempting to find the right instance. Because the cascade is visible to the compiler entirely, it should be able to optimize.

Note

Callable is expected to have a static member function invoke that is callable with Args

Template Parameters
  • Callable – Type which takes a size_t as a compile time param

  • N – Value from which to start the dispatch chain, i.e. 0 in most cases

  • NMAX – Maximum value up to which to attempt a dispatch

Parameters
  • v – The runtime value to dispatch on

  • args – Additional arguments passed to Callable::invoke().

template<size_t N, size_t NMAX, typename Lambda, typename ...Args>
auto template_switch_lambda(size_t v, Lambda &&func, Args&&... args)

Alternative version of template_switch which accepts a generic lambda and communicates the dimension via an integral constant type.

Template Parameters
  • N – Value from which to start the dispatch chain, i.e. 0 in most cases

  • NMAX – Maximum value up to which to attempt a dispatch

Parameters
  • v – The runtime value to dispatch on

  • func – The lambda to invoke

  • args – Additional arguments passed to func

template<std::size_t kDIM, typename value_type>
std::array<value_type, kDIM> to_array(const std::vector<value_type> &vecvals)

This can be abandoned with C++20 to use the std::to_array method.

Note

only the first kDIM elements will obviously be filled, if the vector tends to be longer, it is truncated

Parameters

vecvals – the vector of bound values to be converted

Returns

an array with the filled values

template<typename T>
std::vector<const T*> unpack_shared_const_vector(const std::vector<std::shared_ptr<T>> &items)

Helper function to unpack a vector of shared_ptr into a vector of raw pointers.

Template Parameters

T – the stored type

Parameters

items – The vector of shared_ptr

Returns

The unpacked vector

template<typename T>
std::vector<T*> unpack_shared_vector(const std::vector<std::shared_ptr<T>> &items)

Helper function to unpack a vector of shared_ptr into a vector of raw pointers.

Template Parameters

T – the stored type

Parameters

items – The vector of shared_ptr

Returns

The unpacked vector

template<typename T>
std::vector<const T*> unpack_shared_vector(const std::vector<std::shared_ptr<const T>> &items)

Helper function to unpack a vector of shared_ptr into a vector of raw pointers (const version)

Template Parameters

T – the stored type

Parameters

items – The vector of shared_ptr

Returns

The unpacked vector