CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
fjr2json.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 from FWCore.PythonUtilities.XML2Python import xml2obj
4 from FWCore.PythonUtilities.LumiList import LumiList
5 from pprint import pprint
6 import optparse
7 import sys
8 
9 
10 if __name__ == '__main__':
11 
12  parser = optparse.OptionParser ("Usage: %prog [--options] job1.fjr [job2.fjr...]")
13  parser.add_option ('--output', dest='output', type='string',
14  help='Save output to file OUTPUT')
15  (options, args) = parser.parse_args()
16  if not args:
17  raise RuntimeError, "Must provide at least one input file"
18 
19  runsLumisDict = {}
20  for fjr in args:
21  try:
22  obj = xml2obj (filename=fjr)
23  except:
24  print "'%s' is not an framework job report. Skipping." % fjr
25  continue
26  for inputFile in obj.InputFile:
27  try:
28  runList = inputFile.Runs.Run
29  except:
30  try:
31  print "'%s' in '%s' contains no runs. Skipping." % \
32  (inputFile.PFN, fjr)
33  except:
34  print "Some run in '%s' contains no runs. Skipping." % \
35  fjr
36  continue
37  for run in runList:
38  runNumber = int (run.ID)
39  runList = runsLumisDict.setdefault (runNumber, [])
40  for lumiPiece in run.LumiSection:
41  lumi = int (lumiPiece.ID)
42  runList.append (lumi)
43 
44  jsonList = LumiList (runsAndLumis = runsLumisDict)
45  if options.output:
46  jsonList.writeJSON (options.output)
47  else:
48  print jsonList
49