3 from pathlib
import Path
5 from typing
import Optional
14 rf = uproot.open(path)
18 for tree_name
in sorted(rf.keys(cycle=
False)):
19 gh.update(tree_name.encode(
"utf8"))
23 if not isinstance(tree, uproot.TTree):
25 except NotImplementedError:
27 keys = list(sorted(tree.keys()))
29 branches = tree.arrays(library=
"ak")
31 if not ordering_invariant:
35 h.update(name.encode(
"utf8"))
37 arr = ak.flatten(arr, axis=
None)
39 h.update(arr.tobytes())
45 for row
in zip(*[branches[b]
for b
in keys]):
48 if isinstance(obj, ak.highlevel.Array):
50 h.update(ak.to_numpy(obj).tobytes())
52 arr = ak.to_numpy(ak.flatten(obj, axis=
None))
53 h.update(arr.tobytes())
55 h.update(np.array([obj]).tobytes())
56 items = np.append(items, h.digest())
61 h.update(
"".
join(keys).encode(
"utf8"))
62 h.update(items.tobytes())
68 if "__main__" == __name__:
69 p = argparse.ArgumentParser(
70 description=
"Calculate a hash of the numeric content of a root file"
74 "input_file", type=Path, help=
"The input ROOT file to calculate a hash for"
77 "--no-ordering-invariant",
80 help=
"Calculate a hash that is not invariant under reordering of entries? (faster than invariant)",
88 ordering_invariant=
not args.no_ordering_invariant,