CMS 3D CMS Logo

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