9 def __init__(self, database_connection):
10 self.
_db = database_connection
12 def load(self, filename, batch_id=0, tables=None, if_exists='replace'):
16 except ImportError
as e:
17 print (
"The uproot package is required for loading ROOT files "
18 "with TTreeLoader. \nInstall it with `pip install uproot`",
23 if isinstance(tables, str):
27 input_file = uproot.open(filename)
30 with self.
_db.connect()
as db:
32 for key
in input_file.keys():
37 if not isinstance(obj, uproot.behaviors.TTree.TTree):
41 if tables
is not None and all([key
not in t
for t
in tables]):
45 obj.arrays(library=
'np')
47 df[
'input_file'] = batch_id
48 df.to_sql(obj.name, db, if_exists=if_exists)