Skip to content

Commit 56ccc62

Browse files
committed
MultiFile: Return stream from which event was loaded
1 parent 1be1790 commit 56ccc62

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/ctapipe_io_lst/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def _generator(self):
612612
mon = self.initialize_mon_container()
613613

614614
# loop on events
615-
for count, zfits_event in enumerate(self.multi_file):
615+
for count, (_, zfits_event) in enumerate(self.multi_file):
616616
# Skip "empty" events that occur at the end of some runs
617617
if zfits_event.event_id == 0:
618618
self.log.warning('Event with event_id=0 found, skipping')

src/ctapipe_io_lst/multifiles.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def _load_next_subrun(self, stream):
146146

147147
if stream is None:
148148
path = self.path
149+
stream = self.file_info.stream
149150
else:
150151
self.current_subrun[stream] += 1
151152

@@ -235,4 +236,4 @@ def __next__(self):
235236
except FileNotFoundError:
236237
pass
237238

238-
return event
239+
return stream, event

src/ctapipe_io_lst/tests/test_multifile.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import pytest
2-
from pathlib import Path
31
import os
2+
from pathlib import Path
43

54
test_data = Path(os.getenv('LSTCHAIN_TEST_DATA', 'test_data')).absolute()
65
test_r0_dir = test_data / 'multifile_test'
@@ -16,9 +15,10 @@ def test_multifile_streams():
1615
assert multi_files.dvr_applied is False
1716

1817
event_count = 0
19-
for event in multi_files:
18+
for stream, event in multi_files:
2019
event_count += 1
2120
assert event.event_id == event_count
21+
assert stream in (1, 2, 3, 4)
2222

2323
assert event_count == 40
2424

@@ -32,9 +32,10 @@ def test_multifile_all_subruns():
3232
assert multi_files.n_open_files == 4
3333

3434
event_count = 0
35-
for event in multi_files:
35+
for stream, event in multi_files:
3636
event_count += 1
3737
assert event.event_id == event_count
38+
assert stream in (1, 2, 3, 4)
3839

3940
assert event_count == 200
4041

@@ -48,9 +49,10 @@ def test_multifile_last_subrun():
4849
assert multi_files.n_open_files == 4
4950

5051
event_count = 80
51-
for event in multi_files:
52+
for stream, event in multi_files:
5253
event_count += 1
5354
assert event.event_id == event_count
55+
assert stream in (1, 2, 3, 4)
5456

5557
assert event_count == 200
5658

@@ -59,9 +61,10 @@ def test_multifile_last_subrun():
5961
assert multi_files.n_open_files == 4
6062

6163
event_count = 80
62-
for event in multi_files:
64+
for stream, event in multi_files:
6365
event_count += 1
6466
assert event.event_id == event_count
67+
assert stream in (1, 2, 3, 4)
6568

6669
assert event_count == 160
6770

@@ -71,21 +74,25 @@ def test_multifile_single():
7174

7275
path = test_r0_dir / 'LST-1.3.Run00001.0002.fits.fz'
7376

77+
# only load multiple streams if stream 1 is passed
7478
with MultiFiles(path, all_streams=True, all_subruns=True) as multi_files:
7579
assert multi_files.n_open_files == 1
7680

7781
event_count = 79
78-
for event in multi_files:
82+
for stream, event in multi_files:
7983
event_count += 4
8084
assert event.event_id == event_count
85+
assert stream == 3
8186
assert event_count == 119
8287

88+
# explicitly turn multiple streams off
8389
path = test_r0_dir / 'LST-1.1.Run00001.0000.fits.fz'
8490
with MultiFiles(path, all_streams=False, all_subruns=False) as multi_files:
8591
assert multi_files.n_open_files == 1
8692

8793
event_count = -3
88-
for event in multi_files:
94+
for stream, event in multi_files:
8995
event_count += 4
9096
assert event.event_id == event_count
97+
assert stream == 1
9198
assert event_count == 37

0 commit comments

Comments
 (0)