Python bindings to oxyroot. Makes reading .root files blazing fast 馃殌
1import oxyroot
2
3if __name__ == '__main__':
4 import uproot
5 import numpy as np
6 import time
7
8 file_name = "ntuples.root"
9 tree_name = 'mu_mc'
10
11 up_start_time = time.time()
12 up_tree = uproot.open(file_name)[tree_name]
13 for branch in up_tree:
14 # print(branch, branch.typename)
15 if branch.typename != "std::string": # Uproot cannot read strings?
16 up_values = branch.array(library="np")
17 print(f"Uproot read {branch.name} into a {type(up_values)} and it has a mean of {np.nanmean(up_values):.2f}")
18 up_end_time = time.time()
19
20 print("\n")
21
22 oxy_start_time = time.time()
23 oxy_tree = oxyroot.open(file_name)[tree_name]
24 for branch in oxy_tree:
25 # print(branch, branch.typename)
26 # if branch.typename != "string":
27 oxy_values = branch.array()
28 if type(oxy_values) is np.ndarray:
29 print(f"Oxyroot read {branch.name} into a {type(oxy_values)} and it has a mean of {np.nanmean(oxy_values):.2f}")
30 else:
31 print(f"Oxyroot read {branch.name} into a {type(oxy_values)} and it has a length of {len(oxy_values)}")
32 oxy_end_time = time.time()
33
34 print("\n Total time")
35 print(f"Uproot took: {up_end_time - up_start_time:.3}s")
36 print(f"Oxyroot took: {oxy_end_time - oxy_start_time:.3}s")