-
Notifications
You must be signed in to change notification settings - Fork 264
refactor(detray): Detray-level closed-set detector instantiation #5641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
523274e
aff2ec9
a31aa8e
0815728
cafdae2
48a4d11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // This file is part of the ACTS project. | ||
| // | ||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #pragma once | ||
|
|
||
| /// X-macro over the closed set of shipped detray metadata types for which the | ||
| /// heavy IO operations (write / read / consistency check / payload assembly) | ||
| /// are explicitly instantiated. | ||
| /// | ||
| /// Invoke with a single-argument macro; it is expanded once per metadata name. | ||
| /// This is the single source of truth for the closed set and is used both to | ||
| /// generate the `extern template` declarations (see @c detector_io_array.hpp) | ||
| /// and the matching explicit instantiations (one translation unit per metadata, | ||
| /// see detectors/CMakeLists.txt). The algebra plugin is supplied by the | ||
| /// including header, so the same list serves every algebra variant. | ||
| /// | ||
| /// To add a metadata type: add its header and one line here, then add the same | ||
| /// name to the CMake instantiation list. | ||
| #define DETRAY_IO_METADATA_FOR_EACH(MACRO) \ | ||
| MACRO(default_metadata) \ | ||
| MACRO(odd_metadata) \ | ||
| MACRO(toy_metadata) \ | ||
| MACRO(telescope_metadata) \ | ||
| MACRO(wire_chamber_metadata) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // This file is part of the ACTS project. | ||
| // | ||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #pragma once | ||
|
|
||
| // Extern-template facade for the array-algebra detray detectors. | ||
| // | ||
| // Including this header opts every shipped `detector<meta<array<float>>>` into | ||
| // the pre-built IO operations: the heavy `write_detector`, `read_detector`, | ||
| // `check_consistency` and `assemble_detector` template trees are compiled once | ||
| // in the `detray::detector_io_array` library and merely linked here, instead of | ||
| // being instantiated in every consumer. | ||
| // | ||
| // This is the array counterpart of the `detray::io` vs `detray::io_array` | ||
| // split: the frontend/core headers cannot carry these declarations themselves | ||
| // because they live below the `detectors` layer and cannot name the concrete | ||
| // metadata types. Consumers that need a non-shipped metadata or a different | ||
| // algebra simply include the frontend headers directly and instantiate on use. | ||
|
|
||
| // Project include(s) | ||
| #include "detray/core/detector.hpp" | ||
| #include "detray/definitions/algebra.hpp" | ||
| #include "detray/detectors/default_metadata.hpp" | ||
| #include "detray/detectors/detail/detector_io_instantiations.hpp" | ||
| #include "detray/detectors/odd_metadata.hpp" | ||
| #include "detray/detectors/telescope_metadata.hpp" | ||
| #include "detray/detectors/toy_metadata.hpp" | ||
| #include "detray/detectors/wire_chamber_metadata.hpp" | ||
| #include "detray/io/frontend/definitions.hpp" | ||
| #include "detray/io/frontend/detector_assembler.hpp" | ||
| #include "detray/io/frontend/detector_reader.hpp" | ||
| #include "detray/io/frontend/detector_writer.hpp" | ||
| #include "detray/io/frontend/payloads.hpp" | ||
| #include "detray/utils/consistency_checker.hpp" | ||
|
|
||
| // Vecmem include(s) | ||
| #include <vecmem/memory/memory_resource.hpp> | ||
|
|
||
| // System include(s) | ||
| #include <string_view> | ||
| #include <utility> | ||
|
|
||
| // clang-format off | ||
| #define DETRAY_DETECTOR_IO_EXTERN(META) \ | ||
| extern template void detray::io::write_detector< \ | ||
| detray::detector<detray::META<detray::array<float>>>>( \ | ||
| detray::detector<detray::META<detray::array<float>>>&, \ | ||
| const detray::detector<detray::META<detray::array<float>>>::name_map&, \ | ||
| detray::io::detector_writer_config&); \ | ||
| extern template std::pair< \ | ||
| detray::detector<detray::META<detray::array<float>>>, \ | ||
| detray::detector<detray::META<detray::array<float>>>::name_map> \ | ||
| detray::io::read_detector< \ | ||
| detray::detector<detray::META<detray::array<float>>>>( \ | ||
| vecmem::memory_resource&, const detray::io::detector_reader_config&); \ | ||
| extern template bool detray::detail::check_consistency< \ | ||
| detray::detector<detray::META<detray::array<float>>>>( \ | ||
| const detray::detector<detray::META<detray::array<float>>>&, bool, \ | ||
| const detray::detector<detray::META<detray::array<float>>>::name_map&); \ | ||
| extern template detray::detector<detray::META<detray::array<float>>> \ | ||
| detray::io::assemble_detector< \ | ||
| detray::detector<detray::META<detray::array<float>>>>( \ | ||
| vecmem::memory_resource&, const detray::io::detector_payload&, \ | ||
| const detray::io::detector_homogeneous_material_payload*, \ | ||
| detray::io::detector_grids_payload< \ | ||
| detray::io::surface_material_payload, detray::io::material_id>*, \ | ||
| const detray::io::detector_grids_payload<std::size_t, \ | ||
| detray::io::accel_id>*, \ | ||
| std::string_view, \ | ||
| detray::detector<detray::META<detray::array<float>>>::name_map&); | ||
| // clang-format on | ||
|
|
||
| DETRAY_IO_METADATA_FOR_EACH(DETRAY_DETECTOR_IO_EXTERN) | ||
|
|
||
| #undef DETRAY_DETECTOR_IO_EXTERN |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // This file is part of the ACTS project. | ||
| // | ||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| // Generated from DetrayIoInstantiate.cpp.in by CMake — do not edit. | ||
| // | ||
| // Explicit instantiation of the heavy detray IO operations for a single | ||
| // (metadata, array-algebra) detector. One such translation unit is compiled per | ||
| // shipped metadata into the detray::detector_io_array library; consumers see | ||
| // the matching `extern template` declarations via detector_io_array.hpp. | ||
|
|
||
| // Project include(s) | ||
| #include "detray/core/detector.hpp" | ||
| #include "detray/definitions/algebra.hpp" | ||
| #include "detray/detectors/@DETRAY_META@.hpp" | ||
| #include "detray/io/frontend/definitions.hpp" | ||
| #include "detray/io/frontend/detector_assembler.hpp" | ||
| #include "detray/io/frontend/detector_reader.hpp" | ||
| #include "detray/io/frontend/detector_writer.hpp" | ||
| #include "detray/io/frontend/payloads.hpp" | ||
| #include "detray/utils/consistency_checker.hpp" | ||
|
|
||
| // Vecmem include(s) | ||
| #include <vecmem/memory/memory_resource.hpp> | ||
|
|
||
| // System include(s) | ||
| #include <string_view> | ||
| #include <utility> | ||
|
|
||
| namespace detray { | ||
|
|
||
| using io_detector_t = detector<@DETRAY_META@<array<float>>>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs the detray scalar type, so that we can build double precision detectors in double precision tests |
||
|
|
||
| namespace io { | ||
|
|
||
| template void write_detector<io_detector_t>( | ||
| io_detector_t&, const io_detector_t::name_map&, detector_writer_config&); | ||
|
|
||
| template std::pair<io_detector_t, io_detector_t::name_map> | ||
| read_detector<io_detector_t>(vecmem::memory_resource&, | ||
| const detector_reader_config&); | ||
|
|
||
| template io_detector_t assemble_detector<io_detector_t>( | ||
| vecmem::memory_resource&, const detector_payload&, | ||
| const detector_homogeneous_material_payload*, | ||
| detector_grids_payload<surface_material_payload, material_id>*, | ||
| const detector_grids_payload<std::size_t, accel_id>*, std::string_view, | ||
| io_detector_t::name_map&); | ||
|
|
||
| } // namespace io | ||
|
|
||
| namespace detail { | ||
|
|
||
| template bool check_consistency<io_detector_t>(const io_detector_t&, bool, | ||
| const io_detector_t::name_map&); | ||
|
|
||
| } // namespace detail | ||
|
|
||
| } // namespace detray | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||||
| // This file is part of the ACTS project. | ||||||||
| // | ||||||||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||||||||
| // | ||||||||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||||||||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||||||||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||||||||
|
|
||||||||
| #pragma once | ||||||||
|
|
||||||||
| // Project include(s) | ||||||||
| #include "detray/builders/detector_builder.hpp" | ||||||||
| #include "detray/io/backend/geometry_reader.hpp" | ||||||||
| #include "detray/io/backend/homogeneous_material_reader.hpp" | ||||||||
| #include "detray/io/backend/material_map_reader.hpp" | ||||||||
| #include "detray/io/backend/surface_grid_reader.hpp" | ||||||||
| #include "detray/io/frontend/definitions.hpp" | ||||||||
| #include "detray/io/frontend/payloads.hpp" | ||||||||
|
|
||||||||
| // Vecmem include(s) | ||||||||
| #include <vecmem/memory/memory_resource.hpp> | ||||||||
|
|
||||||||
| // System include(s) | ||||||||
| #include <string> | ||||||||
| #include <string_view> | ||||||||
| #include <type_traits> | ||||||||
| #include <utility> | ||||||||
|
|
||||||||
| namespace detray::io { | ||||||||
|
|
||||||||
| /// @brief Assemble a detray detector from its individual IO payloads. | ||||||||
| /// | ||||||||
| /// This is the payload-driven counterpart of @c read_detector: instead of | ||||||||
| /// reading the components from files, it consumes payloads that a client (e.g. | ||||||||
| /// the ACTS geometry converter) has produced in memory and drives the detray | ||||||||
| /// @c detector_builder to construct the detector. It is a single, extern-able | ||||||||
| /// entry point for the otherwise heavy detector-building template tree. | ||||||||
| /// | ||||||||
| /// @tparam detector_t the type of detector to be built | ||||||||
| /// | ||||||||
| /// @param mr the memory resource used for the detector container allocations | ||||||||
| /// @param geometry the geometry payload (always required) | ||||||||
| /// @param homogeneous_material homogeneous material payload, or @c nullptr to | ||||||||
| /// skip homogeneous material | ||||||||
| /// @param material_grids material map payload (moved-from), or @c nullptr to | ||||||||
| /// skip material maps | ||||||||
| /// @param surface_grids surface grid payload, or @c nullptr to skip surface | ||||||||
| /// grids | ||||||||
| /// @param name detector name to set, or empty to leave the builder default | ||||||||
| /// @param names filled with the volume/surface name map during the build | ||||||||
| /// | ||||||||
| /// @returns the assembled detector | ||||||||
| template <class detector_t> | ||||||||
| detector_t assemble_detector( | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should merge with the |
||||||||
| vecmem::memory_resource& mr, const detector_payload& geometry, | ||||||||
| const detector_homogeneous_material_payload* homogeneous_material, | ||||||||
| detector_grids_payload<surface_material_payload, material_id>* | ||||||||
| material_grids, | ||||||||
| const detector_grids_payload<std::size_t, accel_id>* surface_grids, | ||||||||
| std::string_view name, typename detector_t::name_map& names) { | ||||||||
| detector_builder<typename detector_t::metadata> det_builder{}; | ||||||||
|
|
||||||||
| geometry_reader::from_payload<detector_t>(det_builder, geometry); | ||||||||
|
|
||||||||
| if (homogeneous_material != nullptr) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There is a concept for every detector component to turn off stuff that the detector type cannot hold |
||||||||
| homogeneous_material_reader::from_payload<detector_t>( | ||||||||
| det_builder, *homogeneous_material); | ||||||||
| } | ||||||||
|
|
||||||||
| if (material_grids != nullptr) { | ||||||||
| material_map_reader<std::integral_constant<std::size_t, 2>>::from_payload< | ||||||||
| detector_t>(det_builder, std::move(*material_grids)); | ||||||||
| } | ||||||||
|
|
||||||||
| if (surface_grids != nullptr) { | ||||||||
| surface_grid_reader<typename detector_t::surface_type, | ||||||||
| std::integral_constant<std::size_t, 0>, | ||||||||
| std::integral_constant<std::size_t, 2>>:: | ||||||||
| template from_payload<detector_t>(det_builder, *surface_grids); | ||||||||
| } | ||||||||
|
|
||||||||
| if (!name.empty()) { | ||||||||
| det_builder.set_name(std::string{name}); | ||||||||
| } | ||||||||
|
|
||||||||
| return det_builder.build(mr, names); | ||||||||
| } | ||||||||
|
|
||||||||
| } // namespace detray::io | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should into the IO lib?