Skip to content

Commit 0ca5549

Browse files
committed
docs with examples and compiles snippets
1 parent a5e7f6d commit 0ca5549

11 files changed

Lines changed: 295 additions & 10 deletions

File tree

Core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(ACTS_GEOMETRY_MODULE_CAPI 1)
1414
set(_acts_geometry_module_abi_tag
1515
"acts-${Acts_VERSION}|sys-${CMAKE_SYSTEM_NAME}|arch-${CMAKE_SYSTEM_PROCESSOR}|cxx-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}|capi-${ACTS_GEOMETRY_MODULE_CAPI}"
1616
)
17-
set(ACTS_GEOMETRY_MODULE_ABI_TAG_VALUE
17+
set(ACTS_GEOMETRY_MODULE_ABI_TAG
1818
"${_acts_geometry_module_abi_tag}"
1919
CACHE INTERNAL
2020
"ACTS geometry module ABI tag"

Core/include/Acts/Geometry/GeometryModuleLoader.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class TrackingGeometry;
2626
/// the tracking geometry. The returned deleter keeps the module loaded until
2727
/// the geometry is destroyed. Throws if the module requires user data (e.g.
2828
/// a DD4hep module) — use the appropriate typed loader instead.
29+
/// @param modulePath Path to the geometry module shared library.
30+
/// @param logger Logger instance used by the module loader.
31+
/// @return Shared pointer to the loaded tracking geometry.
2932
std::shared_ptr<TrackingGeometry> loadGeometryModule(
3033
const std::filesystem::path& modulePath,
3134
const Logger& logger = getDummyLogger());

Plugins/DD4hep/include/ActsPlugins/DD4hep/GeometryModuleLoader.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class TrackingGeometry;
3030
/// validate ABI compatibility, build and return the tracking geometry.
3131
/// The returned deleter keeps the module loaded until the geometry is
3232
/// destroyed.
33+
/// @param modulePath Path to the geometry module shared library.
34+
/// @param detector DD4hep detector instance passed to the module.
35+
/// @param logger Logger instance used by the module loader.
36+
/// @return Shared pointer to the loaded tracking geometry.
3337
std::shared_ptr<TrackingGeometry> loadDD4hepGeometryModule(
3438
const std::filesystem::path& modulePath, const dd4hep::Detector& detector,
3539
const Logger& logger = getDummyLogger());

cmake/ActsConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
set(Acts_COMPONENTS @_components@)
1717
set(Acts_COMMIT_HASH "@_acts_commit_hash@")
1818
set(Acts_COMMIT_HASH_SHORT "@_acts_commit_hash_short@")
19-
set(Acts_GEOMETRY_MODULE_ABI_TAG "@ACTS_GEOMETRY_MODULE_ABI_TAG_VALUE@")
19+
set(ACTS_GEOMETRY_MODULE_ABI_TAG "@ACTS_GEOMETRY_MODULE_ABI_TAG@")
2020

2121
# print version and components information
2222
if(NOT Acts_FIND_QUIETLY)

cmake/ActsDD4hepGeometryModuleHelpers.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ function(acts_add_dd4hep_geometry_module target)
77
)
88
endif()
99
if(
10-
NOT DEFINED Acts_GEOMETRY_MODULE_ABI_TAG
11-
OR Acts_GEOMETRY_MODULE_ABI_TAG STREQUAL ""
10+
NOT DEFINED ACTS_GEOMETRY_MODULE_ABI_TAG
11+
OR ACTS_GEOMETRY_MODULE_ABI_TAG STREQUAL ""
1212
)
1313
message(
1414
FATAL_ERROR
15-
"Acts_GEOMETRY_MODULE_ABI_TAG is not set; cannot configure DD4hep geometry module target '${target}'."
15+
"ACTS_GEOMETRY_MODULE_ABI_TAG is not set; cannot configure DD4hep geometry module target '${target}'."
1616
)
1717
endif()
1818

@@ -21,6 +21,6 @@ function(acts_add_dd4hep_geometry_module target)
2121
target_link_libraries(${target} PRIVATE Acts::PluginDD4hep)
2222
target_compile_definitions(
2323
${target}
24-
PRIVATE ACTS_GEOMETRY_MODULE_ABI_TAG="${Acts_GEOMETRY_MODULE_ABI_TAG}"
24+
PRIVATE ACTS_GEOMETRY_MODULE_ABI_TAG="${ACTS_GEOMETRY_MODULE_ABI_TAG}"
2525
)
2626
endfunction()

cmake/ActsGeometryModuleHelpers.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ function(acts_add_geometry_module target)
77
)
88
endif()
99
if(
10-
NOT DEFINED Acts_GEOMETRY_MODULE_ABI_TAG
11-
OR Acts_GEOMETRY_MODULE_ABI_TAG STREQUAL ""
10+
NOT DEFINED ACTS_GEOMETRY_MODULE_ABI_TAG
11+
OR ACTS_GEOMETRY_MODULE_ABI_TAG STREQUAL ""
1212
)
1313
message(
1414
FATAL_ERROR
15-
"Acts_GEOMETRY_MODULE_ABI_TAG is not set; cannot configure geometry module target '${target}'."
15+
"ACTS_GEOMETRY_MODULE_ABI_TAG is not set; cannot configure geometry module target '${target}'."
1616
)
1717
endif()
1818

