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
a1b6862c
Verified
Commit
a1b6862c
authored
1 month ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add I/O helper functions
parent
910db20a
No related branches found
No related tags found
1 merge request
!51
Draft: Add more I/O functionalities
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
docs/src/api.md
+2
-0
2 additions, 0 deletions
docs/src/api.md
src/daq.jl
+6
-0
6 additions, 0 deletions
src/daq.jl
src/exports.jl
+4
-0
4 additions, 0 deletions
src/exports.jl
src/tools/general.jl
+39
-0
39 additions, 0 deletions
src/tools/general.jl
with
51 additions
and
0 deletions
docs/src/api.md
+
2
−
0
View file @
a1b6862c
...
...
@@ -150,6 +150,8 @@ getevent
categorize
nthbitset
most_frequent
packedsize
writestruct
```
### DAQ
...
...
This diff is collapsed.
Click to expand it.
src/daq.jl
+
6
−
0
View file @
a1b6862c
...
...
@@ -52,3 +52,9 @@ function Base.read(s::IO, ::Type{T}; legacy=false) where T<:DAQEvent
T
(
header
,
snapshot_hits
,
triggered_hits
)
end
function
Base.write
(
io
::
IO
,
s
::
Summaryslice
)
# write(io, Int32(size?))
# write(io, Int32(DAQDATATYPES.DAQSUMMARYSLICE))
writestruct
(
io
,
s
.
header
)
end
This diff is collapsed.
Click to expand it.
src/exports.jl
+
4
−
0
View file @
a1b6862c
...
...
@@ -130,6 +130,10 @@ MCEventMatcher,
SummarysliceIntervalIterator
,
getevent
,
# I/O
packedsize
,
writestruct
,
# Utils
categorize
,
is3dmuon
,
...
...
This diff is collapsed.
Click to expand it.
src/tools/general.jl
+
39
−
0
View file @
a1b6862c
...
...
@@ -109,3 +109,42 @@ function tonumifpossible(v::AbstractString)
end
v
end
"""
Calculates the packed size in bytes of an immutable struct containing only
primitives and other isbitstypes.
"""
function
packedsize
(
dt
::
DataType
)
isbitstype
(
dt
)
||
error
(
"Only isbits types are supported"
)
n
=
0
for
ftype
in
fieldtypes
(
dt
)
if
isprimitivetype
(
ftype
)
n
+=
sizeof
(
ftype
)
else
n
+=
packedsize
(
ftype
)
end
end
n
end
packedsize
(
::
T
)
where
T
=
packedsize
(
T
)
"""
Serialises an immutable struct containing only primitives and
other isbitstypes. Returns the number of bytes written.
"""
function
writestruct
(
io
::
IO
,
s
::
T
)
where
T
isbitstype
(
T
)
||
error
(
"Only isbits types are supported"
)
n
=
0
for
fname
in
fieldnames
(
T
)
v
=
getfield
(
s
,
fname
)
if
isprimitivetype
(
fieldtype
(
T
,
fname
))
write
(
io
,
v
)
n
+=
sizeof
(
v
)
else
n
+=
writestruct
(
io
,
v
)
end
end
n
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