Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:01

0001 #!/usr/bin/env python3
0002 
0003 import sys
0004 from argparse import ArgumentParser
0005 import re
0006 from FWCore.PythonUtilities.LumiList import LumiList
0007 
0008 if __name__ == '__main__':
0009     
0010     parser = ArgumentParser()
0011     parser.add_argument('--max', dest='max', type=int, default=0,
0012                         help='maximum run to keep in output')
0013     parser.add_argument('--min', dest='min', type=int, default=0,
0014                         help='minimum run to keep in output')
0015     parser.add_argument('--runs', dest='runs', type=str,
0016                         action='append', default = [],
0017                         help='runs to remove from JSON file')
0018     parser.add_argument('--output', dest='output', type=str,
0019                         help='Save output to file OUTPUT')
0020     parser.add_argument("alpha", metavar="alpha.json", type=str)
0021     # required parameters
0022     options = parser.parse_args()
0023 
0024     if options.min and options.max and options.min > options.max:
0025         raise RuntimeError("Minimum value (%d) is greater than maximum value (%d)" % (options.min, options.max))
0026 
0027     commaRE = re.compile (r',')
0028     runsToRemove = []
0029     for chunk in options.runs:
0030         runs = commaRE.split (chunk)
0031         runsToRemove.extend (runs)
0032 
0033     alphaList = LumiList (filename = options.alpha)  # Read in first JSON file
0034     allRuns = alphaList.getRuns()
0035     for run in allRuns:
0036         if options.min and int(run) < options.min:
0037             runsToRemove.append (run)
0038         if options.max and int(run) > options.max:
0039             runsToRemove.append (run)
0040 
0041     alphaList.removeRuns (runsToRemove)
0042 
0043     if options.output:
0044         alphaList.writeJSON (options.output)
0045     else:
0046         print(alphaList)