Skip to content

Commit 82f5d73

Browse files
committed
Generate the headers
1 parent 0b86e6e commit 82f5d73

15 files changed

Lines changed: 155 additions & 74 deletions

File tree

.github/workflows/builds.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
steps:
3636
# Use a standard checkout of the code.
3737
- uses: actions/checkout@v4
38-
# Run the CMake configuration.
38+
# Run the CMake configuration. Test that the metadata generation runs
3939
- name: Configure
4040
run: cmake --preset full-fp64
4141
-DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }}
@@ -45,11 +45,14 @@ jobs:
4545
-DDETRAY_FASTOR_PLUGIN=OFF
4646
-DDETRAY_VC_AOS_PLUGIN=OFF
4747
-DDETRAY_VC_SOA_PLUGIN=OFF
48+
-DDETRAY_GENERATE_METADATA="default_metadata;itk_metadata;odd_metadata;toy_metadata;wire_chamber_metadata"
4849
-S ${{ github.workspace }} -B build
4950
-G "${{ matrix.PLATFORM.GENERATOR }}"
5051
# Perform the build.
5152
- name: Build
52-
run: cmake --build build --config ${{ matrix.BUILD_TYPE }} -- -j 2
53+
run: |
54+
source ./build/python/setup.sh
55+
cmake --build build --config ${{ matrix.BUILD_TYPE }} -- -j 2
5356
5457
# Containerised build jobs.
5558
host-container:

