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
a381061c
Commit
a381061c
authored
4 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup
parent
7398b736
No related branches found
No related tags found
1 merge request
!39
WIP: Resolve "uproot4 integration"
Pipeline
#16031
failed
4 years ago
Stage: test
Stage: coverage
Stage: doc
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
km3io/offline.py
+9
-80
9 additions, 80 deletions
km3io/offline.py
with
9 additions
and
80 deletions
km3io/offline.py
+
9
−
80
View file @
a381061c
import
binascii
from
collections
import
namedtuple
from
collections
import
namedtuple
,
defaultdict
import
uproot4
as
uproot
import
uproot4
as
uproot
import
warnings
import
warnings
import
numba
as
nb
import
awkward1
as
ak1
from
.definitions
import
mc_header
,
fitparameters
,
reconstruction
from
.tools
import
cached_property
,
to_num
,
unfold_indices
from
.rootio
import
Branch
,
BranchMapper
MAIN_TREE_NAME
=
"
E
"
EXCLUDE_KEYS
=
[
"
AAObject
"
,
"
t
"
,
"
fBits
"
,
"
fUniqueID
"
]
# 110 MB based on the size of the largest basket found so far in km3net
BASKET_CACHE_SIZE
=
110
*
1024
**
2
BASKET_CACHE
=
uproot
.
cache
.
LRUArrayCache
(
BASKET_CACHE_SIZE
)
class
Usr
:
"""
Helper class to access AAObject `usr` stuff (only for events.usr)
"""
def
__init__
(
self
,
mapper
,
branch
,
index_chain
=
None
):
self
.
_mapper
=
mapper
self
.
_name
=
mapper
.
name
self
.
_index_chain
=
[]
if
index_chain
is
None
else
index_chain
self
.
_branch
=
branch
self
.
_usr_names
=
[]
self
.
_usr_idx_lookup
=
{}
self
.
_usr_key
=
"
usr
"
if
mapper
.
flat
else
mapper
.
key
+
"
.usr
"
self
.
_initialise
()
def
_initialise
(
self
):
try
:
self
.
_branch
[
self
.
_usr_key
]
# This will raise a KeyError in old aanet files
# which has a different strucuter and key (usr_data)
# We do not support those (yet)
except
(
KeyError
,
IndexError
):
print
(
"
The `usr` fields could not be parsed for the
'
{}
'
branch.
"
.
format
(
self
.
_name
)
)
return
self
.
_usr_names
=
self
.
_branch
[
self
.
_usr_key
+
"
_names
"
].
array
()[
0
]
self
.
_usr_idx_lookup
=
{
name
:
index
for
index
,
name
in
enumerate
(
self
.
_usr_names
)
}
data
=
self
.
_branch
[
self
.
_usr_key
].
array
()
if
self
.
_index_chain
:
data
=
unfold_indices
(
data
,
self
.
_index_chain
)
self
.
_usr_data
=
data
for
name
in
self
.
_usr_names
:
setattr
(
self
,
name
,
self
[
name
])
def
__getitem__
(
self
,
item
):
from
.definitions
import
mc_header
if
self
.
_index_chain
:
from
.tools
import
cached_property
return
unfold_indices
(
self
.
_usr_data
,
self
.
_index_chain
)[
:,
self
.
_usr_idx_lookup
[
item
]
]
else
:
return
self
.
_usr_data
[:,
self
.
_usr_idx_lookup
[
item
]]
def
keys
(
self
):
return
self
.
_usr_names
def
__str__
(
self
):
entries
=
[]
for
name
in
self
.
keys
():
entries
.
append
(
"
{}: {}
"
.
format
(
name
,
self
[
name
]))
return
"
\n
"
.
join
(
entries
)
def
__repr__
(
self
):
return
"
<{}[{}]>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
_name
)
class
OfflineReader
:
class
OfflineReader
:
...
@@ -88,7 +12,12 @@ class OfflineReader:
...
@@ -88,7 +12,12 @@ class OfflineReader:
event_path
=
"
E/Evt
"
event_path
=
"
E/Evt
"
item_name
=
"
OfflineEvent
"
item_name
=
"
OfflineEvent
"
skip_keys
=
[
"
t
"
,
"
AAObject
"
]
skip_keys
=
[
"
t
"
,
"
AAObject
"
]
aliases
=
{
"
t_s
"
:
"
t.fSec
"
,
"
t_ns
"
:
"
t.fNanoSec
"
}
aliases
=
{
"
t_s
"
:
"
t.fSec
"
,
"
t_ns
"
:
"
t.fNanoSec
"
,
"
usr
"
:
"
AAObject/usr
"
,
"
usr_names
"
:
"
AAObject/usr_names
"
,
}
special_branches
=
{
special_branches
=
{
"
hits
"
:
{
"
hits
"
:
{
"
channel_id
"
:
"
hits.channel_id
"
,
"
channel_id
"
:
"
hits.channel_id
"
,
...
...
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