File indexing completed on 2023-03-17 11:03:35
0001
0002
0003 from __future__ import print_function
0004 import sys
0005 import optparse
0006 import re
0007 from FWCore.PythonUtilities.LumiList import LumiList
0008
0009
0010 if __name__ == '__main__':
0011
0012 parser = optparse.OptionParser ("Usage: %prog alpha.json")
0013 parser.add_option ('--max', dest='max', type='int', default=0,
0014 help='maximum run to keep in output')
0015 parser.add_option ('--min', dest='min', type='int', default=0,
0016 help='minimum run to keep in output')
0017 parser.add_option ('--runs', dest='runs', type='string',
0018 action='append', default = [],
0019 help='runs to remove from JSON file')
0020 parser.add_option ('--output', dest='output', type='string',
0021 help='Save output to file OUTPUT')
0022
0023 (options, args) = parser.parse_args()
0024 if len (args) != 1:
0025 raise RuntimeError("Must provide exactly one input file")
0026
0027 if options.min and options.max and options.min > options.max:
0028 raise RuntimeError("Minimum value (%d) is greater than maximum value (%d)" % (options.min, options.max))
0029
0030 commaRE = re.compile (r',')
0031 runsToRemove = []
0032 for chunk in options.runs:
0033 runs = commaRE.split (chunk)
0034 runsToRemove.extend (runs)
0035
0036 alphaList = LumiList (filename = args[0])
0037 allRuns = alphaList.getRuns()
0038 for run in allRuns:
0039 if options.min and int(run) < options.min:
0040 runsToRemove.append (run)
0041 if options.max and int(run) > options.max:
0042 runsToRemove.append (run)
0043
0044 alphaList.removeRuns (runsToRemove)
0045
0046 if options.output:
0047 alphaList.writeJSON (options.output)
0048 else:
0049 print(alphaList)