From 488bfe207738c714f074e87a42ea3e8991e52234 Mon Sep 17 00:00:00 2001 From: Oliver Schulz Date: Wed, 28 Oct 2026 17:56:32 +0100 Subject: [PATCH] Support LegendHDF5IO 0.2 LegendHDF5IO 0.2 registers the LH5 datatype names of custom types with `register_datatype!` instead of writing into its datatype dictionary and extending `datatype_to_string`. The extension registers CartesianPoint and CylindricalPoint that way when the function exists and keeps the old route for LegendHDF5IO 0.1, so both versions work. The IO, CSG IO and Geant4 tests pass with LegendHDF5IO 0.1.19 and 0.2.0. Assisted-By: generative AI --- ext/SolidStateDetectorsLegendHDF5IOExt.jl | 23 ++++++++++++++++------- test/Project.toml | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ext/SolidStateDetectorsLegendHDF5IOExt.jl b/ext/SolidStateDetectorsLegendHDF5IOExt.jl index 3490003b1..64665858f 100644 --- a/ext/SolidStateDetectorsLegendHDF5IOExt.jl +++ b/ext/SolidStateDetectorsLegendHDF5IOExt.jl @@ -68,15 +68,24 @@ function SolidStateDetectors.simulate_waveforms( mcevents::AbstractVector{<:Name end -# Add support for reading and writing CartesianPoint and CylindricalPoint using LegendHDF5IO -function __init__() - LegendHDF5IO._datatype_dict["cartesianpoint"] = CartesianPoint - LegendHDF5IO._datatype_dict["cylindricalpoint"] = CylindricalPoint +# Add support for reading and writing CartesianPoint and CylindricalPoint using LegendHDF5IO. +# LegendHDF5IO v0.2 registers datatype names with `register_datatype!`, v0.1 through its +# datatype dictionary and `datatype_to_string`: +if isdefined(LegendHDF5IO, :register_datatype!) + function __init__() + LegendHDF5IO.register_datatype!("cartesianpoint", CartesianPoint) + LegendHDF5IO.register_datatype!("cylindricalpoint", CylindricalPoint) + end +else + function __init__() + LegendHDF5IO._datatype_dict["cartesianpoint"] = CartesianPoint + LegendHDF5IO._datatype_dict["cylindricalpoint"] = CylindricalPoint + end + + LegendHDF5IO.datatype_to_string(::Type{<:CartesianPoint}) = "cartesianpoint" + LegendHDF5IO.datatype_to_string(::Type{<:CylindricalPoint}) = "cylindricalpoint" end -LegendHDF5IO.datatype_to_string(::Type{<:CartesianPoint}) = "cartesianpoint" -LegendHDF5IO.datatype_to_string(::Type{<:CylindricalPoint}) = "cylindricalpoint" - # support writing points to HDF5 file using LH5Array diff --git a/test/Project.toml b/test/Project.toml index 0b7a10ffc..e1eb909df 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -23,4 +23,4 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [compat] Geant4 = "0.3.1" LegendDataTypes = "0.1.3" -LegendHDF5IO = "0.1" +LegendHDF5IO = "0.1, 0.2"