Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:35

0001 #!/usr/bin/env python3
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 def filterRuns (lumiList, minRun, maxRun):
0011     allRuns = lumiList.getRuns()
0012     runsToRemove = []
0013     for run in allRuns:
0014         if minRun and int(run) < minRun:
0015             runsToRemove.append (run)
0016         if maxRun and int(run) > maxRun:
0017             runsToRemove.append (run)
0018     lumiList.removeRuns (runsToRemove)
0019     
0020 
0021 
0022 if __name__ == '__main__':
0023     
0024     parser = optparse.OptionParser ("Usage: %prog alpha1.json [alpha2.json:142300-145900]")
0025     parser.add_option ('--output', dest='output', type='string',
0026                        help='Save output to file OUTPUT')
0027     # required parameters
0028     (options, args) = parser.parse_args()
0029     if not len (args):
0030         raise RuntimeError("Must provide at least one input file")
0031 
0032     minMaxRE = re.compile (r'(\S+):(\d+)-(\d*)')
0033 
0034     finalList = LumiList()
0035     for filename in args:
0036         minRun = maxRun = 0
0037         match = minMaxRE.search (filename)
0038         if match:
0039             filename   =      match.group(1)
0040             minRun     = int( match.group(2) )
0041             try:
0042                 maxRun = int( match.group(3) )
0043             except:
0044                 pass
0045             if maxRun and minRun > maxRun:
0046                 raise RuntimeError("Minimum value (%d) is greater than maximum value (%d) for file '%s'" % (minRun, maxRun, filename))
0047         localList = LumiList (filename = filename)
0048         filterRuns (localList, minRun, maxRun)
0049         finalList = finalList | localList
0050 
0051     if options.output:
0052         finalList.writeJSON (options.output)
0053     else:
0054         print(finalList)