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
30d68c73
Commit
30d68c73
authored
4 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
make yapf
parent
96d49876
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!27
Refactor offline I/O
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
km3io/offline.py
+5
-3
5 additions, 3 deletions
km3io/offline.py
km3io/tools.py
+9
-6
9 additions, 6 deletions
km3io/tools.py
tests/test_offline.py
+2
-2
2 additions, 2 deletions
tests/test_offline.py
tests/test_tools.py
+2
-1
2 additions, 1 deletion
tests/test_tools.py
with
18 additions
and
12 deletions
km3io/offline.py
+
5
−
3
View file @
30d68c73
...
...
@@ -151,7 +151,9 @@ class Usr:
def
__getitem_flat__
(
self
,
item
):
if
self
.
_index_chain
:
return
_unfold_indices
(
self
.
_usr_data
,
self
.
_index_chain
)[:,
self
.
_usr_idx_lookup
[
item
]]
return
_unfold_indices
(
self
.
_usr_data
,
self
.
_index_chain
)[:,
self
.
_usr_idx_lookup
[
item
]]
else
:
return
self
.
_usr_data
[:,
self
.
_usr_idx_lookup
[
item
]]
...
...
@@ -197,8 +199,8 @@ class OfflineReader:
def
events
(
self
):
"""
The `E` branch, containing all offline events.
"""
return
OfflineBranch
(
self
.
_tree
,
mapper
=
EVENTS_MAP
,
subbranchmaps
=
SUBBRANCH_MAPS
)
mapper
=
EVENTS_MAP
,
subbranchmaps
=
SUBBRANCH_MAPS
)
@cached_property
def
header
(
self
):
...
...
This diff is collapsed.
Click to expand it.
km3io/tools.py
+
9
−
6
View file @
30d68c73
...
...
@@ -26,9 +26,10 @@ def _unfold_indices(obj, indices):
try
:
obj
=
obj
[
idx
]
except
IndexError
:
print
(
"
IndexError while accessing an item from
'
{}
'
at depth {} ({})
"
"
using the index chain {}
"
.
format
(
repr
(
original_obj
),
depth
,
idx
,
indices
))
print
(
"
IndexError while accessing an item from
'
{}
'
at depth {} ({})
"
"
using the index chain {}
"
.
format
(
repr
(
original_obj
),
depth
,
idx
,
indices
))
raise
return
obj
...
...
@@ -62,7 +63,7 @@ class Branch:
if
subbranchmaps
is
not
None
:
for
mapper
in
subbranchmaps
:
subbranch
=
self
.
__class__
(
self
.
_tree
,
mapper
=
mapper
,
mapper
=
mapper
,
index_chain
=
self
.
_index_chain
)
self
.
_subbranches
.
append
(
subbranch
)
for
subbranch
in
self
.
_subbranches
:
...
...
@@ -129,8 +130,10 @@ class Branch:
elif
isinstance
(
self
.
_index_chain
[
-
1
],
int
):
return
1
else
:
return
len
(
_unfold_indices
(
self
.
_branch
[
self
.
_keymap
[
'
id
'
]].
lazyarray
(
basketcache
=
BASKET_CACHE
),
self
.
_index_chain
))
return
len
(
_unfold_indices
(
self
.
_branch
[
self
.
_keymap
[
'
id
'
]].
lazyarray
(
basketcache
=
BASKET_CACHE
),
self
.
_index_chain
))
def
__str__
(
self
):
return
"
Number of elements: {}
"
.
format
(
len
(
self
.
_branch
))
...
...
This diff is collapsed.
Click to expand it.
tests/test_offline.py
+
2
−
2
View file @
30d68c73
...
...
@@ -154,7 +154,8 @@ class TestOfflineEvents(unittest.TestCase):
def
test_index_chaining
(
self
):
assert
np
.
allclose
(
self
.
events
[
3
:
5
].
n_hits
,
self
.
events
.
n_hits
[
3
:
5
])
assert
np
.
allclose
(
self
.
events
[
3
:
5
][
0
].
n_hits
,
self
.
events
.
n_hits
[
3
:
5
][
0
])
assert
np
.
allclose
(
self
.
events
[
3
:
5
][
0
].
n_hits
,
self
.
events
.
n_hits
[
3
:
5
][
0
])
def
test_str
(
self
):
assert
str
(
self
.
n_events
)
in
str
(
self
.
events
)
...
...
@@ -344,7 +345,6 @@ class TestUsr(unittest.TestCase):
self
.
f
.
events
.
usr
.
DeltaPosZ
)
class
TestNestedMapper
(
unittest
.
TestCase
):
def
test_nested_mapper
(
self
):
self
.
assertEqual
(
'
pos_x
'
,
_nested_mapper
(
"
trks.pos.x
"
))
This diff is collapsed.
Click to expand it.
tests/test_tools.py
+
2
−
1
View file @
30d68c73
...
...
@@ -30,7 +30,8 @@ class TestUnfoldIndices(unittest.TestCase):
assert
data
[
indices
[
0
]][
indices
[
1
]]
==
_unfold_indices
(
data
,
indices
)
indices
=
[
slice
(
1
,
9
,
2
),
slice
(
1
,
4
),
2
]
assert
data
[
indices
[
0
]][
indices
[
1
]][
indices
[
2
]]
==
_unfold_indices
(
data
,
indices
)
assert
data
[
indices
[
0
]][
indices
[
1
]][
indices
[
2
]]
==
_unfold_indices
(
data
,
indices
)
def
test_unfold_indices_raises_index_error
(
self
):
data
=
range
(
10
)
...
...
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