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
e075d2a5
Verified
Commit
e075d2a5
authored
6 months ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Start to count at the time of the first summaryslice
parent
20b81e1d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!41
Start to count at the time of the first summaryslice
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tools/helpers.jl
+27
-18
27 additions, 18 deletions
src/tools/helpers.jl
test/tools.jl
+24
-8
24 additions, 8 deletions
test/tools.jl
with
51 additions
and
26 deletions
src/tools/helpers.jl
+
27
−
18
View file @
e075d2a5
...
...
@@ -68,45 +68,53 @@ The returned summaryslices are also sorted in time.
# Examples
```julia-repl
julia> f = ROOTFile("
/
Volumes
/
Ultraspeed
/
Data
/
Obelix
/
KM3NeT_00000133_00014728
.
root
")
julia> f = ROOTFile("
KM3NeT_00000133_00014728
.
root
")
ROOTFile{OnlineTree (83509 events, 106969 summaryslices)}
julia> sii = SummarysliceIntervalIterator(f, 60)
SummarysliceIntervalIterator (107
53.1
s, 60s intervals, 1
80
chunks)
SummarysliceIntervalIterator (107
39.7
s, 60s intervals, 1
79
chunks)
julia> for summaryslices in sii
@show length(summaryslices)
@show summaryslices[1].header
break
end
length(summaryslices) =
440
length(summaryslices) =
599
(summaryslices[1]).header = SummarysliceHeader(133, 14728, 134, UTCExtended(1676246413, 400000000, 0))
```
!!! note
Short time intervals (
usually less than
a few tens of seconds) will likely return
empty
`Vector{Summaryslice}`s
in the first few iterations due to a delay in run changes.
Additionally, t
he number of frames per summaryslice will
gradually increase due
to the asynchronous nature of the run transition. See
the example below with a time
inteval of 5
s.
Short time intervals (a few tens of seconds) will likely return
`Vector{Summaryslice}`s
with few entries in the first and last iterations
due to a delay in run changes. T
he number of frames per summaryslice will
gradually increase due
to the asynchronous nature of the run transition. See
the example below with a time inteval of 10s and 100 active optical module
s.
```julia-repl
julia> sii = SummarysliceIntervalIterator(f,
5
)
SummarysliceIntervalIterator (10
753.1
s,
5
s intervals,
215
1 chunks)
julia> sii = SummarysliceIntervalIterator(f,
10
)
SummarysliceIntervalIterator (10
6.2
s,
10
s intervals,
1
1 chunks)
julia> for summaryslices in sii
n = length(summaryslices)
@show n
n > 0 && break
end
n = 0
n = 0
n = 5
n = 73
n = 100
n = 100
n = 100
n = 100
n = 100
n = 100
n = 100
n = 100
n = 96
n = 31
```
"""
struct
SummarysliceIntervalIterator
sc
::
KM3io
.
SummarysliceContainer
sc
::
SummarysliceContainer
first_frame_index
::
Int
time_interval
::
Int
# [s]
n_chunks
::
Int
timespan
::
Float64
...
...
@@ -114,9 +122,10 @@ struct SummarysliceIntervalIterator
function
SummarysliceIntervalIterator
(
f
::
ROOTFile
,
time_interval
)
ss
=
f
.
online
.
summaryslices
sorted_summaryslice_indices
=
sortperm
([
sh
.
frame_index
for
sh
in
ss
.
headers
])
timespan
=
ss
.
headers
[
sorted_summaryslice_indices
[
end
]]
.
frame_index
/
10
first_frame_index
=
first
(
f
.
online
.
summaryslices
)
.
header
.
frame_index
timespan
=
(
ss
.
headers
[
sorted_summaryslice_indices
[
end
]]
.
frame_index
-
ss
.
headers
[
first
(
sorted_summaryslice_indices
)]
.
frame_index
)
/
10
n_chunks
=
Int
(
ceil
(
timespan
/
time_interval
))
new
(
f
.
online
.
summaryslices
,
time_interval
,
n_chunks
,
timespan
,
sorted_summaryslice_indices
)
new
(
f
.
online
.
summaryslices
,
first_frame_index
,
time_interval
,
n_chunks
,
timespan
,
sorted_summaryslice_indices
)
end
end
function
Base.show
(
io
::
IO
,
sii
::
SummarysliceIntervalIterator
)
...
...
@@ -130,7 +139,7 @@ function Base.iterate(sii::SummarysliceIntervalIterator, state=(chunk_idx=1, s_i
out_size
=
sii
.
time_interval
*
10
out
=
empty!
(
Vector
{
KM3io
.
Summaryslice
}(
undef
,
out_size
))
frame_index_upper
=
state
.
chunk_idx
*
sii
.
time_interval
*
10
frame_index_upper
=
sii
.
first_frame_index
+
state
.
chunk_idx
*
sii
.
time_interval
*
10
s_idx
=
state
.
s_idx
while
s_idx
<=
length
(
sii
.
indices
)
...
...
This diff is collapsed.
Click to expand it.
test/tools.jl
+
24
−
8
View file @
e075d2a5
...
...
@@ -343,18 +343,34 @@ end
sii
=
SummarysliceIntervalIterator
(
f
,
2
)
suslis
=
collect
(
sii
)
@test
55
==
length
(
suslis
)
@test
0
==
length
(
suslis
[
1
])
@test
1
==
length
(
suslis
[
2
])
@test
2
==
length
(
suslis
[
3
])
@test
all
(
20
.==
length
.
(
suslis
[
4
:
end
-
5
]))
@test
8
==
length
(
suslis
[
end
-
1
])
@test
6
==
length
(
suslis
[
end
])
@test
54
==
length
(
suslis
)
@test
2
==
length
(
suslis
[
1
])
@test
11
==
length
(
suslis
[
2
])
@test
all
(
20
.==
length
.
(
suslis
[
3
:
end
-
6
]))
@test
19
==
length
(
suslis
[
end
-
5
])
@test
17
==
length
(
suslis
[
end
-
4
])
@test
12
==
length
(
suslis
[
end
-
3
])
@test
10
==
length
(
suslis
[
end
-
2
])
@test
6
==
length
(
suslis
[
end
-
1
])
@test
3
==
length
(
suslis
[
end
])
flat_suslis
=
vcat
(
suslis
...
)
original_frame_indices
=
[
s
.
header
.
frame_index
for
s
in
f
.
online
.
summaryslices
]
sorted_original_frame_indices
=
sort
(
original_frame_indices
)
frame_indices
=
[
s
.
header
.
frame_index
for
s
in
flat_suslis
]
@test
!
issorted
(
original_frame_indices
)
@test
issorted
(
frame_indices
)
@test
frame_indices
==
sort
([
s
.
header
.
frame_index
for
s
in
f
.
online
.
summaryslices
])
@test
frame_indices
==
sorted_original_frame_indices
for
time_interval
in
(
1
,
3
,
4
,
10
,
30
,
50
,
100
,
120
,
10000
)
sii
=
SummarysliceIntervalIterator
(
f
,
time_interval
)
suslis
=
collect
(
sii
)
flat_suslis
=
vcat
(
suslis
...
)
@test
length
(
f
.
online
.
summaryslices
)
==
length
(
flat_suslis
)
frame_indices
=
[
s
.
header
.
frame_index
for
s
in
flat_suslis
]
@test
sorted_original_frame_indices
==
frame_indices
@test
length
(
Set
(
frame_indices
))
==
length
(
frame_indices
)
# make sure all frame indices are unique
end
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