Skip to content
Snippets Groups Projects
Commit 769a2757 authored by Zineb Aly's avatar Zineb Aly
Browse files

change lists to sets for lookups

parent 0eed8924
No related branches found
Tags v0.8.1
1 merge request!15Best reco hits events
Pipeline #8558 passed with warnings
......@@ -60,7 +60,7 @@ class OfflineKeys:
except those found in fake branches.
"""
if self._events_keys is None:
fake_branches = ['Evt', 'AAObject', 'TObject', 't']
fake_branches = set(['Evt', 'AAObject', 'TObject', 't'])
t_baskets = ['t.fSec', 't.fNanoSec']
tree = uproot.open(self._file_path)['E']['Evt']
self._events_keys = [
......@@ -80,9 +80,9 @@ class OfflineKeys:
except those found in fake branches.
"""
if self._hits_keys is None:
fake_branches = [
fake_branches = set([
'hits.usr', 'hits.usr_names'
] # to be treated like trks.usr and trks.usr_names
]) # to be treated like trks.usr and trks.usr_names
tree = uproot.open(self._file_path)['E']['hits']
self._hits_keys = [
key.decode('utf8') for key in tree.keys()
......@@ -103,9 +103,9 @@ class OfflineKeys:
if self._tracks_keys is None:
# a solution can be tree['trks.usr_data'].array(
# uproot.asdtype(">i4"))
fake_branches = [
fake_branches = set([
'trks.usr_data', 'trks.usr', 'trks.usr_names'
] # can be accessed using tree['trks.usr_names'].array()
]) # can be accessed using tree['trks.usr_names'].array()
tree = uproot.open(self._file_path)['E']['Evt']['trks']
self._tracks_keys = [
key.decode('utf8') for key in tree.keys()
......@@ -124,7 +124,7 @@ class OfflineKeys:
except those found in fake branches.
"""
if self._mc_hits_keys is None:
fake_branches = ['mc_hits.usr', 'mc_hits.usr_names']
fake_branches = set(['mc_hits.usr', 'mc_hits.usr_names'])
tree = uproot.open(self._file_path)['E']['Evt']['mc_hits']
self._mc_hits_keys = [
key.decode('utf8') for key in tree.keys()
......@@ -143,9 +143,9 @@ class OfflineKeys:
except those found in fake branches.
"""
if self._mc_tracks_keys is None:
fake_branches = [
fake_branches = set([
'mc_trks.usr_data', 'mc_trks.usr', 'mc_trks.usr_names'
] # same solution as above can be used
]) # same solution as above can be used
tree = uproot.open(self._file_path)['E']['Evt']['mc_trks']
self._mc_tracks_keys = [
key.decode('utf8') for key in tree.keys()
......@@ -313,7 +313,7 @@ class Reader:
do not contain data. Therefore, the keys corresponding to these
fake branches are not read.
"""
if key not in self.keys.valid_keys and not isinstance(key, int):
if key not in set(self.keys.valid_keys) and not isinstance(key, int):
raise KeyError(
"'{}' is not a valid key or is a fake branch.".format(key))
return self._data[key]
......
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