test
CMS 3D CMS Logo

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