6 from FWCore.PythonUtilities.LumiList
import LumiList
9 if __name__ ==
'__main__':
11 parser = optparse.OptionParser (
"Usage: %prog input.json input.csv output.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)')
20 parser.add_option (
'--noWarnings', dest=
'noWarnings', action=
'store_true',
21 help=
'do not print warnings about lines not matching run, lumi numbers')
23 (options, args) = parser.parse_args()
25 raise RuntimeError,
"Must provide an input JSON file, an input CSV file, and an output CSV file"
27 sepRE = re.compile (
r'[\s,;:]+')
29 jsonList = LumiList (args[0])
30 source = open (args[1],
'r')
31 target = open (args[2], 'w')
32 runIndex, lumiIndex = options.runIndex, options.lumiIndex
33 minPieces = max (runIndex, lumiIndex) + 1
36 pieces = sepRE.split (copy.strip())
37 if len (pieces) < minPieces:
38 if not options.noWarnings:
39 print "Saving line '%s' since no identifiable run and lumi info" \
44 run, lumi = int( pieces[runIndex] ), int( pieces[lumiIndex] )
46 if not options.noWarnings:
47 print "Saving line '%s' since no identifiable run,lumi info" \
53 if (run, lumi)
in jsonList: