#!/usr/bin/env python3 """Make a temporary TTree copy for legacy Uproot versions.""" from __future__ import annotations import argparse from pathlib import Path import awkward as ak import uproot def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("source", type=Path) parser.add_argument("output", type=Path) args = parser.parse_args() with uproot.open(args.source) as root_file: tree = root_file["output"] arrays = tree.arrays(list(tree.keys()), library="ak") branch_types = { name: str(ak.type(arrays[name])).split("* ", 1)[1] for name in arrays.fields } with uproot.recreate(args.output) as root_file: root_file.mktree("output", branch_types) root_file["output"].extend(arrays) return 0 if __name__ == "__main__": raise SystemExit(main())