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
b90b8d27
Commit
b90b8d27
authored
5 years ago
by
Johannes Schumann
Browse files
Options
Downloads
Patches
Plain Diff
Evt header
parent
7fca36c0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/KM3io.jl
+34
-11
34 additions, 11 deletions
src/KM3io.jl
with
34 additions
and
11 deletions
src/KM3io.jl
+
34
−
11
View file @
b90b8d27
...
...
@@ -69,6 +69,8 @@ end
# Event() = Event(Vector{AbstractHit}(), missing, Vector{Track}(), missing)
struct
EvtFile
<:
DataFile
runid
::
Int64
header
::
Dict
{
AbstractString
,
AbstractString
}
events
::
Dict
{
T
,
Event
}
where
{
T
<:
Integer
}
end
...
...
@@ -76,7 +78,8 @@ function getindex(f::EvtFile, i::Integer)
f
.
events
[
i
]
end
EvtFile
()
=
EvtFile
(
Dict
{
Int64
,
Event
}())
EvtFile
(
runid
)
=
EvtFile
(
runid
,
Dict
{
AbstractString
,
AbstractString
}(),
Dict
{
Int64
,
Event
}())
EvtFile
()
=
EvtFile
(
-
1
)
function
read_evt_hit
(
line
::
AbstractString
)
fields
=
split
(
line
)
...
...
@@ -159,7 +162,19 @@ function read_evt_file(filepath::AbstractString)
evtfile
=
EvtFile
()
while
!
eof
(
f
)
line
=
readline
(
f
)
if
occursin
(
"start_event:"
,
line
)
if
occursin
(
"start_run:"
,
line
)
fields
=
split
(
line
)
runid
=
parse
(
Int64
,
fields
[
2
])
evtfile
=
EvtFile
(
runid
)
line
=
readline
(
f
)
while
!
occursin
(
"end_event:"
,
line
)
fields
=
split
(
line
,
":"
)
key
=
fields
[
1
]
value
=
strip
(
join
(
fields
[
2
:
end
]))
evtfile
.
header
[
key
]
=
value
line
=
readline
(
f
)
end
elseif
occursin
(
"start_event:"
,
line
)
fields
=
split
(
line
)
eventid
=
parse
(
Int64
,
fields
[
2
])
hits
=
Vector
{
AbstractHit
}()
...
...
@@ -201,30 +216,38 @@ function read_compound(files::Vector{T}) where {T <: AbstractString}
filedata
end
function
write_evt_file
(
filepath
::
AbstractString
,
data
::
EvtFile
)
f
=
open
(
filepath
,
"w"
)
function
Base.write
(
io
::
IO
,
data
::
EvtFile
)
write_hit_no
=
sum
(
length
.
(
getproperty
.
(
values
(
data
.
events
),
:
hits
)))
>
0
write
(
io
,
"start_run:
$
(data.runid)
\n
"
)
for
(
key
,
value
)
in
data
.
header
write
(
io
,
"
$(key)
:
$(value)
\n
"
)
end
write
(
io
,
"end_event:
\n
"
)
for
key
in
sort
(
collect
(
keys
(
data
.
events
)))
event
=
data
.
events
[
key
]
write
(
f
,
"start_event:
$
key 1
\n
"
)
write
(
io
,
"start_event:
$
key 1
\n
"
)
for
hit
in
event
.
hits
hit_line
=
build_evt_hit_entry
(
hit
)
write
(
f
,
hit_line
)
write
(
io
,
hit_line
)
end
if
write_hit_no
write
(
f
,
"total_hits:
$
(length(event.hits))
\n
"
)
write
(
io
,
"total_hits:
$
(length(event.hits))
\n
"
)
end
for
track
in
event
.
tracks
trk_line
=
build_evt_track_entry
(
track
)
write
(
f
,
trk_line
)
write
(
io
,
trk_line
)
end
if
!
ismissing
(
event
.
neutrino
)
nu_line
=
build_evt_nu_entry
(
event
.
neutrino
)
write
(
f
,
nu_line
)
write
(
io
,
nu_line
)
end
write
(
f
,
"end_event:
\n
"
)
end
close
(
f
)
end
function
Base.write
(
filepath
::
AbstractString
,
data
::
EvtFile
)
io
=
open
(
filepath
,
"w"
)
write
(
io
,
data
)
close
(
io
)
end
end
# module
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