From 98b71eed91748e0caa5419ef455e275666bf8b6e Mon Sep 17 00:00:00 2001 From: Morit Lotze <lotzemoritz@gmail.com> Date: Sat, 11 Aug 2018 15:21:07 +0200 Subject: [PATCH 1/3] ENH Use history for trackname if available, instead of generic --- km3pipe/io/aanet.py | 71 ++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/km3pipe/io/aanet.py b/km3pipe/io/aanet.py index 54c2136b6..5d3f1b882 100644 --- a/km3pipe/io/aanet.py +++ b/km3pipe/io/aanet.py @@ -60,8 +60,8 @@ RECO2NUM = { 'JMUONGANDALF': 3, 'JMUONENERGY': 4, 'JMUONSTART': 5, - 'JLINEFIT': 6, # JMUONEND @ 10.1, JLINEFIT @ trunk - 'LineFit': 7, # 10.1 artifact, REMOVE IN FUTURE + 'JLINEFIT': 6, # JMUONEND @ 10.1, JLINEFIT @ trunk + 'LineFit': 7, # 10.1 artifact, REMOVE IN FUTURE 'JMUONEND': 99, 'JSHOWERBEGIN': 100, 'JSHOWERPREFIT': 101, @@ -76,7 +76,6 @@ RECO2NUM = { 'JMCEVT': 1004, 'JUSEREND': 1099, 'KM3DeltaPos': 10000, - } FITINF2NAME = {v: k for k, v in FITINF2NUM.items()} @@ -195,38 +194,36 @@ class AanetPump(Pump): out = defaultdict(list) for i, trk in enumerate(tracks): self.log.debug('Reading Track #{}...'.format(i)) + trk_dict = self._read_track(trk) + # set name + h5loc later, if the name is not available, we need + # the dtype to make a new name + tab = Table(trk_dict) + trk_type = trk.rec_type - # THIS DOES NOT WORK! DTYPE DEPENDS ON FULL HISTORY - # # hack-ish: rec type is the last entry in the history - # if trk_type == 4000: - # # iterating empty ROOT vector causes segfaults! - # if len(trk.rec_stages) == 0: - # pass - # else: - # trk_type = trk.rec_stages[-1] - # # after that, if the tracktype is still 4000, just - # enumerate it as another generic track try: trk_name = RECO2NAME[trk_type] except KeyError: trk_type = AANET_RECTYPE_PLACEHOLDER - trk_dict = self._read_track(trk) - tab = Table( - trk_dict, - h5loc='/reco/{}'.format(trk_name.lower()), - name=trk_name - ) if trk_type == AANET_RECTYPE_PLACEHOLDER: - self.log.info( - "Unknown Reconstruction type! Setting to 'GENERIC_TRACK_#'" - ) - trk_name = self._handle_generic(tab.dtype) - tab.name = trk_name - tab.h5loc = '/reco/{}'.format(trk_name.lower()) - # print(RECO2NAME[trk_type], - # [RECO2NAME[k] for k in trk.rec_stages], - # tab.dtype.names, - # ) + # if we have a history available but no name (because JEvt.cc), + # then use the concatenated history as the name. + # If that is not available, enumerate the tracks by their + # dtypes (since they have no other tagging) + if len(trk.rec_stages) == 0: + self.log.info( + "Unknown Reconstruction type & no history available!" + ) + trk_name = self._handle_generic(tab.dtype) + else: + self.log.info( + "Unknown Reconstruction type! Using history..." + ) + trk_name = '__'.join([ + RECO2NAME[k] for k in trk.rec_stages[::-1] + ]) + + tab.name = trk_name + tab.h5loc = '/reco/{}'.format(trk_name.lower()) out[trk_name].append(tab) log.info("Merging tracks into table...") for key in out: @@ -391,7 +388,7 @@ class AanetPump(Pump): fields.append(field_name) values.append(field_value) try: - _ = float(field_value) # noqa + _ = float(field_value) # noqa types.append('f4') except ValueError: types.append('a{}'.format(len(field_value))) @@ -399,12 +396,14 @@ class AanetPump(Pump): tab_dict['field_names'].append(' '.join(fields)) tab_dict['field_values'].append(' '.join(values)) tab_dict['dtype'].append(' '.join(types)) - log.debug("{}: {} {} {}".format( - tab_dict['parameter'][-1], - tab_dict['field_names'][-1], - tab_dict['field_values'][-1], - tab_dict['dtype'][-1], - )) + log.debug( + "{}: {} {} {}".format( + tab_dict['parameter'][-1], + tab_dict['field_names'][-1], + tab_dict['field_values'][-1], + tab_dict['dtype'][-1], + ) + ) return Table( tab_dict, h5loc='/raw_header', name='RawHeader', h5singleton=True ) -- GitLab From 5542005d289afd0b06b3b203f67bdca0adf69e19 Mon Sep 17 00:00:00 2001 From: Moritz Lotze <lotzemoritz@gmail.com> Date: Sat, 11 Aug 2018 15:40:56 +0200 Subject: [PATCH 2/3] FIX avoid root segfaulting when iterating in reverse order --- km3pipe/io/aanet.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/km3pipe/io/aanet.py b/km3pipe/io/aanet.py index 5d3f1b882..a6a90ec2a 100644 --- a/km3pipe/io/aanet.py +++ b/km3pipe/io/aanet.py @@ -218,9 +218,12 @@ class AanetPump(Pump): self.log.info( "Unknown Reconstruction type! Using history..." ) + # iteration in reverse order segfaults, whyever... + stages = [k for k in trk.rec_stages] trk_name = '__'.join([ - RECO2NAME[k] for k in trk.rec_stages[::-1] + RECO2NAME[k] for k in stages[::-1] ]) + # trk_name = 'JHIST__' + trk_name tab.name = trk_name tab.h5loc = '/reco/{}'.format(trk_name.lower()) @@ -248,7 +251,6 @@ class AanetPump(Pump): # both A and B. # This needs to be fixed upstream obviously, so here we should just make # noise about it - dtypes_avail = {} def _handle_generic(self, dt): pref = "GENERIC_TRACK" -- GitLab From 0088d91f61242fd5d95375e45d413181b16e8f12 Mon Sep 17 00:00:00 2001 From: Morit Lotze <lotzemoritz@gmail.com> Date: Sat, 11 Aug 2018 15:41:06 +0200 Subject: [PATCH 3/3] STL fix whitespace of comments --- km3pipe/io/aanet.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/km3pipe/io/aanet.py b/km3pipe/io/aanet.py index 5d3f1b882..46672584d 100644 --- a/km3pipe/io/aanet.py +++ b/km3pipe/io/aanet.py @@ -60,8 +60,10 @@ RECO2NUM = { 'JMUONGANDALF': 3, 'JMUONENERGY': 4, 'JMUONSTART': 5, - 'JLINEFIT': 6, # JMUONEND @ 10.1, JLINEFIT @ trunk - 'LineFit': 7, # 10.1 artifact, REMOVE IN FUTURE + # JMUONEND @ 10.1, JLINEFIT @ trunk + 'JLINEFIT': 6, + # 10.1 artifact, REMOVE IN FUTURE + 'LineFit': 7, 'JMUONEND': 99, 'JSHOWERBEGIN': 100, 'JSHOWERPREFIT': 101, @@ -120,7 +122,7 @@ class AanetPump(Pump): """Create a blob generator.""" # pylint: disable:F0401,W0612 import aa # pylint: disablF0401 # noqa - from ROOT import EventFile # pylint: disablF0401 + from ROOT import EventFile # pylint: disable F0401 filename = self.filename log.info("Reading from file: {0}".format(filename)) -- GitLab