-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjsonToCut
executable file
·49 lines (38 loc) · 1.22 KB
/
jsonToCut
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
45
46
47
48
49
#!/usr/bin/env python
import argparse
import sys
import json
"""
Setup argument parser
"""
parser = argparse.ArgumentParser(description="This script generates a valid cut string from a JSON file, which specifies runs and luminosity sections. The output can be fed into other scripts as cut string. Note, that you can write the output of this script either to a file with './jsonToCut cut.json > outputFile' or to a shell variable with 'CUT=$(./jsonToCut cut.json)'.")
parser.add_argument("filenameInput", help="Path to the input JSON file")
args = parser.parse_args()
"""
Read JSON file
"""
with open(args.filenameInput, 'r') as f:
json = json.loads(f.read())
"""
Get cut string
"""
cutString = ""
isFirstRun = True
for run, lumiRanges in json.iteritems() :
# Process run
if not isFirstRun :
cutString += " || "
isFirstRun = False
cutString += "( run==" + str(run) + " && ( "
# process lumi
isFirstRange = True
for lumiRange in lumiRanges :
if not isFirstRange :
cutString += " || "
isFirstRange = False
cutString += "( lumi>=" + str(lumiRange[0]) + " && lumi<=" + str(lumiRange[1]) + ")"
cutString += " ) ) "
"""
Print string to stdout
"""
print(cutString)