Skip to content

Commit

Permalink
Merge pull request #158 from cta-observatory/fix_frankenstein
Browse files Browse the repository at this point in the history
Fix telescope descriptions of frankenstein simtel files
  • Loading branch information
maxnoe authored Mar 14, 2019
2 parents fec1b82 + f54729d commit b3d3679
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions eventio/simtel/simtelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self, path, allowed_telescopes=None, skip_calibration=False):
self.mc_run_headers = []
self.corsika_inputcards = []
self.header = None
self.n_telescopes = 0
self.n_telescopes = None
self.telescope_descriptions = defaultdict(dict)
self.camera_monitorings = defaultdict(dict)
self.laser_calibrations = defaultdict(dict)
Expand All @@ -98,9 +98,12 @@ def __init__(self, path, allowed_telescopes=None, skip_calibration=False):
# read the header:
# assumption: the header is done when
# any of the objects in check is not None anymore
# and we found the telescope_descriptions of all telescopes
check = []
while not any(o for o in check):
found_all_telescopes = False
while not (any(o for o in check) and found_all_telescopes):
self.next_low_level()

check = [
self.current_mc_shower,
self.current_array_event,
Expand All @@ -109,7 +112,13 @@ def __init__(self, path, allowed_telescopes=None, skip_calibration=False):
self.camera_monitorings,
]

self._first_event_byte = self.tell()
# check if we found all the descriptions of all telescopes
if self.n_telescopes is not None:
found = sum(
len(t) == len(telescope_descriptions_types)
for t in self.telescope_descriptions.values()
)
found_all_telescopes = found == self.n_telescopes

def __iter__(self):
return self.iter_array_events()
Expand Down Expand Up @@ -173,7 +182,6 @@ def next_low_level(self):
)

def iter_mc_events(self):
self._next_header_pos = self._first_event_byte
while True:
try:
next_event = self.try_build_mc_event()
Expand All @@ -194,7 +202,6 @@ def try_build_mc_event(self):
self.next_low_level()

def iter_array_events(self):
self._next_header_pos = self._first_event_byte
while True:

next_event = self.try_build_event()
Expand Down
Binary file added tests/resources/gamma_merged.simtel.gz
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/simtel/test_simtelfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# a file
prod4_zst_path = 'tests/resources/gamma_20deg_0deg_run102___cta-prod4-sst-1m_desert-2150m-Paranal-sst-1m.simtel.zst'
calib_path = 'tests/resources/calib_events.simtel.gz'
frankenstein_path = 'tests/resources/gamma_merged.simtel.gz'


test_paths = [prod2_path, prod3_path, prod4_path]
Expand Down Expand Up @@ -176,3 +177,8 @@ def test_skip_calibration_events():
if event['type'] == 'calibration':
i += 1
assert i == 0


def test_frankenstein():
with SimTelFile(frankenstein_path) as f:
assert len(f.telescope_descriptions) == f.n_telescopes

0 comments on commit b3d3679

Please sign in to comment.