Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve extensions for LegendDataManagement and refactor test output #41

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ EncodedArrays = "97725368-735e-11e9-0dd7-6bf34c3b13a8"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
LegendDataTypes = "99e09c13-5545-5ee2-bfa2-77f358fb75d8"
RadiationDetectorSignals = "bf2c0563-65cf-5db2-a620-ceb7de82658c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Expand All @@ -27,9 +28,10 @@ ArraysOfArrays = "0.5, 0.6"
ElasticArrays = "1"
EncodedArrays = "0.4"
HDF5 = "0.15, 0.16, 0.17"
LegendDataManagement = "0.2.8"
LegendDataManagement = "0.2"
LegendDataTypes = "0.1"
RadiationDetectorSignals = "0.3"
Requires = "0.5, 1"
StaticArrays = "0.12, 1.0"
StatsBase = "0.32, 0.33, 0.34"
StructArrays = "0.4, 0.5, 0.6"
Expand Down
40 changes: 18 additions & 22 deletions ext/LegendHDF5IOLegendDataManagementExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,31 @@ LegendHDF5IO.LH5Array(ds::LegendHDF5IO.HDF5.Dataset, ::Type{<:T}
T(s)
end

function LegendHDF5IO.LH5Array(ds::LegendHDF5IO.HDF5.Dataset, ::Type{<:AbstractArray{<:T, N}}
) where {T <: DataSelector, N}
function LegendHDF5IO.LH5Array(ds::LegendHDF5IO.HDF5.Dataset,
::Type{<:AbstractArray{<:T, N}}) where {T <: DataSelector, N}

s = read(ds)
T.(s)
end

function __init__()
LegendHDF5IO._datatype_dict["expsetup"] = ExpSetup
LegendHDF5IO._datatype_dict["datatier"] = DataTier
LegendHDF5IO._datatype_dict["datapartition"] = DataPartition
LegendHDF5IO._datatype_dict["dataperiod"] = DataPeriod
LegendHDF5IO._datatype_dict["datarun"] = DataRun
LegendHDF5IO._datatype_dict["datacategory"] = DataCategory
LegendHDF5IO._datatype_dict["timestamp"] = Timestamp
LegendHDF5IO._datatype_dict["filekey"] = FileKey
LegendHDF5IO._datatype_dict["channelid"] = ChannelId
LegendHDF5IO._datatype_dict["detectorid"] = DetectorId
function extend_datatype_dict(::Type{T}, key::String
) where {T <: DataSelector}

LegendHDF5IO._datatype_dict[key] = T
dataselector_bytypes[T] = key
end

dataselector_bytypes[ExpSetup] = "expsetup"
dataselector_bytypes[DataTier] = "datatier"
dataselector_bytypes[DataPartition] = "datapartition"
dataselector_bytypes[DataPeriod] = "dataperiod"
dataselector_bytypes[DataRun] = "datarun"
dataselector_bytypes[DataCategory] = "datacategory"
dataselector_bytypes[Timestamp] = "timestamp"
dataselector_bytypes[FileKey] = "filekey"
dataselector_bytypes[ChannelId] = "channelid"
dataselector_bytypes[DetectorId] = "detectorid"
(@isdefined ExpSetup) && extend_datatype_dict(ExpSetup, "expsetup")
(@isdefined DataTier) && extend_datatype_dict(DataTier, "datatier")
(@isdefined DataRun) && extend_datatype_dict(DataRun, "datarun")
(@isdefined DataPeriod) && extend_datatype_dict(DataPeriod, "dataperiod")
(@isdefined DataCategory) && extend_datatype_dict(DataCategory, "datacategory")
(@isdefined Timestamp) && extend_datatype_dict(Timestamp, "timestamp")
(@isdefined FileKey) && extend_datatype_dict(FileKey, "filekey")
(@isdefined ChannelId) && extend_datatype_dict(ChannelId, "channelid")
(@isdefined DetectorId) && extend_datatype_dict(DetectorId, "detectorid")
(@isdefined DataPartition) && extend_datatype_dict(DataPartition, "datapartition")
end

end
9 changes: 9 additions & 0 deletions src/LegendHDF5IO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@ include("types.jl")

const _datatype_dict = Dict{String,Type}()

@static if !isdefined(Base, :get_extension)
using Requires
end

function __init__()
_datatype_dict[datatype_to_string(EventType)] = EventType
_datatype_dict["table{t0,dt,values}"] = Vector{<:RDWaveform}
_datatype_dict["struct{binning,weights,isdensity}"] = Histogram

@static if !isdefined(Base, :get_extension)
@require LegendDataManagement = "9feedd95-f0e0-423f-a8dc-de0970eae6b3" begin
include("../ext/LegendHDF5IOLegendDataManagementExt.jl")
end
end
end

end # module
6 changes: 5 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Base.show(io::IO, lh::LHDataStore) = show(io, MIME"text/plain"(), lh)

function Base.setindex!(lh::LHDataStore, v, i::AbstractString)
create_entry(lh, i, v, usechunks=lh.usechunks)
return v
nothing
end

Base.setindex!(lh::LHDataStore, v, i::Any...) =
Expand Down Expand Up @@ -686,6 +686,7 @@ function add_entries!(lhd::LHDataStore, i::AbstractString,
HDF5.rename_attribute(lhd.data_store[i], "datatype", "datatype_old")
HDF5.delete_attribute(lhd.data_store[i], "datatype_old")
setdatatype!(lhd.data_store[i], typeof(tbl))
nothing
end

"""
Expand All @@ -704,6 +705,7 @@ function add_entries!(lhd::LHDataStore, i::AbstractString, src::NamedTuple,
HDF5.rename_attribute(lhd.data_store[i], "datatype", "datatype_old")
HDF5.delete_attribute(lhd.data_store[i], "datatype_old")
setdatatype!(lhd.data_store[i], typeof(new_nt))
nothing
end
export add_entries!

Expand Down Expand Up @@ -736,6 +738,7 @@ function _delete_entry(lhd::LHDataStore, nt::NamedTuple,
setdatatype!(lhd.data_store[parent], typeof(new_nt))
end
HDF5.delete_object(lhd.data_store["$(parent)/$(child)"])
nothing
end

function _delete_entry(lhd::LHDataStore, tbl::Table, parent::AbstractString,
Expand All @@ -747,4 +750,5 @@ function _delete_entry(lhd::LHDataStore, tbl::Table, parent::AbstractString,
HDF5.rename_attribute(lhd.data_store[parent], "datatype", "datatype_old")
HDF5.delete_attribute(lhd.data_store[parent], "datatype_old")
setdatatype!(lhd.data_store[parent], typeof(new_tbl))
nothing
end
26 changes: 0 additions & 26 deletions test/arrays/arrays_io.jl

This file was deleted.

3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

using Test

Test.@testset "Package LegendHDF5IO" begin
include("arrays/arrays_io.jl")
Test.@testset verbose=true "Package LegendHDF5IO" begin
include("ranges/range_to_namedtuple.jl")
include("histograms/histogram_io.jl")
include("test_wrappers.jl")
Expand Down
Loading
Loading