Back to home page

EIC code displayed by LXR

 
 

    


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

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 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/navigation/volume_graph.hpp"
0013 #include "detray/utils/consistency_checker.hpp"
0014 #include "detray/utils/logging.hpp"
0015 
0016 // Detray test include(s)
0017 #include "detray/test/framework/fixture_base.hpp"
0018 #include "detray/test/utils/hash_tree.hpp"
0019 
0020 // System include(s)
0021 #include <iostream>
0022 #include <string>
0023 #include <string_view>
0024 
0025 namespace detray::test {
0026 
0027 struct consistency_check_config
0028     : public detray::test::fixture_base<>::configuration {
0029   std::string m_name{"detector_consistency"};
0030   bool m_write_graph{false};
0031 
0032   /// Getters
0033   /// @{
0034   const std::string &name() const { return m_name; }
0035   bool write_graph() const { return m_write_graph; }
0036   /// @}
0037 
0038   /// Setters
0039   /// @{
0040   consistency_check_config &name(const std::string_view v) {
0041     m_name = v;
0042     return *this;
0043   }
0044   consistency_check_config &write_graph(const bool do_write) {
0045     m_write_graph = do_write;
0046     return *this;
0047   }
0048   /// @}
0049 };
0050 
0051 /// @brief Test class that runs the consistency check on a given detector.
0052 ///
0053 /// @note The lifetime of the detector needs to be guaranteed.
0054 template <typename detector_t>
0055 class consistency_check : public detray::test::fixture_base<> {
0056  public:
0057   using fixture_type = detray::test::fixture_base<>;
0058   using config = consistency_check_config;
0059 
0060   template <typename config_t>
0061   explicit consistency_check(
0062       const detector_t &det, const typename detector_t::name_map &names,
0063       const config_t &cfg = {},
0064       const typename detector_t::geometry_context &gctx = {})
0065       : m_cfg{cfg}, m_gctx{gctx}, m_det{det}, m_names{names} {}
0066 
0067   /// Run the consistency check
0068   void TestBody() override {
0069     DETRAY_INFO_HOST("Running consistency check on: " << m_det.name(m_names)
0070                                                       << std::endl);
0071 
0072     // Build the graph
0073     volume_graph graph(m_det);
0074 
0075     ASSERT_TRUE(detail::check_consistency(m_det, true, m_names))
0076         << graph.to_string();
0077 
0078     if (m_cfg.write_graph()) {
0079       DETRAY_INFO_HOST(graph.to_string());
0080     }
0081 
0082     // Not currently supported
0083     if (false) {
0084       constexpr std::size_t root_hash{3244u};  // < toy detector only
0085 
0086       const auto &adj_mat = graph.adjacency_matrix();
0087 
0088       auto geo_checker = hash_tree(adj_mat);
0089 
0090       EXPECT_EQ(geo_checker.root(), root_hash) << graph.to_string();
0091     }
0092   }
0093 
0094  private:
0095   /// The configuration of this test
0096   const config m_cfg;
0097   /// The geometry context to check
0098   typename detector_t::geometry_context m_gctx{};
0099   /// The detector to be checked
0100   const detector_t &m_det;
0101   /// Volume names
0102   const typename detector_t::name_map &m_names;
0103 };
0104 
0105 }  // namespace detray::test