3from typing
import Collection, Union, Dict, Optional, Any
26 Ease loading nTuples generated with Gaussino into the SQLite
27 event model of Lamarr.
28 As the other python data loaders, UprootLoader should be configured in the
30 The configured object is then called during the event loop to
31 pass the updated connection to the SQLamarr.SQLite3DB instance.
33 The ROOT file with path `input_file` is expected contain a
34 `TDirectory` (named as configured
35 with the `collector` keyword) with a `TTree` per SQLite table (the
36 names of the `TTree`s are listed in `tables`) and each `TTree` should
37 include a column (titled as indicated by `batch_id_var`) providing
38 a unique identifier for the event number.
43 tables: Collection[str],
44 collector: str =
'LamarrCollector',
45 batch_id_var: str =
'batch_id',
46 max_rows: Union[int,
None] =
None
56 root_dir = uproot.open(input_file)[collector]
59 root_dir[tables[0]].arrays(self.
bid_var, library=
'np', entry_stop=max_rows)[self.
bid_var]
63 n: pd.DataFrame(root_dir[n].arrays(library=
'np', entry_stop=max_rows))
for n
in self.
tables
66 self.
logger = logging.getLogger(self.__class__.__name__)
73 def __call__(self, db):
78 def load(self, batch):
80 raise ValueError(
"PandasLoader tried loading with uninitialized db.\n"
83 self.
logger.debug(f
"Preparing uproot loader for batch {batch}")
85 description=f
"batch_id: {batch}",