-
Notifications
You must be signed in to change notification settings - Fork 6
/
bestlumi.py
73 lines (62 loc) · 1.9 KB
/
bestlumi.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
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
# A helper script for making the best lumi files. Run this on an
# output file from lumicalc and it will make a JSON snippet containing
# the run/lumisections present in the data. Also substitutes the
# luminometer names with their normtags.
import os, sys, re
import csv
import argparse
get_input_name = lambda base: base
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("basename", help="Input basename")
parser.add_argument("--delimiter", default=",", help="The separator for each row's data")
return parser.parse_args()
def main():
options = parse_args()
base_name = options.basename
input_filename = get_input_name(base_name)
lastdet=""
lastrow=""
firstls=""
lastls=""
lastrun=""
first=True
with open(input_filename) as csv_input:
#, \
#open(output_filename, 'w') as csv_output:
#reader = csv.reader(csv_input, delimiter=options.delimiter)
reader = csv.reader(csv_input, delimiter=",")
for row in reader:
if len(row)>7 and row[3]=="STABLE BEAMS":
fr=row[0].split(":")
run=fr[0]
fill=fr[1]
lsls=row[1].split(":")
ls=lsls[0]
cmsls=lsls[1]
thisdet=row[8]
if thisdet=="PLTZERO":
thisdet="pltzero16v3"
if thisdet=="BCM1F":
thisdet="bcm1f16v1"
if thisdet=="HFOC":
thisdet="hfoc16v3b"
if first and cmsls!="0":
firstls=ls
lastls=ls
lastrun=run
lastdet=thisdet
first=False
elif cmsls !="0" and (run!=lastrun or thisdet !=lastdet or int(ls)!=(int(lastls)+1) ):
output="[\""+str(lastdet)+"\",{\""+str(lastrun)+"\":[["+str(firstls)+","+str(lastls)+"]]}],"
#print "[\"",lastdet,"\",{\"",lastrun,"\":[[",firstls,",",lastls,"]]}],"
print output
lastrun=run
lastdet=thisdet
firstls=ls
lastls=ls
output="[\""+str(lastdet)+"\",{\""+str(lastrun)+"\":[["+str(firstls)+","+str(lastls)+"]]}]"
print output
if __name__ == "__main__":
main()