Skip to content
Snippets Groups Projects
Commit 7822134f authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Cleanup

parent e93a51e1
No related branches found
No related tags found
1 merge request!21Resolve "Reduce the amount of uproot.open (to one)"
...@@ -198,18 +198,6 @@ class OfflineKeys: ...@@ -198,18 +198,6 @@ class OfflineKeys:
""" """
return [k.replace('.', '_') for k in self.events_keys] return [k.replace('.', '_') for k in self.events_keys]
@cached_property
def trigger(self):
"""trigger parameters and their index from km3net-Dataformat.
Returns
-------
dict
dictionary of trigger parameters and their index in an Offline
file.
"""
return km3io.definitions.trigger.data
class OfflineReader: class OfflineReader:
"""reader for offline ROOT files""" """reader for offline ROOT files"""
...@@ -220,7 +208,7 @@ class OfflineReader: ...@@ -220,7 +208,7 @@ class OfflineReader:
---------- ----------
file_path : path-like object file_path : path-like object
Path to the file of interest. It can be a str or any python Path to the file of interest. It can be a str or any python
path-like object that points to the file of ineterst. path-like object that points to the file.
""" """
self._file_path = file_path self._file_path = file_path
...@@ -331,7 +319,7 @@ class OfflineReader: ...@@ -331,7 +319,7 @@ class OfflineReader:
@cached_property @cached_property
def usr(self): def usr(self):
return Usr(self._file_path) return Usr(self._tree)
def get_best_reco(self): def get_best_reco(self):
"""returns the best reconstructed track fit data. The best fit is defined """returns the best reconstructed track fit data. The best fit is defined
...@@ -674,15 +662,14 @@ class OfflineReader: ...@@ -674,15 +662,14 @@ class OfflineReader:
class Usr: class Usr:
"""Helper class to access AAObject usr stuff""" """Helper class to access AAObject usr stuff"""
def __init__(self, filepath): def __init__(self, tree):
self._f = uproot.open(filepath)
# Here, we assume that every event has the same names in the same order # Here, we assume that every event has the same names in the same order
# to massively increase the performance. This needs triple check if it's # to massively increase the performance. This needs triple check if it's
# always the case; the usr-format is simply a very bad design. # always the case; the usr-format is simply a very bad design.
try: try:
self._usr_names = [ self._usr_names = [
n.decode("utf-8") n.decode("utf-8")
for n in self._f['E']['Evt']['usr_names'].array()[0] for n in tree['Evt']['usr_names'].array()[0]
] ]
except (KeyError, IndexError): # e.g. old aanet files except (KeyError, IndexError): # e.g. old aanet files
self._usr_names = [] self._usr_names = []
...@@ -691,7 +678,7 @@ class Usr: ...@@ -691,7 +678,7 @@ class Usr:
name: index name: index
for index, name in enumerate(self._usr_names) for index, name in enumerate(self._usr_names)
} }
self._usr_data = self._f['E']['Evt']['usr'].lazyarray( self._usr_data = tree['Evt']['usr'].lazyarray(
basketcache=uproot.cache.ThreadSafeArrayCache( basketcache=uproot.cache.ThreadSafeArrayCache(
BASKET_CACHE_SIZE)) BASKET_CACHE_SIZE))
for name in self._usr_names: for name in self._usr_names:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment