Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:01

0001 #! /usr/bin/env python3
0002 
0003 from FWCore.PythonUtilities.XML2Python import xml2obj
0004 from FWCore.PythonUtilities.LumiList   import LumiList
0005 from pprint import pprint
0006 
0007 import ast
0008 from argparse import ArgumentParser
0009 import sys
0010 
0011 if __name__ == '__main__':
0012 
0013     parser = ArgumentParser()
0014     parser.add_argument('--output', dest='output', type=str,
0015                         help='Save output to file OUTPUT')
0016     parser.add_argument("job_fjr", metavar="job.fjr", nargs='+', type=str)
0017     options = parser.parse_args()
0018 
0019     runsLumisDict = {}
0020     for fjr in options.job_fjr:
0021         try:
0022             obj = xml2obj (filename=fjr)
0023         except:
0024             print("'%s' is not an framework job report.  Skipping." % fjr)
0025             continue
0026         for inputFile in obj.InputFile:
0027             try: # Regular XML version, assume only one of these
0028                 runObjects = inputFile.Runs.Run
0029                 for run in runObjects:
0030                     runNumber = int (run.ID)
0031                     runList = runsLumisDict.setdefault (runNumber, [])
0032                     for lumiPiece in run.LumiSection:
0033                         lumi = int (lumiPiece.ID)
0034                         runList.append (lumi)
0035             except:
0036                 try: # JSON-like version in CRAB XML files, runObjects is usually a list
0037                     if isinstance(inputFile.Runs, str):
0038                         runObjects = [inputFile.Runs]
0039                     else:
0040                         runObjects = inputFile.Runs
0041 
0042                     for runObject in runObjects:
0043                         try:
0044                             runs = ast.literal_eval(runObject)
0045                             for (run, lumis) in runs.items():
0046                                 runList = runsLumisDict.setdefault (int(run), [])
0047                                 runList.extend(lumis)
0048                         except ValueError: # Old style handled above
0049                             pass
0050                 except:
0051                     print("Run missing in '%s'.  Skipping." % fjr)
0052                 continue
0053 
0054     jsonList = LumiList (runsAndLumis = runsLumisDict)
0055     if options.output:
0056         jsonList.writeJSON (options.output)
0057     else:
0058         print(jsonList)
0059