-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcreateLumiJson.py
More file actions
37 lines (34 loc) · 1.02 KB
/
createLumiJson.py
File metadata and controls
37 lines (34 loc) · 1.02 KB
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
import json
import sys
def convertFileRunLumiToRunLumiRanges(fileRunLumiFile):
with open(fileRunLumiFile, 'r') as f:
fileRunLumi = json.load(f)
runLumi = {}
for file, runLumis in fileRunLumi.items():
for run, lumis in runLumis.items():
if run not in runLumi:
runLumi[run] = set()
runLumi[run].update(lumis)
runLumiRanges = {}
for run, lumis in runLumi.items():
ranges = []
current_range = None
for lumi in sorted(lumis):
if current_range is None:
current_range = [lumi, lumi]
else:
if lumi == current_range[1] + 1:
current_range[1] = lumi
else:
ranges.append(current_range)
current_range = [lumi, lumi]
if current_range is not None:
ranges.append(current_range)
runLumiRanges[run] = ranges
return runLumiRanges
if __name__ == '__main__':
input = sys.argv[1]
output = sys.argv[2]
runLumiRanges = convertFileRunLumiToRunLumiRanges(input)
with open(output, 'w') as f:
json.dump(runLumiRanges, f)