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
f05051af
Commit
f05051af
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Finalise branchmapper prototype
parent
9217b6c9
No related branches found
No related tags found
1 merge request
!27
Refactor offline I/O
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
km3io/offline.py
+46
-10
46 additions, 10 deletions
km3io/offline.py
with
46 additions
and
10 deletions
km3io/offline.py
+
46
−
10
View file @
f05051af
...
...
@@ -26,7 +26,8 @@ BRANCH_MAPS = [
BranchMapper
(
"
mc_tracks
"
,
"
mc_trks
"
,
{},
[
'
mc_trks.usr_data
'
,
'
mc_trks.usr
'
],
{},
_nested_mapper
),
BranchMapper
(
"
hits
"
,
"
hits
"
,
{},
[
'
hits.usr
'
],
{},
_nested_mapper
),
BranchMapper
(
"
mc_hits
"
,
"
mc_hits
"
,
{},
[
'
mc_hits.usr
'
],
{},
BranchMapper
(
"
mc_hits
"
,
"
mc_hits
"
,
{},
[
'
mc_hits.usr
'
,
'
mc_hits.dom_id
'
,
'
mc_hits.channel_id
'
],
{},
_nested_mapper
),
BranchMapper
(
"
events
"
,
"
Evt
"
,
{
'
t_sec
'
:
'
t.fSec
'
,
...
...
@@ -81,9 +82,8 @@ class OfflineReader:
self
.
_data
=
data
for
mapper
in
BRANCH_MAPS
:
setattr
(
self
,
mapper
.
name
,
BranchElement
(
self
.
_tree
,
mapper
=
mapper
,
index
=
self
.
_index
))
setattr
(
self
,
mapper
.
name
,
Branch
(
self
.
_tree
,
mapper
=
mapper
,
index
=
self
.
_index
))
@classmethod
def
from_index
(
cls
,
source
,
index
):
...
...
@@ -543,8 +543,8 @@ class Header:
return
"
\n
"
.
join
(
lines
)
class
Branch
Element
:
"""
w
ra
pper for offline track
s
"""
class
Branch
:
"""
B
ra
nch accessor clas
s
"""
def
__init__
(
self
,
tree
,
mapper
,
index
=
slice
(
None
)):
self
.
_tree
=
tree
self
.
_mapper
=
mapper
...
...
@@ -581,10 +581,14 @@ class BranchElement:
if
isinstance
(
item
,
slice
):
return
self
.
__class__
(
self
.
_tree
,
self
.
_mapper
,
index
=
item
)
if
isinstance
(
item
,
int
):
return
{
key
:
self
.
_branch
[
self
.
_keymap
[
key
]].
array
()[
self
.
_index
,
item
]
for
key
in
self
.
keys
()
}
return
BranchElement
(
self
.
_mapper
.
name
,
{
key
:
self
.
_branch
[
self
.
_keymap
[
key
]].
array
()[
self
.
_index
,
item
]
for
key
in
self
.
keys
()
})
if
isinstance
(
item
,
tuple
):
return
self
[
item
[
0
]][
item
[
1
]]
return
self
.
_branch
[
self
.
_keymap
[
item
]].
lazyarray
(
basketcache
=
uproot
.
cache
.
ThreadSafeArrayCache
(
BASKET_CACHE_SIZE
))[
self
.
_index
]
...
...
@@ -603,3 +607,35 @@ class BranchElement:
return
"
<{}[{}]: {} parsed elements>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
_mapper
.
name
,
len
(
self
))
class
BranchElement
:
"""
Represents a single branch element
Parameters
----------
name: str
The name of the branch
dct: dict (keys=attributes, values=arrays of values)
The data
index: slice
The slice mask to be applied to the sub-arrays
"""
def
__init__
(
self
,
name
,
dct
,
index
=
slice
(
None
)):
self
.
_dct
=
dct
self
.
_name
=
name
self
.
_index
=
index
self
.
ItemConstructor
=
namedtuple
(
self
.
_name
[:
-
1
],
dct
.
keys
())
for
key
,
values
in
dct
.
items
():
setattr
(
self
,
key
,
values
[
index
])
def
__getitem__
(
self
,
item
):
if
isinstance
(
item
,
slice
):
return
self
.
__class__
(
self
.
_name
,
self
.
_dct
,
index
=
item
)
if
isinstance
(
item
,
int
):
return
self
.
ItemConstructor
(
**
{
k
:
v
[
self
.
_index
][
item
]
for
k
,
v
in
self
.
_dct
.
items
()})
def
__repr__
(
self
):
return
"
<{}[{}]>
"
.
format
(
self
.
__class__
.
__name__
,
self
.
_name
)
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