Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-03 02:23:28

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