12 parser = argparse.ArgumentParser(description=
"Check for branches in a ROOT TTree.")
13 parser.add_argument(
"--input_file", required=
True, help=
"Path to the ROOT file")
14 parser.add_argument(
"--tree_name", required=
True, help=
"Name of the TTree inside the file")
15 parser.add_argument(
"--branches", nargs=
"*", default=[], help=
"Branch names to check that should be present in tree")
16 parser.add_argument(
"--forbidden-branches", nargs=
"*", default=[], help=
"Branch names to check that should not be present in tree")
18 args = parser.parse_args()
21 f = ROOT.TFile.Open(args.input_file)
22 if not f
or f.IsZombie():
23 print(f
"Error: Could not open file '{args.input_file}'")
27 tree = f.Get(args.tree_name)
29 print(f
"Error: Could not find tree '{args.tree_name}' in file '{args.input_file}'")
33 available = {b.GetName()
for b
in tree.GetListOfBranches()}
37 forbidden_found =
False
42 print(f
"Checking required branches in tree '{args.tree_name}':")
43 for br
in args.branches:
47 print(f
"[ MISSING ] {br}")
51 if args.forbidden_branches:
53 print(
"Checking forbidden branches:")
54 for br
in args.forbidden_branches:
56 print(f
"[ FORBIDDEN ] {br}")
57 forbidden_found =
True
59 print(f
"[ OK (not present) ] {br}")
64 if missing
or forbidden_found: