#!/usr/bin/env python import os, sys try: # Can remove when CMSSW 3.7 and earlier are dropped from FWCore.PythonUtilities.LumiList import LumiList except ImportError: print "FWCore.PythonUtilities.LumiList not in PythonPath" print "This script must be executed from a CMSSW environment" exit(1) try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson from ProdCommon.FwkJobRep.ReportParser import readJobReport except ImportError: print "ProdCommon.FwkJobRep.ReportParser not in PythonPath" print "This script must be executed from a CRAB environment" exit(1) try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson import json except: import simplejson as json def getLumi(lumiFilename): ''' Return the delivered and recorded lumi section and luminosity of current task ''' try: from RecoLuminosity.LumiDB import inputFilesetParser,csvSelectionParser, selectionParser,csvReporter,argparse,CommonUtil,lumiQueryAPI except: print "Failed to load python modules inputFilesetParser,csvSelectionParser, selectionParser,csvReporter,argparse,CommonUtil,lumiQueryAPI" exit(2) parameters = lumiQueryAPI.ParametersObject() # parameters.verbose = False parameters.noWarnings = True # parameters.beammode = 'STABLE BEAMS' # parameters.xingMinLum = 1e-3 session,svc = lumiQueryAPI.setupSession ('frontier://LumiProd/CMS_LUMI_PROD', None, parameters) inputRange = inputFilesetParser.inputFilesetParser(lumiFilename) delivereddata=lumiQueryAPI.deliveredLumiForRange(session, parameters, inputRange) recordeddata=lumiQueryAPI.recordedLumiForRange(session, parameters, inputRange) totalDeliveredLS = 0 totalSelectedLS = 0 totalDelivered = 0.0 totalRecorded = 0.0 for runidx, deliveredrowdata in enumerate (delivereddata): if deliveredrowdata[1] == 'N/A': continue totalDeliveredLS += int (deliveredrowdata[1]) totalDelivered += float (deliveredrowdata[2]) selectedls = recordeddata[runidx][2].keys() if len (selectedls) != 0: recordedLumi = lumiQueryAPI.calculateTotalRecorded (recordeddata[runidx][2]) else: recordedLumi = 0.0 totalSelectedLS += len (selectedls) totalRecorded += recordedLumi del session del svc return (totalDeliveredLS, totalDelivered, totalSelectedLS, totalRecorded) if __name__ == '__main__': fjr = 'fjr.xml' if len(sys.argv)>1: fjr = sys.argv[1] else: print 'No Input File' print 'Usage: ',sys.argv[0],' InputFrameworkJobReport.xml' exit(2) if (fjr in ['-h','--help']): print 'Usage: ',sys.argv[0],' InputFrameworkJobReport.xml' exit(1) if( not os.path.exists(fjr)) : print 'Input file not found',fjr exit(2) filesRead=0 eventsRead=0 lumis = [] jobReport = readJobReport(fjr) if len(jobReport) > 0: inputFiles = jobReport[0].inputFiles for inputFile in inputFiles: # Accumulate the list of lum sections run over for run in inputFile.runs.keys(): for lumi in inputFile.runs[run]: lumis.append((run, lumi)) filesRead+=1 eventsRead+=int(inputFile['EventsRead']) #print jobReport[0].inputFiles,'\n' else: print "failed to read Job Report",fjr pass lumiList = LumiList(lumis = lumis) compactList = lumiList.getCompactList() lumiFilename = 'lumiSummary.json' lumiSummary = open(lumiFilename, 'w') json.dump(compactList, lumiSummary) lumiSummary.write('\n') lumiSummary.close() msg = "Total Events read: %s\n" % eventsRead msg += "Total Files read: %s\n" % filesRead msg += "Luminosity section summary file: %s\n" % lumiFilename if (os.path.exists(lumiFilename)) : totalDeliveredLS, totalDelivered, totalSelectedLS, totalRecorded = getLumi(lumiFilename) msg += ' LS (Delivered/Recorded): ( %i / %i )' % (totalDeliveredLS,totalSelectedLS) msg += ' Lumi (Delivered/Recorded): ( %.3f / %.3f ) /nb \n' % (totalDelivered/1.E3,totalRecorded/1.E3) print msg exit(0)