9 parser = argparse.ArgumentParser()
10 parser.add_argument(
"-j",
"--jsonpath")
11 args = parser.parse_args()
14 period_name =
'Run2015D' 17 with open(args.jsonpath)
as jfile:
18 jdata = json.load(jfile)
20 lumifile = args.jsonpath.replace(
'golden_Cert',
'lumi').replace(
'.json',
'.txt')
21 if (
not os.path.exists(
'lumi.csv')):
22 print "First obtain luminosity for each run with following command (requires brilcalc installation):" 23 print "brilcalc lumi --normtag /afs/cern.ch/user/c/cmsbril/public/normtag_json/OfflineNormtagV1.json -i "+args.jsonpath+
" -u /pb -o "+lumifile
26 with open(lumifile)
as lfile:
28 if line[0]==
'#':
continue 29 lumidict[line.split(
':')[0]] = line.split(
',')[-1]
34 runs = sorted(jdata.keys())
36 newjson[run] = jdata[run]
37 lumi = lumi + float(lumidict[run])
38 if (lumi > pb_per_json)
or run==runs[-1]:
39 subjson = args.jsonpath.split(
'golden_')[0]+
'subgolden_'+period_name+str(ijson)+
'.json' 40 json.dump(newjson, open(subjson,
'w'), sort_keys=
True)
41 with open(subjson)
as fsubj:
42 data = fsubj.readlines()
43 with open(subjson+
'.tmp',
'w')
as tmp_fsubj:
45 tmp_fsubj.write(line.replace(
', "',
',\n "'))
47 os.rename(subjson+
'.tmp', subjson)
48 print "Wrote json %s with lumi %.2f" % (subjson, lumi)