Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
km3io
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
km3py
km3io
Commits
196cbe1c
Commit
196cbe1c
authored
5 years ago
by
Johannes Schumann
Browse files
Options
Downloads
Patches
Plain Diff
First version of GSGReader
parent
e3012b97
No related branches found
No related tags found
1 merge request
!26
Gseagen dataformat
Pipeline
#10074
passed with warnings
5 years ago
Stage: test
Stage: coverage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
km3io/gseagen.py
+55
-0
55 additions, 0 deletions
km3io/gseagen.py
with
55 additions
and
0 deletions
km3io/gseagen.py
0 → 100644
+
55
−
0
View file @
196cbe1c
#!/usr/bin/env python
# coding=utf-8
# Filename: gseagen.py
# Author: Johannes Schumann <jschumann@km3net.de>
import
uproot
import
numpy
as
np
import
warnings
from
.tools
import
Branch
,
BranchMapper
,
cached_property
MAIN_TREE_NAME
=
"
Events
"
class
GSGReader
:
"""
reader for gSeaGen ROOT files
"""
def
__init__
(
self
,
file_path
=
None
,
fobj
=
None
):
"""
GSGReader class is a gSeaGen ROOT file wrapper
Parameters
----------
file_path : path-like object
Path to the file of interest. It can be a str or any python
path-like object that points to the file.
"""
if
file_path
is
not
None
:
self
.
_fobj
=
uproot
.
open
(
file_path
)
else
:
self
.
_fobj
=
fobj
@cached_property
def
header
(
self
):
header_key
=
'
Header
'
if
header_key
in
self
.
_fobj
:
header
=
{}
for
k
,
v
in
self
.
_fobj
[
header_key
].
items
():
v
=
v
.
array
()[
0
]
if
isinstance
(
v
,
bytes
):
try
:
v
=
v
.
decode
(
'
utf-8
'
)
except
UnicodeDecodeError
:
pass
header
[
k
.
decode
(
"
utf-8
"
)]
=
v
return
header
else
:
warnings
.
warn
(
"
Your file header has an unsupported format
"
)
@cached_property
def
events
(
self
):
gseagen_events_mapper
=
BranchMapper
(
name
=
"
Events
"
,
key
=
"
Events
"
,
extra
=
{},
exclude
=
{},
update
=
{},
attrparser
=
lambda
x
:
x
,
flat
=
True
)
return
Branch
(
self
.
_fobj
,
gseagen_events_mapper
)
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