forked from cms-btv-pog/BTVNanoCommissioning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skim_broken.py
36 lines (31 loc) · 1.24 KB
/
skim_broken.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
import argparse
import uproot
import json
import sys
import os
parser = argparse.ArgumentParser(description='Save json files without broken files')
parser.add_argument('-i', '--input', type=str, default='datasets_local.json', help='Input file with file list')
parser.add_argument('-b', '--broken', type=str, default='datasets_broken.json', help='Input file with broken files list')
parser.add_argument('-o', '--output', type=str, default='datasets_fixed.json', help='Output file without broken files')
args = parser.parse_args()
if ((not args.input.endswith(".json")) | (not args.broken.endswith(".json")) | (not args.output.endswith(".json"))):
sys.exit("Only json files allowed as input/output.")
if (os.path.exists(args.output)):
sys.exit(f"Output file {args.output} is already existing.")
files = None
brokenfiles = None
with open(args.input) as f:
files = json.load(f)
with open(args.broken) as g:
brokenfiles = json.load(g)
f.close()
g.close()
for key in brokenfiles.keys():
filestoskim = []
for f in files[key]:
if f in brokenfiles[key]:
filestoskim.append(f)
#print(f"Removing {f}")
files[key] = [f for f in files[key] if not f in filestoskim]
with open(args.output, 'w') as outfile:
json.dump(files, outfile, sort_keys=True, indent=4)