File indexing completed on 2025-08-05 08:09:29
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012
0013 #include <algorithm>
0014 #include <iostream>
0015 #include <limits>
0016 #include <memory>
0017 #include <optional>
0018 #include <string>
0019 #include <vector>
0020
0021 #define ACTS_CHECK_BIT(value, mask) ((value & mask) == mask)
0022
0023 namespace Acts {
0024
0025
0026
0027
0028
0029
0030 template <typename T>
0031 std::vector<T*> unpack_shared_vector(
0032 const std::vector<std::shared_ptr<T>>& items) {
0033 std::vector<T*> rawPtrs;
0034 rawPtrs.reserve(items.size());
0035 for (const std::shared_ptr<T>& item : items) {
0036 rawPtrs.push_back(item.get());
0037 }
0038 return rawPtrs;
0039 }
0040
0041
0042
0043
0044
0045
0046 template <typename T>
0047 std::vector<const T*> unpack_shared_vector(
0048 const std::vector<std::shared_ptr<const T>>& items) {
0049 std::vector<const T*> rawPtrs;
0050 rawPtrs.reserve(items.size());
0051 for (const std::shared_ptr<const T>& item : items) {
0052 rawPtrs.push_back(item.get());
0053 }
0054 return rawPtrs;
0055 }
0056
0057
0058
0059
0060
0061
0062 template <typename T>
0063 std::vector<const T*> unpack_shared_const_vector(
0064 const std::vector<std::shared_ptr<T>>& items) {
0065 std::vector<const T*> rawPtrs;
0066 rawPtrs.reserve(items.size());
0067 for (const std::shared_ptr<T>& item : items) {
0068 rawPtrs.push_back(item.get());
0069 }
0070 return rawPtrs;
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080 template <std::size_t kDIM, typename value_type>
0081 std::array<value_type, kDIM> to_array(const std::vector<value_type>& vecvals) {
0082 std::array<value_type, kDIM> rarray = {};
0083 for (const auto [iv, v] : enumerate(vecvals)) {
0084 if (iv < kDIM) {
0085 rarray[iv] = v;
0086 }
0087 }
0088 return rarray;
0089 }
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 template <template <std::size_t> class Callable, std::size_t N,
0109 std::size_t NMAX, typename... Args>
0110 auto template_switch(std::size_t v, Args&&... args) {
0111 if (v == N) {
0112 return Callable<N>::invoke(std::forward<Args>(args)...);
0113 }
0114 if (v == 0) {
0115 std::cerr << "template_switch<Fn, " << N << ", " << NMAX << ">(v=" << v
0116 << ") is not valid (v == 0 and N != 0)" << std::endl;
0117 std::abort();
0118 }
0119 if constexpr (N < NMAX) {
0120 return template_switch<Callable, N + 1, NMAX>(v,
0121 std::forward<Args>(args)...);
0122 }
0123 std::cerr << "template_switch<Fn, " << N << ", " << NMAX << ">(v=" << v
0124 << ") is not valid (v > NMAX)" << std::endl;
0125 std::abort();
0126 }
0127
0128
0129
0130
0131
0132
0133
0134
0135 template <std::size_t N, std::size_t NMAX, typename Lambda, typename... Args>
0136 auto template_switch_lambda(std::size_t v, Lambda&& func, Args&&... args) {
0137 if (v == N) {
0138 return func(std::integral_constant<std::size_t, N>{},
0139 std::forward<Args>(args)...);
0140 }
0141 if (v == 0) {
0142 std::cerr << "template_switch<Fn, " << N << ", " << NMAX << ">(v=" << v
0143 << ") is not valid (v == 0 and N != 0)" << std::endl;
0144 std::abort();
0145 }
0146 if constexpr (N < NMAX) {
0147 return template_switch_lambda<N + 1, NMAX>(v, func,
0148 std::forward<Args>(args)...);
0149 }
0150 std::cerr << "template_switch<Fn, " << N << ", " << NMAX << ">(v=" << v
0151 << ") is not valid (v > NMAX)" << std::endl;
0152 std::abort();
0153 }
0154
0155
0156
0157
0158
0159
0160 template <typename T, typename U>
0161 T clampValue(U value) {
0162 return std::clamp(value, static_cast<U>(std::numeric_limits<T>::lowest()),
0163 static_cast<U>(std::numeric_limits<T>::max()));
0164 }
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174 template <typename T>
0175 std::array<typename T::value_type, 2u> min_max(const T& tseries) {
0176 return {*std::min_element(tseries.begin(), tseries.end()),
0177 *std::max_element(tseries.begin(), tseries.end())};
0178 }
0179
0180
0181
0182
0183
0184
0185
0186
0187 template <typename T>
0188 std::tuple<typename T::value_type, ActsScalar> range_medium(const T& tseries) {
0189 auto [min, max] = min_max(tseries);
0190 typename T::value_type range = (max - min);
0191 ActsScalar medium = static_cast<ActsScalar>((max + min) * 0.5);
0192 return std::tie(range, medium);
0193 }
0194
0195 }