obdeect-stream 0.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- obdeect_stream-0.8.0/CMakeLists.txt +205 -0
- obdeect_stream-0.8.0/PKG-INFO +52 -0
- obdeect_stream-0.8.0/README.md +25 -0
- obdeect_stream-0.8.0/cmake/obdeect_stream-config.cmake.in +3 -0
- obdeect_stream-0.8.0/cmake/version.hpp.in +11 -0
- obdeect_stream-0.8.0/cpp/bench/bench_stream.cpp +119 -0
- obdeect_stream-0.8.0/cpp/bench/gen_corsika.cpp +138 -0
- obdeect_stream-0.8.0/cpp/bindings/core.cpp +409 -0
- obdeect_stream-0.8.0/cpp/capi/obdeect_stream_c.cpp +674 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/constants.hpp +18 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/corsika.hpp +628 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/eventio.hpp +824 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/format.hpp +58 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/grisu.hpp +575 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/obdeect_stream.h +218 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/photons.hpp +99 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/random.hpp +66 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/simtel.hpp +1162 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/stages.hpp +40 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/stdin_buffer.hpp +49 -0
- obdeect_stream-0.8.0/cpp/include/obdeect/stream/stream.hpp +572 -0
- obdeect_stream-0.8.0/cpp/tests/check.hpp +43 -0
- obdeect_stream-0.8.0/cpp/tests/consumer/CMakeLists.txt +13 -0
- obdeect_stream-0.8.0/cpp/tests/consumer/main.cpp +31 -0
- obdeect_stream-0.8.0/cpp/tests/consumer/main_c.c +6 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/bad_magic.ps +0 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/expected.json +130 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/make_conformance.py +137 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/too_many_rows.ps +0 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/truncated_chunk.ps +0 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/unknown_major.ps +0 -0
- obdeect_stream-0.8.0/cpp/tests/data/conformance/valid.ps +0 -0
- obdeect_stream-0.8.0/cpp/tests/test_capi.c +304 -0
- obdeect_stream-0.8.0/cpp/tests/test_capi_cpp.cpp +177 -0
- obdeect_stream-0.8.0/cpp/tests/test_corsika.cpp +517 -0
- obdeect_stream-0.8.0/cpp/tests/test_eventio.cpp +464 -0
- obdeect_stream-0.8.0/cpp/tests/test_format.cpp +128 -0
- obdeect_stream-0.8.0/cpp/tests/test_grisu.cpp +338 -0
- obdeect_stream-0.8.0/cpp/tests/test_simtel.cpp +1169 -0
- obdeect_stream-0.8.0/cpp/tests/test_stages.cpp +18 -0
- obdeect_stream-0.8.0/cpp/tests/test_stream.cpp +308 -0
- obdeect_stream-0.8.0/cpp/tests/test_version.cpp +11 -0
- obdeect_stream-0.8.0/cpp/tools/corsika2ps.cpp +84 -0
- obdeect_stream-0.8.0/cpp/tools/ps2grisu.cpp +141 -0
- obdeect_stream-0.8.0/cpp/tools/ps2simtel.cpp +143 -0
- obdeect_stream-0.8.0/cpp/tools/ps_cat.cpp +174 -0
- obdeect_stream-0.8.0/cpp/tools/ps_tee.cpp +125 -0
- obdeect_stream-0.8.0/cpp/tools/tool_version.hpp +17 -0
- obdeect_stream-0.8.0/pyproject.toml +43 -0
- obdeect_stream-0.8.0/python/obdeect/stream/__init__.py +28 -0
- obdeect_stream-0.8.0/python/obdeect/stream/__main__.py +60 -0
- obdeect_stream-0.8.0/python/obdeect/stream/_package.py +27 -0
- obdeect_stream-0.8.0/python/obdeect/stream/cli.py +145 -0
- obdeect_stream-0.8.0/python/obdeect/stream/convert.py +103 -0
- obdeect_stream-0.8.0/python/obdeect/stream/stage.py +140 -0
- obdeect_stream-0.8.0/python/obdeect/stream/stream.py +78 -0
- obdeect_stream-0.8.0/python/tests/test_cli.py +50 -0
- obdeect_stream-0.8.0/python/tests/test_cmake_package.py +51 -0
- obdeect_stream-0.8.0/python/tests/test_constants.py +23 -0
- obdeect_stream-0.8.0/python/tests/test_convert.py +482 -0
- obdeect_stream-0.8.0/python/tests/test_grisu.py +140 -0
- obdeect_stream-0.8.0/python/tests/test_import.py +9 -0
- obdeect_stream-0.8.0/python/tests/test_stage.py +198 -0
- obdeect_stream-0.8.0/python/tests/test_stream.py +255 -0
- obdeect_stream-0.8.0/python/tests/test_validation_script.py +37 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.20)
|
|
2
|
+
|
|
3
|
+
# Single source of truth for the version: the package version. Wheels and sdists get it
|
|
4
|
+
# from setuptools-scm (scikit-build-core passes SKBUILD_PROJECT_VERSION). Other builds use
|
|
5
|
+
# the newest v* git tag, or 0.0.0 without one. project() gets the numeric part (X.Y.Z).
|
|
6
|
+
if(DEFINED SKBUILD_PROJECT_VERSION)
|
|
7
|
+
set(OBDEECT_STREAM_PACKAGE_VERSION "${SKBUILD_PROJECT_VERSION}")
|
|
8
|
+
else()
|
|
9
|
+
execute_process(COMMAND git describe --tags --match "v[0-9]*" --abbrev=0
|
|
10
|
+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
11
|
+
OUTPUT_VARIABLE OBDEECT_STREAM_GIT_TAG OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
12
|
+
ERROR_QUIET RESULT_VARIABLE OBDEECT_STREAM_GIT_RESULT)
|
|
13
|
+
if(OBDEECT_STREAM_GIT_RESULT EQUAL 0 AND OBDEECT_STREAM_GIT_TAG MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)")
|
|
14
|
+
set(OBDEECT_STREAM_PACKAGE_VERSION "${CMAKE_MATCH_1}")
|
|
15
|
+
else()
|
|
16
|
+
set(OBDEECT_STREAM_PACKAGE_VERSION "0.0.0")
|
|
17
|
+
endif()
|
|
18
|
+
endif()
|
|
19
|
+
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" OBDEECT_STREAM_NUMERIC_VERSION "${OBDEECT_STREAM_PACKAGE_VERSION}")
|
|
20
|
+
if(NOT OBDEECT_STREAM_NUMERIC_VERSION)
|
|
21
|
+
message(FATAL_ERROR "obdeect stream: cannot parse the package version '${OBDEECT_STREAM_PACKAGE_VERSION}'")
|
|
22
|
+
endif()
|
|
23
|
+
project(obdeect_stream VERSION ${OBDEECT_STREAM_NUMERIC_VERSION} LANGUAGES CXX)
|
|
24
|
+
|
|
25
|
+
include(GNUInstallDirs)
|
|
26
|
+
include(CMakePackageConfigHelpers)
|
|
27
|
+
|
|
28
|
+
option(OBDEECT_STREAM_BUILD_TESTING "Build the C++ tests" ON)
|
|
29
|
+
option(OBDEECT_STREAM_BUILD_TOOLS "Build the command-line tools of obdeect stream (cat, tee, from-corsika, to-simtel, to-grisu)" ON)
|
|
30
|
+
option(OBDEECT_STREAM_BUILD_CAPI "Build the C API shared library libobdeect_stream_c" ON)
|
|
31
|
+
option(OBDEECT_STREAM_INSTALL "Install the headers and the CMake package (OFF when another component embeds the stream sources)" ON)
|
|
32
|
+
option(OBDEECT_STREAM_BUILD_BENCH "Build the photon-stream benchmark" OFF)
|
|
33
|
+
if(DEFINED SKBUILD_PLATLIB_DIR)
|
|
34
|
+
set(OBDEECT_STREAM_BUILD_PYTHON_API_DEFAULT ON)
|
|
35
|
+
else()
|
|
36
|
+
set(OBDEECT_STREAM_BUILD_PYTHON_API_DEFAULT OFF)
|
|
37
|
+
endif()
|
|
38
|
+
option(OBDEECT_STREAM_BUILD_PYTHON_API "Build the Python extension" ${OBDEECT_STREAM_BUILD_PYTHON_API_DEFAULT})
|
|
39
|
+
|
|
40
|
+
# Install layout. In a wheel the headers and the CMake package live inside the Python
|
|
41
|
+
# package (python -m obdeect.stream --include-dir / --cmake-dir); otherwise they follow GNUInstallDirs.
|
|
42
|
+
if(DEFINED SKBUILD_PLATLIB_DIR)
|
|
43
|
+
set(OBDEECT_STREAM_INCLUDE_INSTALL_DIR obdeect/stream/include)
|
|
44
|
+
set(OBDEECT_STREAM_LIB_INSTALL_DIR obdeect/stream/lib)
|
|
45
|
+
set(OBDEECT_STREAM_CMAKE_INSTALL_DIR obdeect/stream/cmake)
|
|
46
|
+
else()
|
|
47
|
+
set(OBDEECT_STREAM_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
|
|
48
|
+
set(OBDEECT_STREAM_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
|
|
49
|
+
set(OBDEECT_STREAM_CMAKE_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/obdeect_stream)
|
|
50
|
+
endif()
|
|
51
|
+
|
|
52
|
+
# Generated headers (version.hpp) live in the build tree.
|
|
53
|
+
set(OBDEECT_STREAM_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
|
|
54
|
+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.hpp.in
|
|
55
|
+
${OBDEECT_STREAM_GENERATED_DIR}/obdeect/stream/version.hpp @ONLY)
|
|
56
|
+
|
|
57
|
+
# Header-only, standard-library-only core. Exported as obdeect::stream; the in-tree
|
|
58
|
+
# name obdeect_stream_core stays valid.
|
|
59
|
+
add_library(obdeect_stream_core INTERFACE)
|
|
60
|
+
add_library(obdeect::stream ALIAS obdeect_stream_core)
|
|
61
|
+
set_target_properties(obdeect_stream_core PROPERTIES EXPORT_NAME stream)
|
|
62
|
+
target_include_directories(obdeect_stream_core INTERFACE
|
|
63
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp/include>
|
|
64
|
+
$<BUILD_INTERFACE:${OBDEECT_STREAM_GENERATED_DIR}>
|
|
65
|
+
$<INSTALL_INTERFACE:${OBDEECT_STREAM_INCLUDE_INSTALL_DIR}>)
|
|
66
|
+
target_compile_features(obdeect_stream_core INTERFACE cxx_std_20)
|
|
67
|
+
# Identical floating-point results for any thread count and chunk size on one
|
|
68
|
+
# platform: no implicit fused multiply-add contraction.
|
|
69
|
+
target_compile_options(obdeect_stream_core INTERFACE -ffp-contract=off)
|
|
70
|
+
|
|
71
|
+
function(obdeect_stream_enable_warnings target)
|
|
72
|
+
target_compile_options(${target} PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
|
73
|
+
endfunction()
|
|
74
|
+
|
|
75
|
+
# Headers and the package config for consumers (find_package(obdeect_stream CONFIG)).
|
|
76
|
+
if(OBDEECT_STREAM_INSTALL)
|
|
77
|
+
install(DIRECTORY cpp/include/obdeect/stream DESTINATION ${OBDEECT_STREAM_INCLUDE_INSTALL_DIR}/obdeect)
|
|
78
|
+
install(FILES ${OBDEECT_STREAM_GENERATED_DIR}/obdeect/stream/version.hpp
|
|
79
|
+
DESTINATION ${OBDEECT_STREAM_INCLUDE_INSTALL_DIR}/obdeect/stream)
|
|
80
|
+
install(TARGETS obdeect_stream_core EXPORT obdeect_stream-targets)
|
|
81
|
+
endif()
|
|
82
|
+
|
|
83
|
+
# C API: stable ABI for non-C++ programs (cpp/include/obdeect/stream/obdeect_stream.h), exported as
|
|
84
|
+
# obdeect::stream_c.
|
|
85
|
+
if(OBDEECT_STREAM_BUILD_CAPI)
|
|
86
|
+
add_library(obdeect_stream_c SHARED cpp/capi/obdeect_stream_c.cpp)
|
|
87
|
+
add_library(obdeect::stream_c ALIAS obdeect_stream_c)
|
|
88
|
+
set_target_properties(obdeect_stream_c PROPERTIES EXPORT_NAME stream_c)
|
|
89
|
+
target_link_libraries(obdeect_stream_c PRIVATE obdeect_stream_core)
|
|
90
|
+
target_include_directories(obdeect_stream_c PUBLIC
|
|
91
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp/include>
|
|
92
|
+
$<INSTALL_INTERFACE:${OBDEECT_STREAM_INCLUDE_INSTALL_DIR}>)
|
|
93
|
+
target_compile_definitions(obdeect_stream_c PRIVATE OBDEECT_STREAM_C_BUILDING
|
|
94
|
+
"OBDEECT_STREAM_PACKAGE_VERSION=\"${OBDEECT_STREAM_PACKAGE_VERSION}\"")
|
|
95
|
+
set_target_properties(obdeect_stream_c PROPERTIES CXX_VISIBILITY_PRESET hidden
|
|
96
|
+
VISIBILITY_INLINES_HIDDEN ON)
|
|
97
|
+
if(NOT DEFINED SKBUILD_PLATLIB_DIR) # wheels cannot hold the symlinks
|
|
98
|
+
set_target_properties(obdeect_stream_c PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION 1)
|
|
99
|
+
endif()
|
|
100
|
+
obdeect_stream_enable_warnings(obdeect_stream_c)
|
|
101
|
+
install(TARGETS obdeect_stream_c EXPORT obdeect_stream-targets
|
|
102
|
+
LIBRARY DESTINATION ${OBDEECT_STREAM_LIB_INSTALL_DIR}
|
|
103
|
+
RUNTIME DESTINATION ${OBDEECT_STREAM_LIB_INSTALL_DIR}
|
|
104
|
+
ARCHIVE DESTINATION ${OBDEECT_STREAM_LIB_INSTALL_DIR})
|
|
105
|
+
endif()
|
|
106
|
+
if(OBDEECT_STREAM_INSTALL)
|
|
107
|
+
install(EXPORT obdeect_stream-targets NAMESPACE obdeect:: DESTINATION ${OBDEECT_STREAM_CMAKE_INSTALL_DIR})
|
|
108
|
+
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/obdeect_stream-config.cmake.in
|
|
109
|
+
${CMAKE_CURRENT_BINARY_DIR}/obdeect_stream-config.cmake
|
|
110
|
+
INSTALL_DESTINATION ${OBDEECT_STREAM_CMAKE_INSTALL_DIR})
|
|
111
|
+
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/obdeect_stream-config-version.cmake
|
|
112
|
+
VERSION ${PROJECT_VERSION} COMPATIBILITY SameMinorVersion)
|
|
113
|
+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/obdeect_stream-config.cmake
|
|
114
|
+
${CMAKE_CURRENT_BINARY_DIR}/obdeect_stream-config-version.cmake
|
|
115
|
+
DESTINATION ${OBDEECT_STREAM_CMAKE_INSTALL_DIR})
|
|
116
|
+
endif()
|
|
117
|
+
|
|
118
|
+
if(OBDEECT_STREAM_BUILD_PYTHON_API)
|
|
119
|
+
find_package(Python 3.14 COMPONENTS Interpreter Development.Module REQUIRED)
|
|
120
|
+
execute_process(COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
|
|
121
|
+
OUTPUT_VARIABLE nanobind_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
122
|
+
COMMAND_ERROR_IS_FATAL ANY)
|
|
123
|
+
find_package(nanobind CONFIG REQUIRED)
|
|
124
|
+
nanobind_add_module(_core NB_STATIC cpp/bindings/core.cpp)
|
|
125
|
+
target_link_libraries(_core PRIVATE obdeect_stream_core)
|
|
126
|
+
obdeect_stream_enable_warnings(_core)
|
|
127
|
+
install(TARGETS _core LIBRARY DESTINATION obdeect/stream)
|
|
128
|
+
endif()
|
|
129
|
+
|
|
130
|
+
if(OBDEECT_STREAM_BUILD_TOOLS)
|
|
131
|
+
# Commands of `obdeect stream <command>` and their sources in cpp/tools.
|
|
132
|
+
set(OBDEECT_STREAM_COMMANDS cat tee from-corsika to-simtel to-grisu)
|
|
133
|
+
set(OBDEECT_STREAM_COMMAND_SOURCES ps_cat ps_tee corsika2ps ps2simtel ps2grisu)
|
|
134
|
+
set(OBDEECT_STREAM_TOOLS)
|
|
135
|
+
foreach(command source IN ZIP_LISTS OBDEECT_STREAM_COMMANDS OBDEECT_STREAM_COMMAND_SOURCES)
|
|
136
|
+
set(tool obdeect-stream-${command})
|
|
137
|
+
list(APPEND OBDEECT_STREAM_TOOLS ${tool})
|
|
138
|
+
add_executable(${tool} cpp/tools/${source}.cpp)
|
|
139
|
+
target_link_libraries(${tool} PRIVATE obdeect_stream_core)
|
|
140
|
+
target_compile_definitions(${tool} PRIVATE
|
|
141
|
+
"OBDEECT_STREAM_PACKAGE_VERSION=\"${OBDEECT_STREAM_PACKAGE_VERSION}\"")
|
|
142
|
+
obdeect_stream_enable_warnings(${tool})
|
|
143
|
+
endforeach()
|
|
144
|
+
# Wheels: inside the package, run through `obdeect stream <command>`.
|
|
145
|
+
if(DEFINED SKBUILD_PLATLIB_DIR)
|
|
146
|
+
install(TARGETS ${OBDEECT_STREAM_TOOLS} RUNTIME DESTINATION obdeect/stream/bin)
|
|
147
|
+
else()
|
|
148
|
+
install(TARGETS ${OBDEECT_STREAM_TOOLS} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
149
|
+
endif()
|
|
150
|
+
endif()
|
|
151
|
+
|
|
152
|
+
if(OBDEECT_STREAM_BUILD_BENCH)
|
|
153
|
+
foreach(bench bench_stream gen_corsika)
|
|
154
|
+
add_executable(${bench} cpp/bench/${bench}.cpp)
|
|
155
|
+
target_link_libraries(${bench} PRIVATE obdeect_stream_core)
|
|
156
|
+
obdeect_stream_enable_warnings(${bench})
|
|
157
|
+
endforeach()
|
|
158
|
+
endif()
|
|
159
|
+
|
|
160
|
+
if(OBDEECT_STREAM_BUILD_TESTING)
|
|
161
|
+
enable_testing()
|
|
162
|
+
if(OBDEECT_STREAM_BUILD_BENCH)
|
|
163
|
+
add_test(NAME bench_stream_partial_chunk COMMAND bench_stream 65537
|
|
164
|
+
${CMAKE_CURRENT_BINARY_DIR}/bench_stream_test.ps)
|
|
165
|
+
endif()
|
|
166
|
+
if(OBDEECT_STREAM_BUILD_CAPI)
|
|
167
|
+
enable_language(C)
|
|
168
|
+
set(CMAKE_C_STANDARD 11)
|
|
169
|
+
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
170
|
+
set(CMAKE_C_EXTENSIONS OFF)
|
|
171
|
+
add_executable(test_capi cpp/tests/test_capi.c)
|
|
172
|
+
target_link_libraries(test_capi PRIVATE obdeect_stream_c)
|
|
173
|
+
target_compile_options(test_capi PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
|
174
|
+
set(OBDEECT_STREAM_CONFORMANCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp/tests/data/conformance)
|
|
175
|
+
add_test(NAME capi COMMAND test_capi ${CMAKE_CURRENT_BINARY_DIR}/capi_roundtrip.ps
|
|
176
|
+
${OBDEECT_STREAM_CONFORMANCE_DIR})
|
|
177
|
+
set_tests_properties(capi PROPERTIES FIXTURES_SETUP capi_stream)
|
|
178
|
+
add_executable(test_capi_cpp cpp/tests/test_capi_cpp.cpp)
|
|
179
|
+
target_link_libraries(test_capi_cpp PRIVATE obdeect_stream_c obdeect_stream_core)
|
|
180
|
+
obdeect_stream_enable_warnings(test_capi_cpp)
|
|
181
|
+
add_test(NAME capi_cpp COMMAND test_capi_cpp ${CMAKE_CURRENT_BINARY_DIR}/capi_roundtrip.ps
|
|
182
|
+
${OBDEECT_STREAM_CONFORMANCE_DIR})
|
|
183
|
+
set_tests_properties(capi_cpp PROPERTIES FIXTURES_REQUIRED capi_stream)
|
|
184
|
+
endif()
|
|
185
|
+
foreach(test_name version format stream eventio corsika simtel grisu stages)
|
|
186
|
+
add_executable(test_${test_name} cpp/tests/test_${test_name}.cpp)
|
|
187
|
+
target_link_libraries(test_${test_name} PRIVATE obdeect_stream_core)
|
|
188
|
+
obdeect_stream_enable_warnings(test_${test_name})
|
|
189
|
+
add_test(NAME ${test_name} COMMAND test_${test_name})
|
|
190
|
+
endforeach()
|
|
191
|
+
|
|
192
|
+
# --version of each tool: "<tool> <package version> (photon-stream format <major>.<minor>)".
|
|
193
|
+
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/cpp/include/obdeect/stream/format.hpp OBDEECT_STREAM_FORMAT_HPP)
|
|
194
|
+
string(REGEX MATCH "format_major = ([0-9]+)" _ "${OBDEECT_STREAM_FORMAT_HPP}")
|
|
195
|
+
set(OBDEECT_STREAM_FORMAT_MAJOR ${CMAKE_MATCH_1})
|
|
196
|
+
string(REGEX MATCH "format_minor = ([0-9]+)" _ "${OBDEECT_STREAM_FORMAT_HPP}")
|
|
197
|
+
set(OBDEECT_STREAM_FORMAT_MINOR ${CMAKE_MATCH_1})
|
|
198
|
+
if(OBDEECT_STREAM_BUILD_TOOLS)
|
|
199
|
+
foreach(command ${OBDEECT_STREAM_COMMANDS})
|
|
200
|
+
add_test(NAME ${command}_version COMMAND obdeect-stream-${command} --version)
|
|
201
|
+
set_tests_properties(${command}_version PROPERTIES PASS_REGULAR_EXPRESSION
|
|
202
|
+
"^obdeect stream ${command} ${OBDEECT_STREAM_PACKAGE_VERSION} \\(photon-stream format ${OBDEECT_STREAM_FORMAT_MAJOR}\\.${OBDEECT_STREAM_FORMAT_MINOR}\\)")
|
|
203
|
+
endforeach()
|
|
204
|
+
endif()
|
|
205
|
+
endif()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: obdeect-stream
|
|
3
|
+
Version: 0.8.0
|
|
4
|
+
Summary: Photon-stream format and I/O for Cherenkov-telescope simulation chains
|
|
5
|
+
Author: obdeect contributors
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Programming Language :: C++
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
12
|
+
Requires-Python: >=3.14
|
|
13
|
+
Requires-Dist: numpy>=2.3
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: nanobind>=3.1; extra == "dev"
|
|
16
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
17
|
+
Requires-Dist: pytest; extra == "dev"
|
|
18
|
+
Requires-Dist: ruff; extra == "dev"
|
|
19
|
+
Provides-Extra: docs
|
|
20
|
+
Requires-Dist: myst-parser; extra == "docs"
|
|
21
|
+
Requires-Dist: pydata-sphinx-theme; extra == "docs"
|
|
22
|
+
Requires-Dist: pyyaml; extra == "docs"
|
|
23
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
24
|
+
Provides-Extra: plot
|
|
25
|
+
Requires-Dist: matplotlib>=3.8; extra == "plot"
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# obdeect-stream
|
|
29
|
+
|
|
30
|
+
Photon-stream format and I/O for Cherenkov-telescope simulation chains. A versioned, columnar
|
|
31
|
+
photon-stream format with a C++20 reader and writer (standard library only), a Python API, and
|
|
32
|
+
adapters from CORSIKA IACT output and to sim_telarray input. Modules of the chain exchange
|
|
33
|
+
photons as photon streams.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pip install obdeect-stream # this component only
|
|
37
|
+
pip install obdeect # all obdeect components
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Requires Python 3.14 or higher.
|
|
41
|
+
|
|
42
|
+
## Commands
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
obdeect stream cat [FILE ...] # concatenate streams; --summary for record counts
|
|
46
|
+
obdeect stream tee FILE # copy a stream passing through
|
|
47
|
+
obdeect stream from-corsika < run.iact # CORSIKA IACT EventIO to photon stream
|
|
48
|
+
obdeect stream to-simtel --camera-map cam.txt run.ps > sim.simtel # photon stream to sim_telarray input
|
|
49
|
+
obdeect stream to-grisu --telescope-config TLLOC.dat run.ps > run.grisu # GrISU photon text
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Full documentation and the repository README: https://github.com/gammasim/obdeect
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# obdeect-stream
|
|
2
|
+
|
|
3
|
+
Photon-stream format and I/O for Cherenkov-telescope simulation chains. A versioned, columnar
|
|
4
|
+
photon-stream format with a C++20 reader and writer (standard library only), a Python API, and
|
|
5
|
+
adapters from CORSIKA IACT output and to sim_telarray input. Modules of the chain exchange
|
|
6
|
+
photons as photon streams.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pip install obdeect-stream # this component only
|
|
10
|
+
pip install obdeect # all obdeect components
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Python 3.14 or higher.
|
|
14
|
+
|
|
15
|
+
## Commands
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
obdeect stream cat [FILE ...] # concatenate streams; --summary for record counts
|
|
19
|
+
obdeect stream tee FILE # copy a stream passing through
|
|
20
|
+
obdeect stream from-corsika < run.iact # CORSIKA IACT EventIO to photon stream
|
|
21
|
+
obdeect stream to-simtel --camera-map cam.txt run.ps > sim.simtel # photon stream to sim_telarray input
|
|
22
|
+
obdeect stream to-grisu --telescope-config TLLOC.dat run.ps > run.grisu # GrISU photon text
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Full documentation and the repository README: https://github.com/gammasim/obdeect
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// Generated by CMake from cmake/version.hpp.in (the project version). Do not edit.
|
|
4
|
+
|
|
5
|
+
namespace obdeect::stream {
|
|
6
|
+
|
|
7
|
+
inline constexpr int version_major = @PROJECT_VERSION_MAJOR@;
|
|
8
|
+
inline constexpr int version_minor = @PROJECT_VERSION_MINOR@;
|
|
9
|
+
inline constexpr int version_patch = @PROJECT_VERSION_PATCH@;
|
|
10
|
+
|
|
11
|
+
} // namespace obdeect::stream
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Throughput of the photon-stream writer and reader through a file.
|
|
2
|
+
// Usage: bench_stream [photons] [file] (defaults: 1e8 photons, temp file)
|
|
3
|
+
|
|
4
|
+
#include "obdeect/stream/stream.hpp"
|
|
5
|
+
|
|
6
|
+
#include <algorithm>
|
|
7
|
+
#include <chrono>
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <cstdio>
|
|
10
|
+
#include <cstdlib>
|
|
11
|
+
#include <exception>
|
|
12
|
+
#include <filesystem>
|
|
13
|
+
#include <fstream>
|
|
14
|
+
#include <string>
|
|
15
|
+
#include <vector>
|
|
16
|
+
|
|
17
|
+
namespace {
|
|
18
|
+
|
|
19
|
+
constexpr std::uint64_t chunk_rows = std::uint64_t{1} << 16;
|
|
20
|
+
|
|
21
|
+
double seconds_since(std::chrono::steady_clock::time_point start) {
|
|
22
|
+
return std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace
|
|
26
|
+
|
|
27
|
+
static int run(int argc, char **argv) {
|
|
28
|
+
const std::uint64_t photons = argc > 1 ? std::strtoull(argv[1], nullptr, 10) : 100000000ULL;
|
|
29
|
+
const std::filesystem::path path =
|
|
30
|
+
argc > 2 ? std::filesystem::path(argv[2])
|
|
31
|
+
: std::filesystem::temp_directory_path() / "obdeect_stream_bench.ps";
|
|
32
|
+
const std::uint64_t n_chunks = (photons + chunk_rows - 1) / chunk_rows;
|
|
33
|
+
|
|
34
|
+
obdeect::stream::PhotonChunk chunk;
|
|
35
|
+
chunk.telescope_id = 1;
|
|
36
|
+
chunk.frame = obdeect::stream::Frame::telescope;
|
|
37
|
+
chunk.resize(chunk_rows, obdeect::stream::required_columns |
|
|
38
|
+
obdeect::stream::column_bit(obdeect::stream::Column::zem) |
|
|
39
|
+
obdeect::stream::column_bit(obdeect::stream::Column::wavelength));
|
|
40
|
+
for (auto &column : chunk.columns) {
|
|
41
|
+
for (std::size_t r = 0; r < column.size(); ++r) {
|
|
42
|
+
column[r] = static_cast<float>(r) * 0.001F;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
std::vector<char> buffer(std::size_t{1} << 20);
|
|
47
|
+
double write_seconds = 0.0;
|
|
48
|
+
double bytes = 0.0; // file size in bytes
|
|
49
|
+
{
|
|
50
|
+
std::ofstream out;
|
|
51
|
+
out.rdbuf()->pubsetbuf(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
|
52
|
+
out.open(path, std::ios::binary);
|
|
53
|
+
if (!out) {
|
|
54
|
+
std::fprintf(stderr, "cannot open %s\n", path.string().c_str());
|
|
55
|
+
return EXIT_FAILURE;
|
|
56
|
+
}
|
|
57
|
+
const auto start = std::chrono::steady_clock::now();
|
|
58
|
+
obdeect::stream::Writer writer(out, "bench_stream");
|
|
59
|
+
for (std::uint64_t i = 0; i < n_chunks; ++i) {
|
|
60
|
+
const std::uint64_t rows = std::min<std::uint64_t>(chunk_rows, photons - i * chunk_rows);
|
|
61
|
+
if (rows != chunk.rows()) { // last, shorter chunk
|
|
62
|
+
const std::uint32_t mask = chunk.mask();
|
|
63
|
+
chunk.resize(rows, mask);
|
|
64
|
+
for (auto &column : chunk.columns) {
|
|
65
|
+
for (std::size_t r = 0; r < column.size(); ++r) {
|
|
66
|
+
column[r] = static_cast<float>(r) * 0.001F;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
chunk.first_index = i * chunk_rows;
|
|
71
|
+
writer.write_chunk(chunk);
|
|
72
|
+
}
|
|
73
|
+
writer.finish();
|
|
74
|
+
out.close();
|
|
75
|
+
write_seconds = seconds_since(start);
|
|
76
|
+
bytes = static_cast<double>(std::filesystem::file_size(path));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
std::uint64_t read_photons = 0;
|
|
80
|
+
double weight_sum = 0.0;
|
|
81
|
+
double read_seconds = 0.0;
|
|
82
|
+
{
|
|
83
|
+
std::ifstream in;
|
|
84
|
+
in.rdbuf()->pubsetbuf(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
|
85
|
+
in.open(path, std::ios::binary);
|
|
86
|
+
const auto start = std::chrono::steady_clock::now();
|
|
87
|
+
obdeect::stream::Reader reader(in);
|
|
88
|
+
obdeect::stream::Record record;
|
|
89
|
+
while (reader.next(record)) {
|
|
90
|
+
if (record.type == obdeect::stream::RecordType::photons) {
|
|
91
|
+
read_photons += record.chunk.rows();
|
|
92
|
+
for (const float w : record.chunk[obdeect::stream::Column::w]) {
|
|
93
|
+
weight_sum += w;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
read_seconds = seconds_since(start);
|
|
98
|
+
}
|
|
99
|
+
std::filesystem::remove(path);
|
|
100
|
+
|
|
101
|
+
const double mb = bytes / 1e6;
|
|
102
|
+
std::printf("photons written: %llu (%llu chunks of %llu rows, 8 columns)\n",
|
|
103
|
+
static_cast<unsigned long long>(photons), static_cast<unsigned long long>(n_chunks),
|
|
104
|
+
static_cast<unsigned long long>(chunk_rows));
|
|
105
|
+
std::printf("file size: %.1f MB\n", mb);
|
|
106
|
+
std::printf("write: %.2f s, %.0f MB/s\n", write_seconds, mb / write_seconds);
|
|
107
|
+
std::printf("read: %.2f s, %.0f MB/s (read %llu photons, weight sum %.6g)\n", read_seconds,
|
|
108
|
+
mb / read_seconds, static_cast<unsigned long long>(read_photons), weight_sum);
|
|
109
|
+
return read_photons == photons ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
int main(int argc, char **argv) {
|
|
113
|
+
try {
|
|
114
|
+
return run(argc, argv);
|
|
115
|
+
} catch (const std::exception &error) {
|
|
116
|
+
std::fprintf(stderr, "bench_stream: %s\n", error.what());
|
|
117
|
+
return 1;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Writes a synthetic CORSIKA IACT EventIO file (normal mode, long-format photon blocks) for
|
|
2
|
+
// throughput tests of obdeect stream from-corsika and obdeect stream to-simtel.
|
|
3
|
+
// Usage: gen_corsika OUTPUT [BUNCHES=10000000] [TELESCOPES=4] [BUNCHES_PER_BLOCK=250000]
|
|
4
|
+
|
|
5
|
+
#include "obdeect/stream/eventio.hpp"
|
|
6
|
+
|
|
7
|
+
#include <cstdint>
|
|
8
|
+
#include <cstdio>
|
|
9
|
+
#include <cstdlib>
|
|
10
|
+
#include <exception>
|
|
11
|
+
#include <fstream>
|
|
12
|
+
#include <random>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <vector>
|
|
15
|
+
|
|
16
|
+
namespace {
|
|
17
|
+
|
|
18
|
+
std::vector<float> words273() { return std::vector<float>(273, 0.0F); }
|
|
19
|
+
|
|
20
|
+
} // namespace
|
|
21
|
+
|
|
22
|
+
static int run(int argc, char **argv) {
|
|
23
|
+
if (argc < 2) {
|
|
24
|
+
std::fprintf(stderr, "usage: gen_corsika OUTPUT [BUNCHES] [TELESCOPES] [BUNCHES_PER_BLOCK]\n");
|
|
25
|
+
return 2;
|
|
26
|
+
}
|
|
27
|
+
const auto total = argc > 2 ? std::strtoull(argv[2], nullptr, 10) : 10000000ULL;
|
|
28
|
+
const auto telescopes = argc > 3 ? std::strtoull(argv[3], nullptr, 10) : 4ULL;
|
|
29
|
+
const auto per_block = argc > 4 ? std::strtoull(argv[4], nullptr, 10) : 250000ULL;
|
|
30
|
+
if (total == 0 || telescopes == 0 || per_block == 0) {
|
|
31
|
+
std::fprintf(stderr, "gen_corsika: counts must be positive\n");
|
|
32
|
+
return 2;
|
|
33
|
+
}
|
|
34
|
+
const std::uint64_t per_event = telescopes * per_block;
|
|
35
|
+
const std::uint64_t events = (total + per_event - 1) / per_event;
|
|
36
|
+
|
|
37
|
+
std::ofstream out(argv[1], std::ios::binary);
|
|
38
|
+
if (!out) {
|
|
39
|
+
std::fprintf(stderr, "gen_corsika: cannot open %s\n", argv[1]);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
std::vector<char> buffer(std::size_t{1} << 20);
|
|
43
|
+
out.rdbuf()->pubsetbuf(buffer.data(), static_cast<std::streamsize>(buffer.size()));
|
|
44
|
+
|
|
45
|
+
std::vector<float> runh = words273();
|
|
46
|
+
runh[1] = 1.0F;
|
|
47
|
+
runh[3] = 7.41F;
|
|
48
|
+
runh[4] = 1.0F;
|
|
49
|
+
runh[5] = 2200000.0F;
|
|
50
|
+
runh[16] = 10.0F;
|
|
51
|
+
runh[17] = 100000.0F;
|
|
52
|
+
obdeect::stream::write_block(
|
|
53
|
+
out, obdeect::stream::make_float_block(obdeect::stream::iact::runh, 1, runh));
|
|
54
|
+
|
|
55
|
+
obdeect::stream::TelPos pos;
|
|
56
|
+
for (std::uint64_t t = 0; t < telescopes; ++t) {
|
|
57
|
+
pos.x.push_back(10000.0 * static_cast<double>(t));
|
|
58
|
+
pos.y.push_back(0.0);
|
|
59
|
+
pos.z.push_back(0.0);
|
|
60
|
+
pos.r.push_back(1200.0);
|
|
61
|
+
}
|
|
62
|
+
obdeect::stream::write_block(out, obdeect::stream::make_telpos_block(pos));
|
|
63
|
+
|
|
64
|
+
std::mt19937 rng{20261107};
|
|
65
|
+
std::uniform_real_distribution<float> position{-10000.0F, 10000.0F};
|
|
66
|
+
std::uniform_real_distribution<float> direction{-0.3F, 0.3F};
|
|
67
|
+
std::uniform_real_distribution<float> time{0.0F, 100.0F};
|
|
68
|
+
for (std::uint64_t e = 1; e <= events; ++e) {
|
|
69
|
+
std::vector<float> evth = words273();
|
|
70
|
+
evth[1] = static_cast<float>(e);
|
|
71
|
+
evth[2] = 14.0F;
|
|
72
|
+
evth[3] = 1000.0F;
|
|
73
|
+
evth[6] = 2500000.0F;
|
|
74
|
+
evth[10] = 0.3F;
|
|
75
|
+
evth[11] = 1.2F;
|
|
76
|
+
evth[76] = 5136.0F;
|
|
77
|
+
evth[95] = 250.0F;
|
|
78
|
+
evth[96] = 800.0F;
|
|
79
|
+
obdeect::stream::write_block(
|
|
80
|
+
out, obdeect::stream::make_float_block(obdeect::stream::iact::evth,
|
|
81
|
+
static_cast<std::uint32_t>(e), evth));
|
|
82
|
+
obdeect::stream::TelOffset off;
|
|
83
|
+
off.xoff = {0.0};
|
|
84
|
+
off.yoff = {0.0};
|
|
85
|
+
obdeect::stream::write_block(out, obdeect::stream::make_teloff_block(off));
|
|
86
|
+
|
|
87
|
+
std::vector<obdeect::stream::EventioBlock> children;
|
|
88
|
+
for (std::uint64_t t = 0; t < telescopes; ++t) {
|
|
89
|
+
obdeect::stream::TelPhotons p;
|
|
90
|
+
p.array = 0;
|
|
91
|
+
p.tel = static_cast<int>(t);
|
|
92
|
+
p.bunches.reserve(per_block);
|
|
93
|
+
for (std::uint64_t i = 0; i < per_block; ++i) {
|
|
94
|
+
obdeect::stream::Bunch b;
|
|
95
|
+
b.x = position(rng);
|
|
96
|
+
b.y = position(rng);
|
|
97
|
+
b.cx = direction(rng);
|
|
98
|
+
b.cy = direction(rng);
|
|
99
|
+
b.ctime = time(rng);
|
|
100
|
+
b.zem = 2000000.0F;
|
|
101
|
+
b.photons = (i % 3 == 0) ? 2.0F : 1.0F;
|
|
102
|
+
b.lambda = 400.0F;
|
|
103
|
+
p.photons += b.photons;
|
|
104
|
+
p.bunches.push_back(b);
|
|
105
|
+
}
|
|
106
|
+
children.push_back(obdeect::stream::make_photons_block(p));
|
|
107
|
+
}
|
|
108
|
+
obdeect::stream::write_block(
|
|
109
|
+
out, obdeect::stream::make_container(obdeect::stream::iact::telarray, 0, 0, children));
|
|
110
|
+
std::vector<float> evte = words273();
|
|
111
|
+
evte[1] = static_cast<float>(e);
|
|
112
|
+
obdeect::stream::write_block(
|
|
113
|
+
out, obdeect::stream::make_float_block(obdeect::stream::iact::evte,
|
|
114
|
+
static_cast<std::uint32_t>(e), evte));
|
|
115
|
+
}
|
|
116
|
+
std::vector<float> rune = words273();
|
|
117
|
+
rune[1] = 1.0F;
|
|
118
|
+
obdeect::stream::write_block(
|
|
119
|
+
out, obdeect::stream::make_float_block(obdeect::stream::iact::rune, 1, rune));
|
|
120
|
+
out.close();
|
|
121
|
+
if (!out) {
|
|
122
|
+
std::fprintf(stderr, "gen_corsika: write failed\n");
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
std::printf("%llu events, %llu telescopes, %llu bunches\n",
|
|
126
|
+
static_cast<unsigned long long>(events), static_cast<unsigned long long>(telescopes),
|
|
127
|
+
static_cast<unsigned long long>(events * per_event));
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
int main(int argc, char **argv) {
|
|
132
|
+
try {
|
|
133
|
+
return run(argc, argv);
|
|
134
|
+
} catch (const std::exception &error) {
|
|
135
|
+
std::fprintf(stderr, "gen_corsika: %s\n", error.what());
|
|
136
|
+
return 1;
|
|
137
|
+
}
|
|
138
|
+
}
|