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
fcca3704
Commit
fcca3704
authored
4 years ago
by
Tamas Gal
Browse files
Options
Downloads
Patches
Plain Diff
Add iteration
parent
fe93cf9b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!27
Refactor offline I/O
Pipeline
#10194
passed with warnings
4 years ago
Stage: test
Stage: coverage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
km3io/tools.py
+17
-1
17 additions, 1 deletion
km3io/tools.py
tests/test_offline.py
+10
-0
10 additions, 0 deletions
tests/test_offline.py
with
27 additions
and
1 deletion
km3io/tools.py
+
17
−
1
View file @
fcca3704
...
...
@@ -55,6 +55,8 @@ class Branch:
self
.
_subbranches
=
[]
self
.
_subbranchmaps
=
subbranchmaps
self
.
_iterator_index
=
0
if
keymap
is
None
:
self
.
_initialise_keys
()
#
else
:
...
...
@@ -125,8 +127,22 @@ class Branch:
self
.
_branch
[
self
.
_keymap
[
'
id
'
]].
lazyarray
(
basketcache
=
BASKET_CACHE
),
self
.
_index_chain
))
def
__iter__
(
self
):
self
.
_iterator_index
=
0
return
self
def
__next__
(
self
):
idx
=
self
.
_iterator_index
self
.
_iterator_index
+=
1
if
idx
>=
len
(
self
):
raise
StopIteration
return
self
[
idx
]
def
__str__
(
self
):
return
"
Number of elements: {}
"
.
format
(
len
(
self
.
_branch
))
length
=
len
(
self
)
return
"
{} ({}) with {} element{}
"
.
format
(
self
.
__class__
.
__name__
,
self
.
_mapper
.
name
,
length
,
'
s
'
if
length
>
1
else
''
)
def
__repr__
(
self
):
length
=
len
(
self
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_offline.py
+
10
−
0
View file @
fcca3704
...
...
@@ -161,6 +161,16 @@ class TestOfflineEvents(unittest.TestCase):
assert
np
.
allclose
(
self
.
events
.
hits
[
3
:
5
][
1
][
4
].
dom_id
,
self
.
events
[
3
:
5
][
1
][
4
].
hits
.
dom_id
)
def
test_iteration
(
self
):
i
=
0
for
event
in
self
.
events
:
i
+=
1
assert
10
==
i
def
test_iteration_2
(
self
):
n_hits
=
[
e
.
n_hits
for
e
in
self
.
events
]
assert
np
.
allclose
(
n_hits
,
self
.
events
.
n_hits
)
def
test_str
(
self
):
assert
str
(
self
.
n_events
)
in
str
(
self
.
events
)
...
...
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