-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunset_rootbit.py
44 lines (42 loc) · 1.65 KB
/
unset_rootbit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import ROOT
import glob
import argparse
import os
from rich.progress import Progress
parser = argparse.ArgumentParser()
parser.add_argument("--basepath", type=str, required=True)
parser.add_argument("--check", action="store_true")
args = parser.parse_args()
# base_path = "ntuples/2018/*/*/*.root"
# dataset = yaml.load(open("datasets.yaml"), Loader=yaml.Loader)
base_path = os.path.join(args.basepath, "*/*/*.root")
ntuples = glob.glob(base_path)
with Progress() as progress:
task = progress.add_task("Updating Statusbit...", total=len(ntuples))
for ntuple in ntuples:
# filename = os.path.basename(ntuple)
# open the ntuple
if args.check:
# do a chort check if it worked
print("Checking", ntuple)
rfile = ROOT.TFile(ntuple, "READ")
t = rfile.Get("ntuple")
if t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled):
print("kEntriesReshuffled bit is true")
else:
print("kEntriesReshuffled bit is false")
rfile.Close()
else:
print("Updating {}".format(ntuple))
rfile = ROOT.TFile(ntuple, "UPDATE")
if "ntuple" not in [x.GetTitle() for x in rfile.GetListOfKeys()]:
print("ntuple tree not found, continueing")
rfile.Close()
continue
t = rfile.Get("ntuple")
if t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled):
print("Bit is set, resetting....")
t.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
rfile.Write()
rfile.Close()
progress.update(task, advance=1)