CMS 3D CMS Logo

fjr2json.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 
3 from FWCore.PythonUtilities.XML2Python import xml2obj
4 from FWCore.PythonUtilities.LumiList import LumiList
5 from pprint import pprint
6 
7 import ast
8 from argparse import ArgumentParser
9 import sys
10 
11 if __name__ == '__main__':
12 
13  parser = ArgumentParser()
14  parser.add_argument('--output', dest='output', type=str,
15  help='Save output to file OUTPUT')
16  parser.add_argument("job_fjr", metavar="job.fjr", nargs='+', type=str)
17  options = parser.parse_args()
18 
19  runsLumisDict = {}
20  for fjr in options.job_fjr:
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: # Regular XML version, assume only one of these
28  runObjects = inputFile.Runs.Run
29  for run in runObjects:
30  runNumber = int (run.ID)
31  runList = runsLumisDict.setdefault (runNumber, [])
32  for lumiPiece in run.LumiSection:
33  lumi = int (lumiPiece.ID)
34  runList.append (lumi)
35  except:
36  try: # JSON-like version in CRAB XML files, runObjects is usually a list
37  if isinstance(inputFile.Runs, str):
38  runObjects = [inputFile.Runs]
39  else:
40  runObjects = inputFile.Runs
41 
42  for runObject in runObjects:
43  try:
44  runs = ast.literal_eval(runObject)
45  for (run, lumis) in runs.items():
46  runList = runsLumisDict.setdefault (int(run), [])
47  runList.extend(lumis)
48  except ValueError: # Old style handled above
49  pass
50  except:
51  print("Run missing in '%s'. Skipping." % fjr)
52  continue
53 
54  jsonList = LumiList (runsAndLumis = runsLumisDict)
55  if options.output:
56  jsonList.writeJSON (options.output)
57  else:
58  print(jsonList)
59 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47