Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-16 03:19:59

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 if __name__ == '__main__':
0011     
0012     parser = optparse.OptionParser ("Usage: %prog input.csv")
0013     parser.add_option ('--output', dest='output', type='string',
0014                        help='Save output to file OUTPUT')
0015     parser.add_option ('--runIndex', dest='runIndex', type='int',
0016                        default = 0,
0017                        help='column to be converted to run number (default %default)')
0018     parser.add_option ('--lumiIndex', dest='lumiIndex', type='int',
0019                        default = 1,
0020                        help='column to be converted to lumi section number (default %default)')
0021     # required parameters
0022     (options, args) = parser.parse_args()
0023     if len (args) != 1:
0024         raise RuntimeError("Must provide exactly one input file")
0025 
0026     sepRE = re.compile (r'[\s,;:]+')
0027     runLumiDict = {}    
0028     events = open (args[0], 'r')
0029     runIndex, lumiIndex = options.runIndex, options.lumiIndex
0030     minPieces = max (runIndex, lumiIndex) + 1
0031     for line in events:
0032         pieces = sepRE.split (line.strip())
0033         if len (pieces) < minPieces:
0034             continue
0035         try:
0036             run, lumi = int( pieces[runIndex] ), int( pieces[lumiIndex] )
0037         except:
0038             continue
0039         runLumiDict.setdefault (run, []).append (lumi)
0040     jsonList = LumiList (runsAndLumis = runLumiDict) 
0041     if options.output:
0042         jsonList.writeJSON (options.output)
0043     else:
0044         print(jsonList)