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

First fix of usr

parent 9149c7d1
No related branches found
No related tags found
1 merge request!27Refactor offline I/O
...@@ -123,29 +123,33 @@ class OfflineReader: ...@@ -123,29 +123,33 @@ class OfflineReader:
class Usr: class Usr:
"""Helper class to access AAObject `usr`` stuff""" """Helper class to access AAObject `usr`` stuff"""
def __init__(self, name, tree, index=None): def __init__(self, mapper, tree, index=None):
# 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 # to massively increase the performance. This needs triple check if
# it's always the case; the usr-format is simply a very bad design. # it's always the case; the usr-format is simply a very bad design.
self._name = name self._name = mapper.key
self._index = index
try: try:
tree['usr'] # This will raise a KeyError in old aanet files tree[mapper.key +
'.usr'] # This will raise a KeyError in old aanet files
# which has a different strucuter and key (usr_data) # which has a different strucuter and key (usr_data)
# We do not support those... # We do not support those...
self._usr_names = [ self._usr_names = [
n.decode("utf-8") for n in tree['usr_names'].lazyarray( n.decode("utf-8")
for n in tree[mapper.key + '.usr_names'].lazyarray(
basketcache=BASKET_CACHE)[0] basketcache=BASKET_CACHE)[0]
] ]
except (KeyError, IndexError): # e.g. old aanet files except (KeyError, IndexError): # e.g. old aanet files
print("The `usr` fields could not be parsed for the '{}' branch." print("The `usr` fields could not be parsed for the '{}' branch.".
.format(name)) format(self._name))
self._usr_names = [] self._usr_names = []
else: else:
self._usr_idx_lookup = { self._usr_idx_lookup = {
name: index name: index
for index, name in enumerate(self._usr_names) for index, name in enumerate(self._usr_names)
} }
data = tree['usr'].lazyarray(basketcache=BASKET_CACHE) data = tree[mapper.key +
'.usr'].lazyarray(basketcache=BASKET_CACHE)
if index is not None: if index is not None:
data = data[index] data = data[index]
self._usr_data = data self._usr_data = data
...@@ -153,7 +157,10 @@ class Usr: ...@@ -153,7 +157,10 @@ class Usr:
setattr(self, name, self[name]) setattr(self, name, self[name])
def __getitem__(self, item): def __getitem__(self, item):
return self._usr_data[:, self._usr_idx_lookup[item]] if self._index is not None:
return self._usr_data[self._index][:, self._usr_idx_lookup[item]]
else:
return self._usr_data[:, self._usr_idx_lookup[item]]
def keys(self): def keys(self):
return self._usr_names return self._usr_names
...@@ -259,7 +266,7 @@ class Branch: ...@@ -259,7 +266,7 @@ class Branch:
@cached_property @cached_property
def usr(self): def usr(self):
return Usr(self._mapper.name, self._branch, index=self._index) return Usr(self._mapper, self._branch, index=self._index)
def __getattribute__(self, attr): def __getattribute__(self, attr):
if attr.startswith("_"): # let all private and magic methods pass if attr.startswith("_"): # let all private and magic methods pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment