CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
edmLumisInFiles.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 from FWCore.PythonUtilities.LumiList import LumiList
4 import optparse
5 
6 
7 if __name__ == '__main__':
8 
9  parser = optparse.OptionParser ("Usage: %prog [--options] edm1.root [edm2.root...]",
10  description='Runs over input EDM files and prints out a list of contained lumi sections')
11  parser.add_option ('--intLumi', dest='intLumi', action='store_true',
12  help='print out total recorded and delivered integrated luminosity')
13  parser.add_option ('--output', dest='output', type='string',
14  help='save lumi sections output to file OUTPUT')
15  (options, args) = parser.parse_args()
16  # put this here after parsing the arguments since ROOT likes to
17  # grab command line arguments even when it shouldn't.
18  from DataFormats.FWLite import Lumis, Handle
19  if not args:
20  raise RuntimeError, "Must provide at least one input file"
21 
22  # do we want to get the luminosity summary?
23  if options.intLumi:
24  handle = Handle ('LumiSummary')
25  label = ('lumiProducer')
26  else:
27  handle, lable = None, None
28 
29  runsLumisDict = {}
30  lumis = Lumis (args)
31  delivered = recorded = 0
32  for lum in lumis:
33  runList = runsLumisDict.setdefault (lum.aux().run(), [])
34  runList.append( lum.aux().id().luminosityBlock() )
35  # get the summary and keep track of the totals
36  if options.intLumi:
37  lum.getByLabel (label, handle)
38  summary = handle.product()
39  delivered += summary.avgInsDelLumi()
40  recorded += summary.avgInsRecLumi()
41 
42  # print out lumi sections in JSON format
43  jsonList = LumiList (runsAndLumis = runsLumisDict)
44  if options.output:
45  jsonList.writeJSON (options.output)
46  else:
47  print jsonList
48 
49  # print out integrated luminosity numbers if requested
50  if options.intLumi:
51  print "\nNote: These numbers should be considered approximate. For official numbers, please use lumiCalc.py"
52  print "delivered %.1f mb, recorded %.1f mb" % \
53  (delivered, recorded)