-
Notifications
You must be signed in to change notification settings - Fork 2
/
bolo8_cal_cap_loop.py
executable file
·152 lines (118 loc) · 4.1 KB
/
bolo8_cal_cap_loop.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
""" bolo8_cal_cap_loop.py ..
run a bolo8 calibration, store to MDSplus ODD shot
run a bolo8 capture, store to MDSplus EVEN shot
ASSUME : each uut has a tree of the same name
Script calls into MDSplus to increment shots, so it MUST run on the MDSplus server
Usage
./bolo8_cal_cap_loop.py --shots=1 acq2106_059
run one cal, one capture
./bolo8_cal_cap_loop.py --shots=100 acq2106_059
run 100 cal/captures
./bolo8_cal_cap_loop.py --cap=0 --shots=1 acq2106_059
run one cal
./bolo8_cal_cap_loop.py --cal=0 --shots=100 acq2106_059
run 100 captures
sage: bolo8_cal_cap_loop.py [-h] [--cap CAP] [--cal CAL] [--post POST]
[--clk CLK] [--trg TRG] [--shots SHOTS]
uuts [uuts ...]
bolo8_cal_cap_loop
positional arguments:
uuts uut list
optional arguments:
-h, --help show this help message and exit
--cap CAP capture
--cal CAL calibrate
--post POST post trigger length
--clk CLK clk "int|ext SR [CR]"
--trg TRG trg "int|ext rising|falling"
--shots SHOTS set number of shots [1]
"""
import sys
import os
import acq400_hapi
import argparse
import time
USING_MDSPLUS=0
if USING_MDSPLUS:
from MDSplus import *
def odd(n):
return n%2 == 1
def even(n):
return n%2 == 0
__shot = 0
def null_set_next_shot(args, flavour, info):
global __shot
__shot += 1
return __shot
def mds_set_next_shot(args, flavour, info):
old_shots = [Tree.getCurrent(u) for u in args.uuts]
sn = max(old_shots) + 1
# this is only going to run once
while not flavour(sn):
sn += 1
for tree in args.uuts:
print("Setting {} for {} to shot {}".format(tree, info, sn))
Tree.setCurrent(tree, sn)
Tree(tree, -1).createPulse(sn)
return sn
if USING_MDSPLUS:
set_next_shot = mds_set_next_shot
else:
set_next_shot = null_set_next_shot
def run_cal1(uut, shot):
txt = uut.run_service(acq400_hapi.AcqPorts.BOLO8_CAL, eof="END")
logfile = "{}/cal_{}.log".format(os.getenv("{}_path".format(uut.uut), "."), shot)
try:
with open(logfile, 'w') as log:
print("logging to {}".format(logfile))
log.write(txt)
except IOError as e:
logfile = "./cal_{}.log".format(shot)
with open(logfile, 'w') as log:
print("logging to {}".format(logfile))
log.write(txt)
def run_cal(args):
uuts = [acq400_hapi.Acq400(u) for u in args.uuts]
shot = set_next_shot(args, odd, "Cal")
# hmm, running the cal serialised?. not cool, parallelize me ..
for u in uuts:
run_cal1(u, shot)
# unfortunately this sleep seems to be necessary, else subsequent shot HANGS at 21760
time.sleep(2)
def run_capture(args):
uuts = [acq400_hapi.Acq400(u) for u in args.uuts]
shot = set_next_shot(args, even, "Cap")
for u in uuts:
u.s0.transient = "POST={} SOFT_TRIGGER=0".format(args.post)
for u in uuts:
u.s0.set_arm = '1'
for u in uuts:
u.statmon.wait_armed()
if args.trg == "int":
# again, not really parallel
for u in uuts:
print("trigger")
u.s0.soft_trigger = '1'
for u in uuts:
u.statmon.wait_stopped()
def run_shots(args):
for shot in range(1, args.shots+1):
print("Cycle {}".format(shot))
if args.cal:
run_cal(args)
if args.cap:
run_capture(args)
def run_main():
parser = argparse.ArgumentParser(description='bolo8_cal_cap_loop')
parser.add_argument('--cap', default=1, type=int, help="capture")
parser.add_argument('--cal', default=1, type=int, help="calibrate")
parser.add_argument('--post', default=100000, help="post trigger length")
parser.add_argument('--clk', default="int 1000000", help='clk "int|ext SR [CR]"')
parser.add_argument('--trg', default="int", help='trg "int|ext rising|falling"')
parser.add_argument('--shots', default=1, type=int, help='set number of shots [1]')
parser.add_argument('uuts', nargs='+', help="uut list")
run_shots(parser.parse_args())
# execution starts here
if __name__ == '__main__':
run_main()