Skip to content

Commit

Permalink
fix: Further fixes to detray plugin
Browse files Browse the repository at this point in the history
This commit makes several minor changes to the detray plugin:

1. It adds the detray plugin to the downstream project.
2. It disables the build of the detray CUDA code, which we don't need.
  • Loading branch information
stephenswat committed Aug 29, 2024
1 parent 4569230 commit 541712c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
47 changes: 2 additions & 45 deletions Plugins/Detray/include/Acts/Plugins/Detray/DetrayConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,53 +38,10 @@ class DetrayConverter {
/// @param options the conversion options
///
/// @returns a detector of requested return type
template <typename detector_t = DetrayDetector>
detector_t convert(
DetrayDetector convert(
const GeometryContext& gctx, const Detector& detector,
vecmem::memory_resource& mr,
[[maybe_unused]] const DetrayConversionUtils::Options& options = {}) {
// The building cache object
DetrayConversionUtils::GeometryIdCache geoIdCache;

typename detector_t::name_map names = {{0u, detector.name()}};

// build detector
detray::detector_builder<typename detector_t::metadata> detectorBuilder{};
// (1) geometry
detray::io::detector_payload detectorPayload =
DetrayGeometryConverter::convertDetector(geoIdCache, gctx, detector,
logger());
detray::io::geometry_reader::convert<detector_t>(detectorBuilder, names,
detectorPayload);
// (2) material
if constexpr (detray::detail::has_material_grids_v<detector_t>) {
if (options.convertMaterial) {
detray::io::detector_grids_payload<detray::io::material_slab_payload,
detray::io::material_id>
materialPayload =
DetrayMaterialConverter::convertSurfaceMaterialGrids(
geoIdCache, detector, logger());
detray::io::material_map_reader<>::convert<detector_t>(
detectorBuilder, names, materialPayload);
}
}

detector_t detrayDetector(detectorBuilder.build(mr));

// Checks and print
detray::detail::check_consistency(detrayDetector);

// If configured, write the detector to json
if (options.writeToJson) {
// Create a writer configuration and write it out
detray::io::detector_writer_config writerConfig{};
writerConfig.m_write_material = options.convertMaterial;
writerConfig.m_write_grids = options.convertSurfaceGrids;
writeToJson(detrayDetector, names, writerConfig);
}

return detrayDetector;
}
[[maybe_unused]] const DetrayConversionUtils::Options& options = {});

/// Write the detector to json output
///
Expand Down
47 changes: 47 additions & 0 deletions Plugins/Detray/src/DetrayConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,50 @@ void Acts::DetrayConverter::writeToJson(
writer_cfg.format(detray::io::format::json);
detray::io::write_detector(dDetector, names, writer_cfg);
}

Acts::DetrayDetector Acts::DetrayConverter::convert(
const GeometryContext& gctx, const Detector& detector,
vecmem::memory_resource& mr,
[[maybe_unused]] const DetrayConversionUtils::Options& options) {
// The building cache object
DetrayConversionUtils::GeometryIdCache geoIdCache;

DetrayDetector::name_map names = {{0u, detector.name()}};

// build detector
detray::detector_builder<DetrayDetector::metadata> detectorBuilder{};
// (1) geometry
detray::io::detector_payload detectorPayload =
DetrayGeometryConverter::convertDetector(geoIdCache, gctx, detector,
logger());
detray::io::geometry_reader::convert<DetrayDetector>(detectorBuilder, names,
detectorPayload);
// (2) material
if constexpr (detray::detail::has_material_grids_v<DetrayDetector>) {
if (options.convertMaterial) {
detray::io::detector_grids_payload<detray::io::material_slab_payload,
detray::io::material_id>
materialPayload =
DetrayMaterialConverter::convertSurfaceMaterialGrids(
geoIdCache, detector, logger());
detray::io::material_map_reader<>::convert<DetrayDetector>(
detectorBuilder, names, std::move(materialPayload));
}
}

DetrayDetector detrayDetector(detectorBuilder.build(mr));

// Checks and print
detray::detail::check_consistency(detrayDetector);

// If configured, write the detector to json
if (options.writeToJson) {
// Create a writer configuration and write it out
detray::io::detector_writer_config writerConfig{};
writerConfig.m_write_material = options.convertMaterial;
writerConfig.m_write_grids = options.convertSurfaceGrids;
writeToJson(detrayDetector, names, writerConfig);
}

return detrayDetector;
}
10 changes: 9 additions & 1 deletion Tests/DownstreamProject/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ find_package(
Acts
CONFIG
REQUIRED
COMPONENTS Core Fatras PluginJson PluginLegacy PluginTGeo PluginCovfie
COMPONENTS
Core
Fatras
PluginJson
PluginLegacy
PluginTGeo
PluginCovfie
PluginDetray
)

# place artifacts in GNU-like paths, e.g. binaries in `<build>/bin`
Expand All @@ -31,6 +38,7 @@ target_link_libraries(
ActsPluginLegacy
ActsPluginTGeo
ActsPluginCovfie
ActsPluginDetray
)

option(DD4HEP "Build with DD4hep" ON)
Expand Down
5 changes: 5 additions & 0 deletions thirdparty/detray/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ set(DETRAY_CUSTOM_SCALARTYPE
"Scalar type to use in the Detray code"
)

set(DETRAY_BUILD_CUDA
OFF
CACHE BOOL
"Turn off the build of the Detray CUDA code"
)
set(DETRAY_BUILD_TESTING
OFF
CACHE BOOL
Expand Down

0 comments on commit 541712c

Please sign in to comment.