CMS 3D CMS Logo

csvLumiCalc.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import sys
5 import re
6 import optparse
7 
8 if __name__ == '__main__':
9 
10 
11  parser = optparse.OptionParser('Usage: %prog lumi.csv')
12 
13  (options, args) = parser.parse_args()
14 
15  if len (args) != 1:
16  print("You must provide a CSV file\n")
17  parser.print_help()
18  sys.exit()
19 
20  sepRE = re.compile (r'[\s,;:]+')
21  totDelivered = totRecorded = 0.
22  events = open (args[0], 'r')
23  minRun = maxRun = 0
24  minLumi = maxLumi = 0
25  for line in events:
26  pieces = sepRE.split (line.strip())
27  if len (pieces) < 4:
28  continue
29  try:
30  run, lumi = int ( pieces[0] ), int ( pieces[1] )
31  delivered, recorded = float( pieces[2] ), float( pieces[3] )
32  except:
33  continue
34  if not minRun or run < minRun:
35  minRun = run
36  minLumi = lumi
37  if run == minRun and lumi < minLumi:
38  minLumi = lumi
39  if not maxRun or run > maxRun:
40  maxRun = run
41  maxLumi = lumi
42  if run == maxRun and lumi > maxLumi:
43  maxLumi = lumi
44  totDelivered += delivered
45  totRecorded += recorded
46  print("Runs (%d, %d) to (%d, %d)" % (minRun, minLumi, maxRun, maxLumi))
47  unit = "ub"
48  if totRecorded > 1000.:
49  totRecorded /= 1000.
50  totDelivered /= 1000.
51  unit = "nb"
52  if totRecorded > 1000.:
53  totRecorded /= 1000.
54  totDelivered /= 1000.
55  unit = "pb"
56  if totRecorded > 1000.:
57  totRecorded /= 1000.
58  totDelivered /= 1000.
59  unit = "fb"
60  print("Total Delivered %.1f 1/%s Total Recorded %.1f 1/%s" % \
61  (totDelivered, unit, totRecorded, unit))
62 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66