Go to the documentation of this file.00001
00002
00003 import sys
00004 import optparse
00005 import re
00006 from FWCore.PythonUtilities.LumiList import LumiList
00007
00008
00009 def filterRuns (lumiList, minRun, maxRun):
00010 allRuns = lumiList.getRuns()
00011 runsToRemove = []
00012 for run in allRuns:
00013 if minRun and int(run) < minRun:
00014 runsToRemove.append (run)
00015 if maxRun and int(run) > maxRun:
00016 runsToRemove.append (run)
00017 lumiList.removeRuns (runsToRemove)
00018
00019
00020
00021 if __name__ == '__main__':
00022
00023 parser = optparse.OptionParser ("Usage: %prog alpha1.json [alpha2.json:142300-145900]")
00024 parser.add_option ('--output', dest='output', type='string',
00025 help='Save output to file OUTPUT')
00026
00027 (options, args) = parser.parse_args()
00028 if not len (args):
00029 raise RuntimeError, "Must provide at least one input file"
00030
00031 minMaxRE = re.compile (r'(\S+):(\d+)-(\d*)')
00032
00033 finalList = LumiList()
00034 for filename in args:
00035 minRun = maxRun = 0
00036 match = minMaxRE.search (filename)
00037 if match:
00038 filename = match.group(1)
00039 minRun = int( match.group(2) )
00040 try:
00041 maxRun = int( match.group(3) )
00042 except:
00043 pass
00044 if maxRun and minRun > maxRun:
00045 raise RuntimeError, "Minimum value (%d) is greater than maximum value (%d) for file '%s'" % (minRun, maxRun, filename)
00046 localList = LumiList (filename = filename)
00047 filterRuns (localList, minRun, maxRun)
00048 finalList = finalList | localList
00049
00050 if options.output:
00051 finalList.writeJSON (options.output)
00052 else:
00053 print finalList