CMS 3D CMS Logo

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