Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
KM3io.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
common
KM3io.jl
Commits
19e2abdc
Verified
Commit
19e2abdc
authored
1 year ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add addmeta() for HDF5 structures
parent
27ee41c8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/src/api.md
+1
-0
1 addition, 0 deletions
docs/src/api.md
src/KM3io.jl
+1
-1
1 addition, 1 deletion
src/KM3io.jl
src/hdf5/hdf5.jl
+16
-0
16 additions, 0 deletions
src/hdf5/hdf5.jl
test/hdf5.jl
+13
-0
13 additions, 0 deletions
test/hdf5.jl
with
31 additions
and
1 deletion
docs/src/api.md
+
1
−
0
View file @
19e2abdc
...
...
@@ -38,6 +38,7 @@ SummaryFrame
```
@docs
H5File
H5CompoundDataset
addmeta
create_dataset
flush
```
...
...
This diff is collapsed.
Click to expand it.
src/KM3io.jl
+
1
−
1
View file @
19e2abdc
...
...
@@ -18,7 +18,7 @@ import UnROOT
using
HDF5
export
ROOTFile
export
H5File
,
H5CompoundDataset
,
create_dataset
export
H5File
,
H5CompoundDataset
,
create_dataset
,
addmeta
export
Direction
,
Position
,
UTMPosition
,
Location
,
Quaternion
,
Track
,
AbstractCalibratedHit
export
Detector
,
DetectorModule
,
PMT
,
Tripod
,
Hydrophone
,
center
,
isbasemodule
...
...
This diff is collapsed.
Click to expand it.
src/hdf5/hdf5.jl
+
16
−
0
View file @
19e2abdc
...
...
@@ -16,6 +16,7 @@ struct H5CompoundDataset{T}
end
Base
.
length
(
c
::
H5CompoundDatasetCache
)
=
length
(
c
.
buffer
)
isfull
(
c
::
H5CompoundDatasetCache
)
=
length
(
c
)
>=
c
.
size
HDF5
.
read_attribute
(
cdset
::
H5CompoundDataset
,
name
::
AbstractString
)
=
HDF5
.
read_attribute
(
cdset
.
dset
,
name
)
"""
...
...
@@ -66,6 +67,7 @@ function Base.write(f::H5File, path::AbstractString, data)
write_dataset
(
f
.
_h5f
,
path
,
data
)
end
Base
.
getindex
(
f
::
H5File
,
args
...
)
=
getindex
(
f
.
_h5f
,
args
...
)
HDF5
.
read_attribute
(
f
::
H5File
,
name
::
AbstractString
)
=
HDF5
.
read_attribute
(
f
.
_h5f
,
name
)
"""
...
...
@@ -88,3 +90,17 @@ function Base.push!(d::H5CompoundDataset{T}, element::T) where T
push!
(
d
.
cache
.
buffer
,
element
)
isfull
(
d
.
cache
)
&&
flush
(
d
)
end
"""
Attaches key-value-pair meta entries to an HDF5 instance for each field of the
given object.
"""
function
addmeta
(
dset
::
Union
{
HDF5
.
Dataset
,
HDF5
.
File
,
HDF5
.
Group
,
HDF5
.
Datatype
},
object
::
T
)
where
T
for
fieldname
in
fieldnames
(
T
)
attributes
(
dset
)[
string
(
fieldname
)]
=
getfield
(
object
,
fieldname
)
end
end
addmeta
(
cdset
::
H5CompoundDataset
,
object
)
=
addmeta
(
cdset
.
dset
,
object
)
addmeta
(
f
::
H5File
,
object
)
=
addmeta
(
f
.
_h5f
,
object
)
This diff is collapsed.
Click to expand it.
test/hdf5.jl
+
13
−
0
View file @
19e2abdc
...
...
@@ -39,5 +39,18 @@ end
write
(
f
,
"directly_written_bars"
,
bars
)
@test
bars
==
reinterpret
(
Bar
,
f
[
"directly_written_bars"
][
:
])
addmeta
(
d
,
Bar
(
1
,
2.3
))
@test
read_attribute
(
d
,
"a"
)
==
1
@test
read_attribute
(
d
,
"b"
)
==
2.3
d2
=
create_dataset
(
f
,
"foo"
,
Int32
;
cache_size
=
1000
)
addmeta
(
d2
.
dset
,
Bar
(
3
,
4.5
))
@test
read_attribute
(
d2
,
"a"
)
==
3
@test
read_attribute
(
d2
,
"b"
)
==
4.5
addmeta
(
f
,
Bar
(
6
,
7.8
))
@test
read_attribute
(
f
,
"a"
)
==
6
@test
read_attribute
(
f
,
"b"
)
==
7.8
close
(
f
)
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment