Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:24

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // detray core
0010 #include "detray/utils/grid/populators.hpp"
0011 
0012 #include "detray/definitions/indexing.hpp"
0013 #include "detray/utils/grid/grid_bins.hpp"
0014 
0015 // Detray test include(s)
0016 #include "detray/test/framework/types.hpp"
0017 
0018 // GTest
0019 #include <gtest/gtest.h>
0020 
0021 // System include(s)
0022 #include <algorithm>
0023 #include <climits>
0024 
0025 using namespace detray;
0026 
0027 namespace {
0028 
0029 constexpr dindex inf{std::numeric_limits<dindex>::max()};
0030 
0031 // Create some bin data for non-owning grid
0032 template <typename bin_t>
0033 struct bin_content_sequence {
0034   using entry_t = typename bin_t::entry_type;
0035   entry_t entry{0};
0036 
0037   auto operator()() {
0038     entry += entry_t{1};
0039     return bin_t{}.init(entry);
0040   }
0041 };
0042 
0043 /// Test single entry bin content element by element
0044 template <typename bin_content_t, typename content_t>
0045 void test_content(const bin_content_t& bin_content, const content_t& expected) {
0046   unsigned int i{0u};
0047   for (const auto& elem : bin_content) {
0048     ASSERT_EQ(elem, expected[i++]);
0049   }
0050 }
0051 
0052 }  // anonymous namespace
0053 
0054 /// Replace populator
0055 GTEST_TEST(detray_grid, replace_populator) {
0056   detray::replace replacer{};
0057 
0058   // Create some bin data
0059   dvector<bins::single<dindex>> bin_data{};
0060   bin_data.resize(50);
0061   std::ranges::generate_n(bin_data.begin(), 50,
0062                           bin_content_sequence<bins::single<dindex>>());
0063 
0064   // Check test setup
0065   EXPECT_EQ(bin_data[0].value(), 1u);
0066   EXPECT_EQ(bin_data[1].value(), 2u);
0067   EXPECT_EQ(bin_data[2].value(), 3u);
0068   EXPECT_EQ(bin_data[3].value(), 4u);
0069   EXPECT_EQ(bin_data[19].value(), 20u);
0070   EXPECT_EQ(bin_data[20].value(), 21u);
0071   EXPECT_EQ(bin_data[21].value(), 22u);
0072   EXPECT_EQ(bin_data[41].value(), 42u);
0073   EXPECT_EQ(bin_data[42].value(), 43u);
0074   EXPECT_EQ(bin_data[43].value(), 44u);
0075   EXPECT_EQ(bin_data[48].value(), 49u);
0076   EXPECT_EQ(bin_data[49].value(), 50u);
0077 
0078   // Replace some bin entries
0079   replacer(bin_data[0], 500u);
0080   replacer(bin_data[2], 5u);
0081   replacer(bin_data[20], 50u);
0082   replacer(bin_data[42], 55u);
0083   replacer(bin_data[49], 6u);
0084 
0085   EXPECT_EQ(bin_data[0].value(), 500u);
0086   EXPECT_EQ(bin_data[1].value(), 2u);
0087   EXPECT_EQ(bin_data[2].value(), 5u);
0088   EXPECT_EQ(bin_data[3].value(), 4u);
0089   EXPECT_EQ(bin_data[19].value(), 20u);
0090   EXPECT_EQ(bin_data[20].value(), 50u);
0091   EXPECT_EQ(bin_data[21].value(), 22u);
0092   EXPECT_EQ(bin_data[41].value(), 42u);
0093   EXPECT_EQ(bin_data[42].value(), 55u);
0094   EXPECT_EQ(bin_data[43].value(), 44u);
0095   EXPECT_EQ(bin_data[48].value(), 49u);
0096   EXPECT_EQ(bin_data[49].value(), 6u);
0097 }
0098 
0099 /// Complete populator
0100 GTEST_TEST(detray_grid, complete_populator) {
0101   detray::complete<> completer{};
0102 
0103   // Create some bin data
0104   dvector<bins::static_array<dindex, 4>> bin_data{};
0105   bin_data.resize(50);
0106   std::ranges::generate_n(
0107       bin_data.begin(), 50,
0108       bin_content_sequence<bins::static_array<dindex, 4>>());
0109 
0110   // Check test setup
0111   std::array<dindex, 4> stored = {1u, inf, inf, inf};
0112   test_content(bin_data[0], stored);
0113   stored = {2u, inf, inf, inf};
0114   test_content(bin_data[1], stored);
0115   stored = {3u, inf, inf, inf};
0116   test_content(bin_data[2], stored);
0117   stored = {4u, inf, inf, inf};
0118   test_content(bin_data[3], stored);
0119   stored = {20u, inf, inf, inf};
0120   test_content(bin_data[19], stored);
0121   stored = {21u, inf, inf, inf};
0122   test_content(bin_data[20], stored);
0123   stored = {22u, inf, inf, inf};
0124   test_content(bin_data[21], stored);
0125   stored = {42u, inf, inf, inf};
0126   test_content(bin_data[41], stored);
0127   stored = {43u, inf, inf, inf};
0128   test_content(bin_data[42], stored);
0129   stored = {44u, inf, inf, inf};
0130   test_content(bin_data[43], stored);
0131   stored = {49u, inf, inf, inf};
0132   test_content(bin_data[48], stored);
0133   stored = {50u, inf, inf, inf};
0134   test_content(bin_data[49], stored);
0135 
0136   // Fill the bins with some bin entry
0137   completer(bin_data[0], 500u);
0138   completer(bin_data[2], 5u);
0139   completer(bin_data[20], 50u);
0140   completer(bin_data[42], 55u);
0141   completer(bin_data[49], 6u);
0142 
0143   stored = {1u, 500u, 500u, 500u};
0144   test_content(bin_data[0], stored);
0145   stored = {2u, inf, inf, inf};
0146   test_content(bin_data[1], stored);
0147   stored = {3u, 5u, 5u, 5u};
0148   test_content(bin_data[2], stored);
0149   stored = {4u, inf, inf, inf};
0150   test_content(bin_data[3], stored);
0151   stored = {20u, inf, inf, inf};
0152   test_content(bin_data[19], stored);
0153   stored = {21u, 50u, 50u, 50u};
0154   test_content(bin_data[20], stored);
0155   stored = {22u, inf, inf, inf};
0156   test_content(bin_data[21], stored);
0157   stored = {42u, inf, inf, inf};
0158   test_content(bin_data[41], stored);
0159   stored = {43u, 55u, 55u, 55u};
0160   test_content(bin_data[42], stored);
0161   stored = {44u, inf, inf, inf};
0162   test_content(bin_data[43], stored);
0163   stored = {49u, inf, inf, inf};
0164   test_content(bin_data[48], stored);
0165   stored = {50u, 6u, 6u, 6u};
0166   test_content(bin_data[49], stored);
0167 }
0168 
0169 /// Regular attach populator
0170 GTEST_TEST(detray_grid, regular_attach_populator) {
0171   detray::attach<> attacher{};
0172 
0173   // Create some bin data
0174   dvector<bins::static_array<dindex, 4>> bin_data{};
0175   bin_data.resize(50);
0176   std::ranges::generate_n(
0177       bin_data.begin(), 50,
0178       bin_content_sequence<bins::static_array<dindex, 4>>());
0179 
0180   // Check test setup
0181   std::array<dindex, 4> stored = {1u, inf, inf, inf};
0182   test_content(bin_data[0], stored);
0183   stored = {2u, inf, inf, inf};
0184   test_content(bin_data[1], stored);
0185   stored = {3u, inf, inf, inf};
0186   test_content(bin_data[2], stored);
0187   stored = {4u, inf, inf, inf};
0188   test_content(bin_data[3], stored);
0189   stored = {20u, inf, inf, inf};
0190   test_content(bin_data[19], stored);
0191   stored = {21u, inf, inf, inf};
0192   test_content(bin_data[20], stored);
0193   stored = {22u, inf, inf, inf};
0194   test_content(bin_data[21], stored);
0195   stored = {42u, inf, inf, inf};
0196   test_content(bin_data[41], stored);
0197   stored = {43u, inf, inf, inf};
0198   test_content(bin_data[42], stored);
0199   stored = {44u, inf, inf, inf};
0200   test_content(bin_data[43], stored);
0201   stored = {49u, inf, inf, inf};
0202   test_content(bin_data[48], stored);
0203   stored = {50u, inf, inf, inf};
0204   test_content(bin_data[49], stored);
0205 
0206   // Fill the bins with some bin entry
0207   attacher(bin_data[0], 500u);
0208   attacher(bin_data[2], 5u);
0209   attacher(bin_data[2], 79u);
0210   attacher(bin_data[20], 50u);
0211   attacher(bin_data[42], 55u);
0212   attacher(bin_data[49], 6u);
0213   attacher(bin_data[49], 7u);
0214   attacher(bin_data[49], 8u);
0215 
0216   stored = {1u, 500u, inf, inf};
0217   test_content(bin_data[0], stored);
0218   stored = {2u, inf, inf, inf};
0219   test_content(bin_data[1], stored);
0220   stored = {3u, 5u, 79u, inf};
0221   test_content(bin_data[2], stored);
0222   stored = {4u, inf, inf, inf};
0223   test_content(bin_data[3], stored);
0224   stored = {20u, inf, inf, inf};
0225   test_content(bin_data[19], stored);
0226   stored = {21u, 50u, inf, inf};
0227   test_content(bin_data[20], stored);
0228   stored = {22u, inf, inf, inf};
0229   test_content(bin_data[21], stored);
0230   stored = {42u, inf, inf, inf};
0231   test_content(bin_data[41], stored);
0232   stored = {43u, 55u, inf, inf};
0233   test_content(bin_data[42], stored);
0234   stored = {44u, inf, inf, inf};
0235   test_content(bin_data[43], stored);
0236   stored = {49u, inf, inf, inf};
0237   test_content(bin_data[48], stored);
0238   stored = {50u, 6u, 7u, 8u};
0239   test_content(bin_data[49], stored);
0240 }