6 |
|
|
7 |
|
parser = OptionParser() |
8 |
|
parser.add_option("-r", "--range", dest="range", help="run range", metavar="BEGIN-END") |
9 |
+ |
parser.add_option("-i", "--intersection", action="store_true", dest="intersection", help="show intersections") |
10 |
+ |
parser.add_option("-u", "--union", action="store_true", dest="union", help="show union") |
11 |
|
|
12 |
|
(options, args) = parser.parse_args() |
13 |
|
|
30 |
|
newList = dict() |
31 |
|
|
32 |
|
for sourceDest in ((old, oldList), (new, newList)): |
33 |
< |
runBlocks = runPat.findall(sourceDest[0]) |
33 |
> |
source = sourceDest[0] |
34 |
> |
dest = sourceDest[1] |
35 |
> |
|
36 |
> |
runBlocks = runPat.findall(source) |
37 |
|
for runBlock in runBlocks: |
38 |
|
run = int(runBlock[0]) |
39 |
|
if run < begin or run > end: |
40 |
|
continue |
41 |
|
|
42 |
|
lumiBlocks = lumiPat.findall(runBlock[1]) |
43 |
< |
beginEnds = [] |
43 |
> |
boundPairs = [] |
44 |
> |
if run in dest: |
45 |
> |
boundPairs = dest[run] |
46 |
> |
|
47 |
|
for lumiBlock in lumiBlocks: |
48 |
< |
beginEnds.append((int(lumiBlock[0]), int(lumiBlock[1]))) |
48 |
> |
boundPairs.append((int(lumiBlock[0]), int(lumiBlock[1]))) |
49 |
|
|
50 |
< |
sourceDest[1][int(runBlock[0])] = beginEnds |
50 |
> |
dest[run] = boundPairs |
51 |
|
|
52 |
|
jsonTxt = '{' |
53 |
|
|
54 |
< |
runs = newList.keys() |
55 |
< |
runs.sort() |
56 |
< |
|
57 |
< |
for run in runs: |
58 |
< |
lumis = newList[run] |
59 |
< |
lumisToWrite = [] |
60 |
< |
|
61 |
< |
if run not in oldList or len(oldList[run]) == 0: |
62 |
< |
lumisToWrite = lumis |
54 |
> |
runs = set(newList.keys()) |
55 |
> |
if options.union: |
56 |
> |
runs |= set(oldList.keys()) |
57 |
> |
|
58 |
> |
runsList = list(runs) |
59 |
> |
runsList.sort() |
60 |
> |
|
61 |
> |
for run in runsList: |
62 |
> |
allOldLumis = set() |
63 |
> |
allNewLumis = set() |
64 |
> |
|
65 |
> |
if run in oldList: |
66 |
> |
for boundPair in oldList[run]: |
67 |
> |
allOldLumis |= set(range(boundPair[0], boundPair[1] + 1)) |
68 |
> |
|
69 |
> |
if run in newList: |
70 |
> |
for boundPair in newList[run]: |
71 |
> |
allNewLumis |= set(range(boundPair[0], boundPair[1] + 1)) |
72 |
> |
|
73 |
> |
if options.union: |
74 |
> |
allLumis = allNewLumis.union(allOldLumis) |
75 |
> |
elif options.intersection: |
76 |
> |
allLumis = allNewLumis.intersection(allOldLumis) |
77 |
|
else: |
78 |
< |
allOldLumis = [] |
57 |
< |
for beginEndPair in oldList[run]: |
58 |
< |
allOldLumis += range(beginEndPair[0], beginEndPair[1] + 1) |
59 |
< |
|
60 |
< |
lumisNotInOld = [] |
61 |
< |
for beginEndPair in lumis: |
62 |
< |
for l in range(beginEndPair[0], beginEndPair[1] + 1): |
63 |
< |
if l not in allOldLumis: |
64 |
< |
lumisNotInOld.append(l) |
78 |
> |
allLumis = allNewLumis.difference(allOldLumis) |
79 |
|
|
80 |
< |
if len(lumisNotInOld) == 0: |
81 |
< |
continue |
82 |
< |
|
83 |
< |
lumisNotInOld.sort() |
84 |
< |
beginOfBlock = lumisNotInOld[0] |
85 |
< |
currentLumi = lumisNotInOld[0] |
86 |
< |
for i in range(1, len(lumisNotInOld)): |
87 |
< |
if lumisNotInOld[i] != currentLumi + 1: |
88 |
< |
lumisToWrite.append((beginOfBlock, currentLumi)) |
89 |
< |
beginOfBlock = lumisNotInOld[i] |
90 |
< |
|
91 |
< |
currentLumi = lumisNotInOld[i] |
92 |
< |
|
93 |
< |
if len(lumisToWrite) > 0: |
94 |
< |
jsonTxt += '"' + str(run) + '": [' |
95 |
< |
for lumiPair in lumisToWrite: |
96 |
< |
jsonTxt += '[' + str(lumiPair[0]) + ', ' + str(lumiPair[1]) + '], ' |
97 |
< |
jsonTxt = jsonTxt.rstrip(', ') |
84 |
< |
jsonTxt += '], ' |
80 |
> |
if len(allLumis) == 0: |
81 |
> |
continue |
82 |
> |
|
83 |
> |
lumiList = list(allLumis) |
84 |
> |
lumiList.sort() |
85 |
> |
|
86 |
> |
jsonTxt += '"' + str(run) + '": [' |
87 |
> |
|
88 |
> |
beginOfBlock = lumiList[0] |
89 |
> |
currentLumi = lumiList[0] |
90 |
> |
for i in range(1, len(lumiList)): |
91 |
> |
if lumiList[i] != currentLumi + 1: |
92 |
> |
jsonTxt += '[' + str(beginOfBlock) + ', ' + str(currentLumi) + '], ' |
93 |
> |
beginOfBlock = lumiList[i] |
94 |
> |
|
95 |
> |
currentLumi = lumiList[i] |
96 |
> |
|
97 |
> |
jsonTxt += '[' + str(beginOfBlock) + ', ' + str(currentLumi) + ']], ' |
98 |
|
|
99 |
|
jsonTxt = jsonTxt.rstrip(', ') |
100 |
|
jsonTxt += '}' |