CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/RecoLuminosity/LumiDB/scripts/csvLumiCalc.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import re
00005 import optparse
00006 
00007 if __name__ == '__main__':
00008 
00009 
00010     parser = optparse.OptionParser('Usage: %prog lumi.csv')
00011 
00012     (options, args) = parser.parse_args()
00013 
00014     if len (args) != 1:
00015         print "You must provide a CSV file\n"
00016         parser.print_help()
00017         sys.exit()
00018 
00019     sepRE = re.compile (r'[\s,;:]+')
00020     totDelivered = totRecorded = 0.
00021     events = open (args[0], 'r')
00022     minRun  = maxRun  = 0
00023     minLumi = maxLumi = 0
00024     for line in events:
00025         pieces = sepRE.split (line.strip())
00026         if len (pieces) < 4:
00027                 continue
00028         try:
00029             run,       lumi     = int  ( pieces[0] ), int  ( pieces[1] )
00030             delivered, recorded = float( pieces[2] ), float( pieces[3] )
00031         except:
00032             continue
00033         if not minRun or run < minRun:
00034             minRun  = run
00035             minLumi = lumi
00036         if run == minRun and lumi < minLumi:
00037             minLumi = lumi
00038         if not maxRun or run > maxRun:
00039             maxRun  = run
00040             maxLumi = lumi
00041         if run == maxRun and lumi > maxLumi:
00042             maxLumi = lumi
00043         totDelivered += delivered
00044         totRecorded  += recorded
00045     print "Runs (%d, %d) to (%d, %d)" % (minRun, minLumi, maxRun, maxLumi)
00046     unit = "ub"
00047     if totRecorded > 1000.:
00048         totRecorded  /= 1000.
00049         totDelivered /= 1000.
00050         unit = "nb"
00051     if totRecorded > 1000.:
00052         totRecorded  /= 1000.
00053         totDelivered /= 1000.
00054         unit = "pb"
00055     if totRecorded > 1000.:
00056         totRecorded  /= 1000.
00057         totDelivered /= 1000.
00058         unit = "fb"
00059     print "Total Delivered %.1f 1/%s  Total Recorded %.1f 1/%s" % \
00060           (totDelivered, unit, totRecorded, unit)
00061