CMakeLists.txt

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ set_property(
6969
PROPERTY STRINGS "NONE" "WARNING" "INFO" "VERBOSE" "DEBUG"
7070
)
7171
option(DETRAY_BUILD_CLI_TOOLS "Build the command line tools of Detray" OFF)
72-
option(
73-
DETRAY_BUILD_PYTHON_BINDINGS
74-
"Build python bindings for all enabled components"
75-
OFF
72+
# Which detector metadata headers to generate during the build
73+
set(DETRAY_GENERATE_METADATA
74+
""
75+
CACHE STRING
76+
"Semicolon-separated list of metdata generator scripts to run in this build"
7677
)
7778

7879
# Device compilation
@@ -90,6 +91,7 @@ option(DETRAY_BUILD_SYCL "Build the SYCL sources included in detray" OFF)
9091

9192
# Check if HIP is available
9293
option(DETRAY_BUILD_HIP "Build the HIP sources included in detray" OFF)
94+
9395
cmake_dependent_option(
9496
DETRAY_BUILD_HOST
9597
"Build the host sources included in detray"
@@ -138,22 +140,6 @@ elseif(DETRAY_SET_LOGGING STREQUAL "DEBUG")
138140
set(DETRAY_LOG_LVL 3 CACHE INTERNAL "Print expert information" FORCE)
139141
endif()
140142

141-
#
142-
# Resolve build options and option dependencies
143-
#
144-
145-
# Set the internal log level from user input
146-
set(DETRAY_LOG_LVL -1 CACHE INTERNAL "Disable logging")
147-
if(DETRAY_SET_LOGGING STREQUAL "WARN")
148-
set(DETRAY_LOG_LVL 0 CACHE INTERNAL "Print warnings and errors" FORCE)
149-
elseif(DETRAY_SET_LOGGING STREQUAL "INFO")
150-
set(DETRAY_LOG_LVL 1 CACHE INTERNAL "Print general information" FORCE)
151-
elseif(DETRAY_SET_LOGGING STREQUAL "VERBOSE")
152-
set(DETRAY_LOG_LVL 2 CACHE INTERNAL "Print detailed information" FORCE)
153-
elseif(DETRAY_SET_LOGGING STREQUAL "DEBUG")
154-
set(DETRAY_LOG_LVL 3 CACHE INTERNAL "Print expert information" FORCE)
155-
endif()
156-
157143
# Need test utils in CLI tools for the example detector generation
158144
if(DETRAY_BUILD_CLI_TOOLS)
159145
set(DETRAY_BUILD_TEST_UTILS ON)
@@ -167,9 +153,12 @@ if(${DETRAY_BUILD_CUDA} AND ${CMAKE_CUDA_STANDARD} LESS 20)
167153
)
168154
endif()
169155

170-
#
171-
# Configure dependencies
172-
#
156+
if(${DETRAY_BUILD_SYCL} AND ${CMAKE_SYCL_STANDARD} LESS 20)
157+
message(
158+
SEND_ERROR
159+
"CMAKE_SYCL_STANDARD=${CMAKE_SYCL_STANDARD}, but detray requires C++>=20"
160+
)
161+
endif()
173162

174163
if(${DETRAY_BUILD_HIP} AND ${CMAKE_HIP_STANDARD} LESS 20)
175164
message(
@@ -502,6 +491,7 @@ if(
502491
add_subdirectory(tests)
503492
endif()
504493

494+
# Set up the tutorial(s).
505495
if(DETRAY_BUILD_TUTORIALS)
506496
add_subdirectory(tutorials)
507497
endif()

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ The following cmake options are available and can also be specified explicitly f
6262
| DETRAY_SET_LOGGING | Set log level (NONE, WARN, INFO, VERBOSE, DEBUG) | INFO |
6363
| DETRAY_BUILD_CUDA | Build the CUDA sources included in detray | ON (if available) |
6464
| DETRAY_BUILD_SYCL | Build the SYCL sources included in detray | OFF |
65-
| DETRAY_BUILD_CLI_TOOLS | Build the detray command line tools | OFF |
66-
| DETRAY_BUILD_BENCHMARKS | Build the detray benchmarks | OFF |
67-
| DETRAY_BUILD_TUTORIALS | Build the examples of detray | OFF |
68-
| DETRAY_BUILD_ALL_TESTS | Build the detray unit and integration tests | OFF |
65+
| DETRAY_BUILD_TEST_UTILS | Build the detray test utilities library (contains e.g. test detectors) | OFF |
6966
| DETRAY_BUILD_UNITTESTS | Build the detray unit tests | OFF |
7067
| DETRAY_BUILD_INTEGRATIONTESTS | Build the detray integration tests | OFF |
71-
| DETRAY_BUILD_TEST_UTILS | Build the detray test utilities library (test detectors etc.) | OFF |
68+
| DETRAY_BUILD_ALL_TESTS | Build the detray unit and integration tests | OFF |
69+
| DETRAY_BUILD_BENCHMARKS | Build the detray benchmarks | OFF |
70+
| DETRAY_BUILD_CLI_TOOLS | Build the detray command line tools | OFF |
71+
| DETRAY_BUILD_TUTORIALS | Build the examples of detray | OFF |
7272
| DETRAY_CUSTOM_SCALARTYPE | Floating point precision | float |
73+
| DETRAY_GENERATE_METADATA | List of metadata generator scripts (separated by semicolon) | empty |
7374
| DETRAY_EIGEN_PLUGIN | Build Eigen math plugin | OFF |
7475
| DETRAY_FASTOR_PLUGIN | Build Fastor math plugin | OFF |
7576
| DETRAY_SMATRIX_PLUGIN | Build ROOT/SMatrix math plugin | OFF |

detectors/CMakeLists.txt

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Detray library, part of the ACTS project (R&D line)
22
#
3-
# (c) 2024 CERN for the benefit of the ACTS project
3+
# (c) 2024-2026 CERN for the benefit of the ACTS project
44
#
55
# Mozilla Public License Version 2.0
66

@@ -24,3 +24,47 @@ target_link_libraries(
2424
)
2525

2626
unset(_detray_detector_headers)
27+
28+
# Create the metadata headers
29+
if(NOT "${DETRAY_GENERATE_METADATA}" STREQUAL "")
30+
message(STATUS "Configuring detray detector types...")
31+
32+
find_package(Python COMPONENTS Interpreter REQUIRED)
33+
34+
set(OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/include/detray/detectors")
35+
file(MAKE_DIRECTORY ${OUTPUT_DIR})
36+
37+
# Generate the custom metadata headers
38+
foreach(GENERATOR ${DETRAY_GENERATE_METADATA})
39+
set(GENERATED_HEADER "${OUTPUT_DIR}/${GENERATOR}.hpp")
40+
set(GENERATOR_SCRIPT
41+
"${PROJECT_SOURCE_DIR}/detectors/python/${GENERATOR}.py"
42+
)
43+
44+
add_custom_command(
45+
OUTPUT "${GENERATED_HEADER}"
46+
COMMAND Python::Interpreter "${GENERATOR_SCRIPT}" -o "${OUTPUT_DIR}"
47+
DEPENDS "${GENERATOR_SCRIPT}" "${CMAKE_BINARY_DIR}/python/setup.sh"
48+
)
49+
50+
add_custom_target(${GENERATOR}_generation DEPENDS ${GENERATED_HEADER})
51+
52+
# Set up how clients should find its headers.
53+
target_include_directories(
54+
detray_detectors
55+
INTERFACE
56+
$<BUILD_INTERFACE:${OUTPUT_DIR}>
57+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
58+
)
59+
60+
install(
61+
DIRECTORY "${OUTPUT_DIR}"
62+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
63+
OPTIONAL
64+
)
65+
66+
add_dependencies(detray_detectors ${GENERATOR}_generation)
67+
68+
message(STATUS "Creating metadata: ${GENERATOR}")
69+
endforeach()
70+
endif()

detectors/include/detray/detectors/odd_metadata.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ struct odd_metadata {
190190
grid_collection<volume_cylinder3D_grid_t<container_t>>>;
191191

192192
enum geo_objects : std::uint_least8_t {
193-
e_portal = 0u,
194193
e_passive = 0u,
194+
e_portal = 0u,
195195
e_sensitive = 1u,
196196
e_volume = 2u,
197197
e_size = 3u,
@@ -204,8 +204,8 @@ struct odd_metadata {
204204
case geo_objects::e_sensitive:
205205
os << "e_sensitive";
206206
break;
207-
case geo_objects::e_passive:
208-
os << "e_portal/e_passive";
207+
case geo_objects::e_portal:
208+
os << "e_passive/e_portal";
209209
break;
210210
case geo_objects::e_volume:
211211
os << "e_volume";

detectors/python/default_metadata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ def __main__():
3131
# Commandline options
3232
parser = argparse.ArgumentParser(prog=sys.argv[0])
3333
detray.detectors.add_logging_options(parser)
34-
detray.detectors.parse_logging_options(parser.parse_args())
34+
detray.detectors.add_io_options(parser)
35+
36+
args = parser.parse_args()
37+
detray.detectors.parse_logging_options(args)
38+
detray.detectors.parse_io_options(args)
3539

3640
logger = logging.getLogger(__name__)
3741

@@ -82,7 +86,10 @@ def __main__():
8286
md.set_default_accel_struct(Accelerator.CYLINDER_GRID3D, "volume")
8387

8488
# Dump the metadata to header file
85-
metadata_generator(md)
89+
if args.output:
90+
metadata_generator(md, args.output)
91+
else:
92+
metadata_generator(md)
8693

8794

8895
if __name__ == "__main__":

detectors/python/itk_metadata.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from detray.detectors import metadata, metadata_generator
1010
from detray.detectors import Shape
1111
from detray.detectors import (
12-
add_logging_options,
13-
parse_logging_options,
1412
add_silicon_tracker_defaults,
1513
)
1614

@@ -43,14 +41,21 @@ def __main__():
4341
# Commandline options
4442
parser = argparse.ArgumentParser(prog=sys.argv[0])
4543
detray.detectors.add_logging_options(parser)
46-
detray.detectors.parse_logging_options(parser.parse_args())
44+
detray.detectors.add_io_options(parser)
45+
46+
args = parser.parse_args()
47+
detray.detectors.parse_logging_options(args)
48+
detray.detectors.parse_io_options(args)
4749

4850
md = metadata("itk")
4951

5052
add_itk_types(md)
5153

5254
# Dump the metadata to header file
53-
metadata_generator(md)
55+
if args.output:
56+
metadata_generator(md, args.output)
57+
else:
58+
metadata_generator(md)
5459

5560

5661
if __name__ == "__main__":

detectors/python/odd_metadata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ def __main__():
4141
# Commandline options
4242
parser = argparse.ArgumentParser(prog=sys.argv[0])
4343
detray.detectors.add_logging_options(parser)
44-
detray.detectors.parse_logging_options(parser.parse_args())
44+
detray.detectors.add_io_options(parser)
45+
46+
args = parser.parse_args()
47+
detray.detectors.parse_logging_options(args)
48+
detray.detectors.parse_io_options(args)
4549

4650
md = metadata("odd")
4751

4852
add_odd_types(md)
4953

5054
# Dump the metadata to header file
51-
metadata_generator(md)
55+
if args.output:
56+
metadata_generator(md, args.output)
57+
else:
58+
metadata_generator(md)
5259

5360

5461
if __name__ == "__main__":

detectors/python/toy_metadata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,21 @@ def __main__():
5252
# Commandline options
5353
parser = argparse.ArgumentParser(prog=sys.argv[0])
5454
detray.detectors.add_logging_options(parser)
55-
detray.detectors.parse_logging_options(parser.parse_args())
55+
detray.detectors.add_io_options(parser)
56+
57+
args = parser.parse_args()
58+
detray.detectors.parse_logging_options(args)
59+
detray.detectors.parse_io_options(args)
5660

5761
md = metadata("toy")
5862

5963
add_toy_types(md)
6064

6165
# Dump the metadata to header file
62-
metadata_generator(md)
66+
if args.output:
67+
metadata_generator(md, args.output)
68+
else:
69+
metadata_generator(md)
6370

6471

6572
if __name__ == "__main__":

detectors/python/wire_chamber_metadata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ def __main__():
3535
# Commandline options
3636
parser = argparse.ArgumentParser(prog=sys.argv[0])
3737
detray.detectors.add_logging_options(parser)
38-
detray.detectors.parse_logging_options(parser.parse_args())
38+
detray.detectors.add_io_options(parser)
39+
40+
args = parser.parse_args()
41+
detray.detectors.parse_logging_options(args)
42+
detray.detectors.parse_io_options(args)
3943

4044
md = metadata("wire_chamber")
4145

4246
add_wire_chamber_types(md)
4347

4448
# Dump the metadata to header file
45-
metadata_generator(md)
49+
if args.output:
50+
metadata_generator(md, args.output)
51+
else:
52+
metadata_generator(md)
4653

4754

4855
if __name__ == "__main__":

0 commit comments

Comments
 (0)