Skip to content

Commit

Permalink
h5hist: write overflow as boolean but still support string (#96)
Browse files Browse the repository at this point in the history
* Write overflow as boolean but still support string

* Fix test

* Update version support

* Override h5hist v1.0

* RefValue unwrap
  • Loading branch information
tamasgal authored Dec 20, 2023
1 parent 6120223 commit 70630a0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ext/FHistHDF5Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function h5writehist(filename::AbstractString, path::AbstractString, h::Union{Hi
for (dim, edges) in enumerate(h.hist.edges)
write(g, "edges_$dim", collect(edges))
end
attributes(g)["overflow"] = string(h.overflow)
attributes(g)["nentries"] = h.nentries.x
attributes(g)["overflow"] = h.overflow
attributes(g)["nentries"] = h.nentries[]
attributes(g)["_producer"] = "FHist.jl"
attributes(g)["_h5hist_version"] = string(CURRENT_H5HIST_VERSION)
end
Expand Down Expand Up @@ -67,7 +67,7 @@ end
function h5readhist(f::HDF5.File, path::AbstractString, H::Type{<: Union{Hist1D, Hist2D, Hist3D}})
version = VersionNumber(read_attribute(f[path], "_h5hist_version"))
version >= v"2" && error("h5hist $(version) is not supported")
version > v"1" && @warn """
version > sort(SUPPORTED_H5HIST_VERSIONS)[end] && @warn """
h5hist $(version) is higher than the currently supperted one, some features might be missing.
Supported versions: $(join(SUPPORTED_H5HIST_VERSIONS, ", "))
"""
Expand All @@ -79,7 +79,7 @@ function h5readhist(f::HDF5.File, path::AbstractString, H::Type{<: Union{Hist1D,
hist = Histogram(edges, weights)

sumw2 = _read_dset(f["$path/sumw2"], H)
overflow = parse(Bool, read_attribute(f[path], "overflow"))
overflow = read_attribute(f[path], "overflow")
nentries = Base.RefValue{Int}(read_attribute(f[path], "nentries"))
H(hist, sumw2, SpinLock(), overflow, nentries)
end
Expand Down

0 comments on commit 70630a0

Please sign in to comment.