9def main(infile, intree="CollectionTree"):
10 """
11 This script simply takes a ROOT file as input,
12 reads the index_ref for all events in the file
13 and makes sure each event has a unique value.
14 Otherwise, it raises an error...
15 """
16
17 logging.info(f"== Using input file {infile} ==")
18
19 f = ROOT.TFile(infile)
20 t = f.Get(intree)
21 t.SetBranchStatus("*", 0)
22 t.SetBranchStatus("index_ref", 1)
23
24 indices = {}
25 nentries = t.GetEntries()
26
27
28
29 for idx in range(nentries):
30 t.GetEntry(idx)
31 if hasattr(t, 'index_ref'):
32 iref = t.index_ref
33 if iref not in indices:
34 indices[iref] = 1
35 else:
36 indices[iref] += 1
37 else:
38 logging.error("Cannot read index_ref!")
39 return sys.exit(1)
40
41 nindices = len(indices)
42
43
44 if nindices == nentries:
45 logging.info(f"== Total number of keys is {nindices} vs"
46 f" total number of events is {nentries} ==")
47 logging.info("All good!")
48 return sys.exit(0)
49 else:
50
51 for key in indices:
52 pid = key >> 32
53 offset = key - ( pid << 32 )
54 logging.warning(f" >> {key} (pid : {pid}, offset : {offset})"
55 f" is repeated {indices[key]} times...")
56 logging.error(f"== Total number of keys is {nindices} vs"
57 f" total number of events is {nentries} ==")
58 logging.error("The test FAILED!")
59 return sys.exit(1)
60