File indexing completed on 2024-04-06 12:13:01
0001
0002
0003 import sys
0004 from argparse import ArgumentParser
0005 import re
0006 from FWCore.PythonUtilities.LumiList import LumiList
0007
0008 def filterRuns (lumiList, minRun, maxRun):
0009 allRuns = lumiList.getRuns()
0010 runsToRemove = []
0011 for run in allRuns:
0012 if minRun and int(run) < minRun:
0013 runsToRemove.append (run)
0014 if maxRun and int(run) > maxRun:
0015 runsToRemove.append (run)
0016 lumiList.removeRuns (runsToRemove)
0017
0018 if __name__ == '__main__':
0019
0020 parser = ArgumentParser()
0021 parser.add_argument('--output', dest='output', type=str,
0022 help='Save output to file OUTPUT')
0023 parser.add_argument("alpha_json", metavar="alpha.json[:142300-145900]", type=str, nargs='+')
0024
0025 options = parser.parse_args()
0026
0027 minMaxRE = re.compile (r'(\S+):(\d+)-(\d*)')
0028
0029 finalList = LumiList()
0030 for filename in options.alpha_json:
0031 minRun = maxRun = 0
0032 match = minMaxRE.search (filename)
0033 if match:
0034 filename = match.group(1)
0035 minRun = int( match.group(2) )
0036 try:
0037 maxRun = int( match.group(3) )
0038 except:
0039 pass
0040 if maxRun and minRun > maxRun:
0041 raise RuntimeError("Minimum value (%d) is greater than maximum value (%d) for file '%s'" % (minRun, maxRun, filename))
0042 localList = LumiList (filename = filename)
0043 filterRuns (localList, minRun, maxRun)
0044 finalList = finalList | localList
0045
0046 if options.output:
0047 finalList.writeJSON (options.output)
0048 else:
0049 print(finalList)