CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DataFormats/FWLite/scripts/edmLumisInFiles.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 from FWCore.PythonUtilities.LumiList   import LumiList
00004 import optparse
00005 
00006 
00007 if __name__ == '__main__':
00008     
00009     parser = optparse.OptionParser ("Usage: %prog [--options] edm1.root [edm2.root...]",
00010                                     description='Runs over input EDM files and prints out a list of contained lumi sections')
00011     parser.add_option ('--intLumi', dest='intLumi', action='store_true',
00012                        help='print out total recorded and delivered integrated luminosity')
00013     parser.add_option ('--output', dest='output', type='string',
00014                        help='save lumi sections output to file OUTPUT')
00015     (options, args) = parser.parse_args()
00016     # put this here after parsing the arguments since ROOT likes to
00017     # grab command line arguments even when it shouldn't.
00018     from DataFormats.FWLite import Lumis, Handle
00019     if not args:
00020         raise RuntimeError, "Must provide at least one input file"
00021 
00022     # do we want to get the luminosity summary?
00023     if options.intLumi:
00024         handle = Handle ('LumiSummary')
00025         label  = ('lumiProducer')
00026     else:
00027         handle, lable = None, None
00028 
00029     runsLumisDict = {}
00030     lumis = Lumis (args)
00031     delivered = recorded = 0
00032     for lum in lumis:
00033         runList = runsLumisDict.setdefault (lum.aux().run(), [])
00034         runList.append( lum.aux().id().luminosityBlock() )
00035         # get the summary and keep track of the totals
00036         if options.intLumi:
00037             lum.getByLabel (label, handle)
00038             summary = handle.product()
00039             delivered += summary.avgInsDelLumi()
00040             recorded  += summary.avgInsRecLumi()
00041 
00042     # print out lumi sections in JSON format
00043     jsonList = LumiList (runsAndLumis = runsLumisDict)
00044     if options.output:
00045         jsonList.writeJSON (options.output)
00046     else:
00047         print jsonList
00048 
00049     # print out integrated luminosity numbers if requested
00050     if options.intLumi:
00051         print "\nNote: These numbers should be considered approximate.  For official numbers, please use lumiCalc.py"
00052         print "delivered %.1f mb,  recorded %.1f mb" % \
00053               (delivered, recorded)