-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonrunsel.py
62 lines (46 loc) · 1.38 KB
/
jsonrunsel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
import sys,ConfigParser,os,string,commands,time,re
# for json support
try: # FUTURE: Python 2.6, prior to 2.6 requires simplejson
import json
except:
try:
import simplejson as json
except:
print "Please use lxplus or set an environment (for example crab) with json lib available"
sys.exit(1)
#######################################################################################
#main starts here#
# reading config file
if len(sys.argv)!=5:
print "Usage: ",sys.argv[0],"<runmin> <runmax> <oldjson> <filteredjson>"
sys.exit(1)
RUNMINstr=sys.argv[1]
RUNMAXstr=sys.argv[2]
JSON=sys.argv[3]
JSONNEW=sys.argv[4]
if not RUNMINstr.isdigit():
print "RUNMIN paramente not understood:"+RUNMINstr
sys.exit(1)
if not RUNMAXstr.isdigit():
print "RUNMIN paramente not understood:"+RUNMINstr
sys.exit(1)
RUNMIN=int(RUNMINstr)
RUNMAX=int(RUNMAXstr)
if RUNMIN>RUNMAX:
print "RUNMIN is > than RUNMAX"
sys.exit(1)
jsondict={}
jsonfiltered={}
# read json file
jsonfile=file(JSON,'r')
jsondict = json.load(jsonfile)
for run in jsondict.keys():
print "Reading run: "+run
if int(run)>=RUNMIN and int(run)<=RUNMAX:
jsonfiltered[run]=jsondict[run]
print "-----------> accepted"
newfile = open(JSONNEW, 'w')
json.dump(jsonfiltered, newfile)
newfile.close()
print "New filtered json file produced in: "+JSONNEW