ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/FGolf/Tools/compareJSON.py
Revision: 1.1
Committed: Sun Aug 29 18:25:19 2010 UTC (14 years, 8 months ago) by fgolf
Content type: text/x-python
Branch: MAIN
CVS Tags: ss_summer2011approvalV2, ss_summer2011approval, synchMay2011v1, ss20May2011, ss2010_10_06, fkwsynch3pbv2, fkw_3pb_samesign_synch, HEAD
Log Message:
some tools useful for a variety of studies

File Contents

# Content
1 #!/usr/bin/env python
2
3 import sys,os,json
4
5 def convertRange(runs):
6 result = {}
7 for run in runs.keys():
8 tmp = []
9 for lumirange in runs[run]:
10 tmp.extend(range(lumirange[0],lumirange[1]+1))
11 result[run] = tmp
12 return result
13
14 one = json.load(open(sys.argv[1]))
15 two = json.load(open(sys.argv[2]))
16
17 sorted_runs_one = one.keys()
18 sorted_runs_one.sort()
19
20 sorted_runs_two = two.keys()
21 sorted_runs_two.sort()
22
23 runInBoth = []
24 runInNone = []
25
26 for run in sorted_runs_one:
27 if run in sorted_runs_two:
28 if run not in runInBoth:
29 runInBoth.append(run)
30 else :
31 if run not in runInNone:
32 runInNone.append(run)
33
34 for run in sorted_runs_two:
35 if run in sorted_runs_one:
36 if run not in runInBoth:
37 runInBoth.append(run)
38 else :
39 if run not in runInNone:
40 runInNone.append(run)
41
42 if len(runInNone) > 0 :
43 print ''
44 print 'Following runs are not in both files:'
45 print ','.join(runInNone)
46 print ''
47 else :
48 print ''
49 print 'Both files contain the same runs!'
50 print ''
51
52 oneArray = convertRange(one)
53 twoArray = convertRange(two)
54
55 fileOneExcessLumi = {}
56 fileTwoExcessLumi = {}
57
58 for run in runInBoth:
59 # print 'one',run,oneArray[run]
60 # print 'two',run,twoArray[run]
61 for lumi in oneArray[run] :
62 if lumi not in twoArray[run] :
63 if run in fileOneExcessLumi.keys():
64 if lumi not in fileOneExcessLumi[run]:
65 fileOneExcessLumi[run].append(lumi)
66 else :
67 fileOneExcessLumi[run] = [lumi]
68 for lumi in twoArray[run] :
69 if lumi not in oneArray[run] :
70 if run in fileTwoExcessLumi.keys():
71 if lumi not in fileTwoExcessLumi[run]:
72 fileTwoExcessLumi[run].append(lumi)
73 else :
74 fileTwoExcessLumi[run] = [lumi]
75
76
77 fileOneExcessLumiSortedRuns = fileOneExcessLumi.keys()
78 fileOneExcessLumiSortedRuns.sort()
79 if len(fileOneExcessLumiSortedRuns) > 0:
80 print ''
81 print 'File one contains these excess lumi sections:'
82 for run in fileOneExcessLumiSortedRuns:
83 print 'run:',run,'lumi sections:',fileOneExcessLumi[run]
84 print ''
85 else:
86 print ''
87 print 'File one does not contain any excess lumi sections!'
88 print ''
89 fileTwoExcessLumiSortedRuns = fileTwoExcessLumi.keys()
90 fileTwoExcessLumiSortedRuns.sort()
91 if len(fileTwoExcessLumiSortedRuns) > 0:
92 print ''
93 print 'File two contains these excess lumi sections:'
94 for run in fileTwoExcessLumiSortedRuns:
95 print 'run:',run,'lumi sections:',fileTwoExcessLumi[run]
96 print ''
97 else:
98 print ''
99 print 'File one does not contain any excess lumi sections!'
100 print ''
101
102