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
41e151ac
Commit
41e151ac
authored
5 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Allow dict-key access to attributes
parent
c2c476a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!27
Refactor offline I/O
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
km3io/offline.py
+11
-5
11 additions, 5 deletions
km3io/offline.py
tests/test_offline.py
+4
-4
4 additions, 4 deletions
tests/test_offline.py
with
15 additions
and
9 deletions
km3io/offline.py
+
11
−
5
View file @
41e151ac
...
...
@@ -266,14 +266,17 @@ class Branch:
return
object
.
__getattribute__
(
self
,
attr
)
if
attr
in
self
.
_keymap
.
keys
():
# intercept branch key lookups
out
=
self
.
_branch
[
self
.
_keymap
[
attr
]].
lazyarray
(
basketcache
=
BASKET_CACHE
)
if
self
.
_index
is
not
None
:
out
=
out
[
self
.
_index
]
return
out
return
self
.
__getkey__
(
attr
)
return
object
.
__getattribute__
(
self
,
attr
)
def
__getkey__
(
self
,
key
):
out
=
self
.
_branch
[
self
.
_keymap
[
key
]].
lazyarray
(
basketcache
=
BASKET_CACHE
)
if
self
.
_index
is
not
None
:
out
=
out
[
self
.
_index
]
return
out
def
__getitem__
(
self
,
item
):
"""
Slicing magic
"""
if
isinstance
(
item
,
(
int
,
slice
)):
...
...
@@ -286,6 +289,9 @@ class Branch:
if
isinstance
(
item
,
tuple
):
return
self
[
item
[
0
]][
item
[
1
]]
if
isinstance
(
item
,
str
):
return
self
.
__getkey__
(
item
)
return
self
.
__class__
(
self
.
_tree
,
self
.
_mapper
,
index
=
np
.
array
(
item
),
...
...
This diff is collapsed.
Click to expand it.
tests/test_offline.py
+
4
−
4
View file @
41e151ac
...
...
@@ -63,10 +63,10 @@ class TestOfflineEvents(unittest.TestCase):
self
.
assertListEqual
(
self
.
t_ns
,
list
(
self
.
events
.
t_ns
))
def
test_keys
(
self
):
self
.
assert
ListEqual
(
self
.
n_hits
,
list
(
self
.
events
[
'
n_hits
'
])
)
self
.
assert
ListEqual
(
self
.
n_tracks
,
list
(
self
.
events
[
'
n_tracks
'
])
)
self
.
assert
ListEqual
(
self
.
t_sec
,
list
(
self
.
events
[
'
t_sec
'
])
)
self
.
assert
ListEqual
(
self
.
t_ns
,
list
(
self
.
events
[
'
t_ns
'
])
)
assert
np
.
allclose
(
self
.
n_hits
,
self
.
events
[
'
n_hits
'
])
assert
np
.
allclose
(
self
.
n_tracks
,
self
.
events
[
'
n_tracks
'
])
assert
np
.
allclose
(
self
.
t_sec
,
self
.
events
[
'
t_sec
'
])
assert
np
.
allclose
(
self
.
t_ns
,
self
.
events
[
'
t_ns
'
])
def
test_slicing
(
self
):
s
=
slice
(
2
,
8
,
2
)
...
...
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