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
9343b7ae
Commit
9343b7ae
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Prototype for rearranging branches
parent
24894e8f
No related branches found
Branches containing commit
No related tags found
2 merge requests
!24
Refactor offline
,
!22
WIP: Slicing and refactoring offline
Pipeline
#9302
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/offline.py
+43
-4
43 additions, 4 deletions
km3io/offline.py
with
43 additions
and
4 deletions
km3io/offline.py
+
43
−
4
View file @
9343b7ae
...
...
@@ -41,6 +41,36 @@ BRANCH_MAPS = [
},
lambda
a
:
a
,
True
),
]
SUBBRANCH_MAPS
=
[
BranchMapper
(
"
tracks
"
,
"
trks
"
,
{},
[
'
trks.usr_data
'
,
'
trks.usr
'
],
{},
_nested_mapper
,
False
),
BranchMapper
(
"
mc_tracks
"
,
"
mc_trks
"
,
{},
[
'
mc_trks.usr_data
'
,
'
mc_trks.usr
'
],
{},
_nested_mapper
,
False
),
BranchMapper
(
"
hits
"
,
"
hits
"
,
{},
[
'
hits.usr
'
],
{},
_nested_mapper
,
False
),
BranchMapper
(
"
mc_hits
"
,
"
mc_hits
"
,
{},
[
'
mc_hits.usr
'
,
'
mc_hits.dom_id
'
,
'
mc_hits.channel_id
'
],
{},
_nested_mapper
,
False
),
BranchMapper
(
"
events
"
,
"
Evt
"
,
{
'
t_sec
'
:
'
t.fSec
'
,
'
t_ns
'
:
'
t.fNanoSec
'
},
[],
{
'
n_hits
'
:
'
hits
'
,
'
n_mc_hits
'
:
'
mc_hits
'
,
'
n_tracks
'
:
'
trks
'
,
'
n_mc_tracks
'
:
'
mc_trks
'
},
lambda
a
:
a
,
True
),
]
EVENTS_MAP
=
BranchMapper
(
"
events
"
,
"
Evt
"
,
{
'
t_sec
'
:
'
t.fSec
'
,
'
t_ns
'
:
'
t.fNanoSec
'
},
[],
{
'
n_hits
'
:
'
hits
'
,
'
n_mc_hits
'
:
'
mc_hits
'
,
'
n_tracks
'
:
'
trks
'
,
'
n_mc_tracks
'
:
'
mc_trks
'
},
lambda
a
:
a
,
True
)
class
cached_property
:
"""
A simple cache decorator for properties.
"""
...
...
@@ -83,6 +113,10 @@ class OfflineReader:
setattr
(
self
,
mapper
.
name
,
Branch
(
self
.
_tree
,
mapper
=
mapper
,
index
=
self
.
_index
))
@cached_property
def
_events
(
self
):
return
Branch
(
self
.
_tree
,
mapper
=
EVENTS_MAP
,
index
=
self
.
_index
,
subbranches
=
SUBBRANCH_MAPS
)
@classmethod
def
from_index
(
cls
,
source
,
index
):
"""
Create an instance with a subtree of a given index
...
...
@@ -554,15 +588,20 @@ class Header:
class
Branch
:
"""
Branch accessor class
"""
def
__init__
(
self
,
tree
,
mapper
,
index
=
None
):
def
__init__
(
self
,
tree
,
mapper
,
index
=
None
,
subbranches
=
[]
):
self
.
_tree
=
tree
self
.
_mapper
=
mapper
self
.
_index
=
index
self
.
_keymap
=
None
self
.
_branch
=
tree
[
mapper
.
key
]
self
.
_subbranches
=
subbranches
self
.
_initialise_keys
()
for
mapper
in
subbranches
:
setattr
(
self
,
mapper
.
name
,
Branch
(
self
.
_tree
,
mapper
=
mapper
,
index
=
self
.
_index
))
def
_initialise_keys
(
self
):
"""
Create the keymap and instance attributes
"""
keys
=
set
(
k
.
decode
(
'
utf-8
'
)
for
k
in
self
.
_branch
.
keys
())
-
set
(
...
...
@@ -592,7 +631,7 @@ class Branch:
def
__getitem__
(
self
,
item
):
"""
Slicing magic a la numpy
"""
if
isinstance
(
item
,
slice
):
return
self
.
__class__
(
self
.
_tree
,
self
.
_mapper
,
index
=
item
)
return
self
.
__class__
(
self
.
_tree
,
self
.
_mapper
,
index
=
item
,
subbranches
=
self
.
_subbranches
)
if
isinstance
(
item
,
int
):
# A bit ugly, but whatever works
if
self
.
_mapper
.
flat
:
...
...
@@ -636,7 +675,7 @@ class Branch:
out
=
out
[
self
.
_index
]
return
out
return
self
.
__class__
(
self
.
_tree
,
self
.
_mapper
,
index
=
np
.
array
(
item
))
return
self
.
__class__
(
self
.
_tree
,
self
.
_mapper
,
index
=
np
.
array
(
item
)
,
subbranches
=
self
.
_subbranches
)
def
__len__
(
self
):
if
self
.
_index
is
None
:
...
...
@@ -666,7 +705,7 @@ class BranchElement:
index: slice
The slice mask to be applied to the sub-arrays
"""
def
__init__
(
self
,
name
,
dct
,
index
=
None
):
def
__init__
(
self
,
name
,
dct
,
index
=
None
,
subbranches
=
[]
):
self
.
_dct
=
dct
self
.
_name
=
name
self
.
_index
=
index
...
...
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