@@ -21,6 +21,6 @@ function(acts_add_geometry_module target)
2121
target_link_libraries(${target} PRIVATE Acts::Core)
2222
target_compile_definitions(
2323
${target}
24-
PRIVATE ACTS_GEOMETRY_MODULE_ABI_TAG="${Acts_GEOMETRY_MODULE_ABI_TAG}"
24+
PRIVATE ACTS_GEOMETRY_MODULE_ABI_TAG="${ACTS_GEOMETRY_MODULE_ABI_TAG}"
2525
)
2626
endfunction()

docs/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,33 @@ set_target_properties(docs-examples PROPERTIES EXCLUDE_FROM_ALL TRUE)
3333
target_sources(
3434
docs-examples
3535
PRIVATE examples/logging.cpp examples/units.cpp examples/errors.cpp
36+
examples/geometry_module.cpp
3637
)
3738
target_link_libraries(docs-examples PRIVATE Acts::Core)
39+
40+
if(ACTS_BUILD_PLUGIN_DD4HEP)
41+
target_link_libraries(docs-examples PRIVATE Acts::PluginDD4hep)
42+
target_compile_definitions(docs-examples PRIVATE ACTS_BUILD_PLUGIN_DD4HEP)
43+
endif()
44+
45+
# Compile the module writing templates as real geometry modules so the
46+
# snippet examples are verified at build time.
47+
#! [Plain Module CMake]
48+
include(ActsGeometryModuleHelpers)
49+
acts_add_geometry_module(
50+
docs-geometry-module-template
51+
examples/geometry_module_template.cpp
52+
)
53+
#! [Plain Module CMake]
54+
add_dependencies(docs-examples docs-geometry-module-template)
55+
56+
if(ACTS_BUILD_PLUGIN_DD4HEP)
57+
#! [DD4hep Module CMake]
58+
include(ActsDD4hepGeometryModuleHelpers)
59+
acts_add_dd4hep_geometry_module(
60+
docs-geometry-module-template-dd4hep
61+
examples/geometry_module_template_dd4hep.cpp
62+
)
63+
#! [DD4hep Module CMake]
64+
add_dependencies(docs-examples docs-geometry-module-template-dd4hep)
65+
endif()

docs/examples/geometry_module.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
#include "Acts/Geometry/GeometryModuleLoader.hpp"
10+
#include "Acts/Utilities/Logger.hpp"
11+
12+
#include <filesystem>
13+
14+
#ifdef ACTS_BUILD_PLUGIN_DD4HEP
15+
#include "ActsPlugins/DD4hep/GeometryModuleLoader.hpp"
16+
17+
#include <DD4hep/Detector.h>
18+
#endif
19+
20+
void exampleLoadPlainModule(const Acts::Logger& logger,
21+
const std::filesystem::path& modulePath) {
22+
//! [Load Plain Module]
23+
auto geometry = Acts::loadGeometryModule(modulePath, logger);
24+
// 'geometry' is a std::shared_ptr<Acts::TrackingGeometry>.
25+
// The shared library stays loaded until 'geometry' is destroyed.
26+
//! [Load Plain Module]
27+
(void)geometry;
28+
}
29+
30+
#ifdef ACTS_BUILD_PLUGIN_DD4HEP
31+
void exampleLoadDD4hepModule(const dd4hep::Detector& detector,
32+
const Acts::Logger& logger,
33+
const std::filesystem::path& modulePath) {
34+
//! [Load DD4hep Module]
35+
auto geometry =
36+
Acts::loadDD4hepGeometryModule(modulePath, detector, logger);
37+
// 'geometry' is a std::shared_ptr<Acts::TrackingGeometry>.
38+
// The shared library stays loaded until 'geometry' is destroyed.
39+
//! [Load DD4hep Module]
40+
(void)geometry;
41+
}
42+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
//! [Write Plain Module]
10+
#include "Acts/Geometry/GeometryModuleHelper.hpp"
11+
#include "Acts/Geometry/TrackingGeometry.hpp"
12+
13+
#include <stdexcept>
14+
15+
namespace {
16+
std::unique_ptr<Acts::TrackingGeometry> buildMyGeometry(
17+
const Acts::Logger& logger) {
18+
ACTS_INFO("Building my geometry");
19+
// ... construct and return a TrackingGeometry ...
20+
throw std::logic_error("not implemented");
21+
}
22+
} // namespace
23+
24+
ACTS_DEFINE_GEOMETRY_MODULE(buildMyGeometry)
25+
//! [Write Plain Module]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
//! [Write DD4hep Module]
10+
#include "ActsPlugins/DD4hep/GeometryModuleHelper.hpp"
11+
#include "Acts/Geometry/TrackingGeometry.hpp"
12+
13+
#include <DD4hep/Detector.h>
14+
#include <stdexcept>
15+
16+
namespace {
17+
std::unique_ptr<Acts::TrackingGeometry> buildMyGeometry(
18+
const dd4hep::Detector& detector, const Acts::Logger& logger) {
19+
(void)detector;
20+
ACTS_INFO("Building DD4hep geometry");
21+
// ... use detector to build and return a TrackingGeometry ...
22+
throw std::logic_error("not implemented");
23+
}
24+
} // namespace
25+
26+
ACTS_DEFINE_DD4HEP_GEOMETRY_MODULE(buildMyGeometry)
27+
//! [Write DD4hep Module]

0 commit comments

Comments
 (0)