From 7a457b14c9ccb7632d9da275d422f25bffcec2f3 Mon Sep 17 00:00:00 2001 From: Tamas Gal <himself@tamasgal.com> Date: Wed, 9 Feb 2022 15:39:13 +0100 Subject: [PATCH] Add length to SummarysliceReader --- km3io/online.py | 3 +++ tests/test_online.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/km3io/online.py b/km3io/online.py index 37d0eea..59e2fee 100644 --- a/km3io/online.py +++ b/km3io/online.py @@ -60,6 +60,9 @@ class SummarysliceReader: def __next__(self): return next(self._summaryslices) + def __len__(self): + return int(np.ceil(len(self._branch) / self._step_size)) + @nb.vectorize( [nb.int32(nb.int8), nb.int32(nb.int16), nb.int32(nb.int32), nb.int32(nb.int64)] diff --git a/tests/test_online.py b/tests/test_online.py index 70a84ff..c86ab49 100644 --- a/tests/test_online.py +++ b/tests/test_online.py @@ -739,6 +739,14 @@ class TestSummarysliceReader(unittest.TestCase): def test_init(self): sr = SummarysliceReader(data_path("online/km3net_online.root")) + def test_length(self): + sr = SummarysliceReader(data_path("online/km3net_online.root")) + assert 1 == len(sr) + sr = SummarysliceReader(data_path("online/km3net_online.root"), step_size=2) + assert 2 == len(sr) + sr = SummarysliceReader(data_path("online/km3net_online.root"), step_size=3) + assert 1 == len(sr) + def test_iterate_with_step_size_one(self): sr = SummarysliceReader(data_path("online/km3net_online.root"), step_size=1) i = 0 -- GitLab