6 from FWCore.PythonUtilities.LumiList
import LumiList
9 if __name__ ==
'__main__':
11 parser = optparse.OptionParser (
"Usage: %prog input.csv")
12 parser.add_option (
'--output', dest=
'output', type=
'string',
13 help=
'Save output to file OUTPUT')
14 parser.add_option (
'--runIndex', dest=
'runIndex', type=
'int',
16 help=
'column to be converted to run number (default %default)')
17 parser.add_option (
'--lumiIndex', dest=
'lumiIndex', type=
'int',
19 help=
'column to be converted to lumi section number (default %default)')
21 (options, args) = parser.parse_args()
23 raise RuntimeError(
"Must provide exactly one input file")
25 sepRE = re.compile (
r'[\s,;:]+')
27 events = open (args[0],
'r')
28 runIndex, lumiIndex = options.runIndex, options.lumiIndex
29 minPieces = max (runIndex, lumiIndex) + 1
31 pieces = sepRE.split (line.strip())
32 if len (pieces) < minPieces:
35 run, lumi = int( pieces[runIndex] ), int( pieces[lumiIndex] )
38 runLumiDict.setdefault (run, []).append (lumi)
39 jsonList = LumiList (runsAndLumis = runLumiDict)
41 jsonList.writeJSON (options.output)