File indexing completed on 2025-01-18 09:11:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <type_traits>
0010
0011 template <std::size_t DIM>
0012 template <typename first_value_t, typename... vals>
0013 void Acts::GridBinFinder<DIM>::storeValue(first_value_t&& fv,
0014 vals&&... others) {
0015 constexpr std::size_t N = sizeof...(vals);
0016 static_assert(N < DIM);
0017
0018 using decayed_value_t = typename std::decay_t<first_value_t>;
0019 if constexpr (std::is_same_v<int, decayed_value_t>) {
0020
0021 assert(fv >= 0);
0022 m_values[DIM - N - 1ul] = fv;
0023 } else if constexpr (std::is_same_v<std::pair<int, int>, decayed_value_t>) {
0024 m_values[DIM - N - 1ul] = fv;
0025 } else {
0026
0027 if (!fv.empty()) {
0028 m_values[DIM - N - 1ul] = std::forward<first_value_t>(fv);
0029 } else {
0030 m_values[DIM - N - 1ul] = 1;
0031 }
0032 }
0033 if constexpr (N != 0ul) {
0034 storeValue(std::forward<vals>(others)...);
0035 }
0036 }
0037
0038 template <std::size_t DIM>
0039 std::array<std::pair<int, int>, DIM> Acts::GridBinFinder<DIM>::getSizePerAxis(
0040 const std::array<std::size_t, DIM>& locPosition) const {
0041 std::array<std::pair<int, int>, DIM> output;
0042 for (std::size_t i(0ul); i < DIM; ++i) {
0043 output[i] = std::visit(
0044 [&locPosition, i](const auto& val) -> std::pair<int, int> {
0045 using value_t = typename std::decay_t<decltype(val)>;
0046 if constexpr (std::is_same_v<int, value_t>) {
0047 assert(val >= 0);
0048 return {-val, val};
0049 } else if constexpr (std::is_same_v<std::pair<int, int>, value_t>) {
0050 return {-val.first, val.second};
0051 } else {
0052 assert(locPosition.size() > i);
0053 assert(locPosition[i] > 0ul);
0054 assert(val.size() >= locPosition[i]);
0055 return val[locPosition[i] - 1ul];
0056 }
0057 },
0058 m_values[i]);
0059 }
0060 return output;
0061 }
0062
0063 template <std::size_t DIM>
0064 template <typename stored_t, class... Axes>
0065 auto Acts::GridBinFinder<DIM>::findBins(
0066 const std::array<std::size_t, DIM>& locPosition,
0067 const Acts::Grid<stored_t, Axes...>& grid) const
0068 -> boost::container::small_vector<std::size_t, dimCubed> {
0069 static_assert(sizeof...(Axes) == DIM);
0070 assert(isGridCompatible(grid));
0071 std::array<std::pair<int, int>, DIM> sizePerAxis =
0072 getSizePerAxis(locPosition);
0073 return grid.neighborHoodIndices(locPosition, sizePerAxis).collect();
0074 }
0075
0076 template <std::size_t DIM>
0077 template <typename stored_t, class... Axes>
0078 bool Acts::GridBinFinder<DIM>::isGridCompatible(
0079 const Acts::Grid<stored_t, Axes...>& grid) const {
0080 const std::array<std::size_t, DIM> nLocBins = grid.numLocalBins();
0081 for (std::size_t i(0ul); i < DIM; ++i) {
0082 std::size_t nBins = nLocBins[i];
0083 bool isCompabile = std::visit(
0084 [nBins](const auto& val) -> bool {
0085 using value_t = typename std::decay_t<decltype(val)>;
0086 if constexpr (std::is_same_v<int, value_t> ||
0087 std::is_same_v<std::pair<int, int>, value_t>) {
0088 return true;
0089 } else {
0090 return val.size() == nBins;
0091 }
0092 },
0093 m_values[i]);
0094 if (!isCompabile) {
0095 return false;
0096 }
0097 }
0098 return true;
0099 }