Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:10

0001 #! /usr/bin/env python3
0002 
0003 from FWCore.PythonUtilities.LumiList import LumiList
0004 from argparse import ArgumentParser
0005 
0006 if __name__ == '__main__':
0007     parser = ArgumentParser(description='Runs over input EDM files and prints out a list of contained lumi sections')
0008     parser.add_argument('--intLumi', dest='intLumi', action='store_true',
0009                         help='print out total recorded and delivered integrated luminosity')
0010     parser.add_argument('--output', dest='output', type=str,
0011                         help='save lumi sections output to file OUTPUT')
0012     parser.add_argument("edm", metavar="edm.root", type=str, nargs='+')
0013     options = parser.parse_args()
0014     # put this here after parsing the arguments since ROOT likes to
0015     # grab command line arguments even when it shouldn't.
0016     from DataFormats.FWLite import Lumis, Handle
0017 
0018     # do we want to get the luminosity summary?
0019     if options.intLumi:
0020         handle = Handle ('LumiSummary')
0021         label  = ('lumiProducer')
0022     else:
0023         handle, lable = None, None
0024 
0025     runsLumisDict = {}
0026     lumis = Lumis (options.edm)
0027     delivered = recorded = 0
0028     for lum in lumis:
0029         runList = runsLumisDict.setdefault (lum.aux().run(), [])
0030         runList.append( lum.aux().id().luminosityBlock() )
0031         # get the summary and keep track of the totals
0032         if options.intLumi:
0033             lum.getByLabel (label, handle)
0034             summary = handle.product()
0035             delivered += summary.avgInsDelLumi()
0036             recorded  += summary.avgInsRecLumi()
0037 
0038     # print out lumi sections in JSON format
0039     jsonList = LumiList (runsAndLumis = runsLumisDict)
0040     if options.output:
0041         jsonList.writeJSON (options.output)
0042     else:
0043         print(jsonList)
0044 
0045     # print out integrated luminosity numbers if requested
0046     if options.intLumi:
0047         print("\nNote: These numbers should be considered approximate.  For official numbers, please use lumiCalc.py")
0048         print("delivered %.1f mb,  recorded %.1f mb" % \
0049               (delivered, recorded))