ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/ForwardAnalysis/Scripts/scripts/countLumisFromJSON.py
Revision: 1.2
Committed: Sun Sep 18 16:51:30 2011 UTC (13 years, 7 months ago) by antoniov
Content type: text/x-python
Branch: MAIN
CVS Tags: antoniov-forwardAnalysis-Oct072011-v1, sfonseca_10_04_2011, antoniov-forwardAnalysis-Sep182011-v1, HEAD
Changes since 1.1: +2 -2 lines
Log Message:
update

File Contents

# Content
1 #! /usr/bin/env python
2
3 import json
4 import sys
5 import optparse
6
7 def countLumisFromJSON(filename,runMin,runMax):
8 jsonFile = open(filename)
9 jsonOut = json.load(jsonFile)
10 runList = [int(key) for key in jsonOut if int(key) >= runMin and int(key) <= runMax]
11 runList.sort()
12
13 totalNumberLumis = 0
14 for run in runList:
15 countLumi = 0
16 for pair in jsonOut[str(run)]:
17 nLumis = pair[-1] - pair[0] + 1
18 countLumi += nLumis
19 print "Run",run,"-->",countLumi,jsonOut[str(run)]
20 totalNumberLumis += countLumi
21
22 print "Total number of lumis =",totalNumberLumis,
23
24 if __name__ == '__main__':
25 parser = optparse.OptionParser(usage="usage: %prog [options]")
26 parser.add_option("-f","--file", dest="filename", metavar="FILE", help="read JSON file FILE")
27 parser.add_option("--runMin", dest="runMin", type="int", default=1, metavar="RUN", help="read info from RUN")
28 parser.add_option("--runMax", dest="runMax", type="int", default=9999999, metavar="RUN", help="read info up to RUN")
29
30 (input, args) = parser.parse_args()
31
32 if not input.filename: parser.error('must set input JSON file')
33
34 countLumisFromJSON(filename=input.filename,
35 runMin=input.runMin,
36 runMax=input.runMax)
37
38 sys.exit(0)