source: fact/tools/PyDimCtrl/service.py@ 13793

Last change on this file since 13793 was 13793, checked in by neise, 12 years ago
evolving
  • Property svn:executable set to *
File size: 9.1 KB
Line 
1#!/usr/bin/python -tti
2from fpydim import *
3
4
5
6def IsReadyForDataTaking( verbose = True ):
7 drive = drive_control
8 bias = bias_control
9 fad = fad_control
10
11 msg = MSG()
12 msg.output = verbose
13 msg("Checking if System isready for data taking... ")
14
15 ok = True
16 if not drive() == 7:
17 msg.warn( drive.state()[0] + " NOT ok")
18 ok = False
19 if not feedback() == 12:
20 msg.warn( feedback.state()[0] + " NOT ok")
21 ok = False
22 if not bias() == 9:
23 msg.warn( bias.state()[0] + " NOT ok")
24 ok = False
25 if not fad() == 4:
26 msg.warn( fad.state()[0] + " NOT ok")
27 ok = False
28
29 if ok:
30 msg.ok( " all ok " )
31
32 return ok
33
34def StopTracking( verbose = True ):
35 msg = MSG()
36 msg.output = verbose
37
38 # defining a shortcut
39 drive = drive_control
40
41 drive.stop()
42 if not drive.wait(5, 10):
43 msg.warn("drive did not reach state 5 after 10 seconds")
44 msg.warn( drive.state()[0].rstrip('\x00') )
45 return False
46
47 return True
48
49def TakeDataRun( verbose = True ):
50 fad = fad_control
51 msg = MSG()
52 msg.output = verbose
53 if not IsReadyForDataTaking( verbose=False ):
54 msg.fail("System not Ready for DataTaking")
55 IsReadyForDataTaking( verbose=True )
56 return False
57 mcp.start(300,-1,'data\0')
58 if not fad.wait(8, 10):
59 msg.warn("FAD not in Writing Data after 10seconds")
60 return False
61 msg("... taking data: 300 seconds - normal data run")
62 if not fad.wait(4, 330):
63 msg.warn("FAD did not return to Connected, after 330 seconds")
64 return False
65 return True
66
67def TrackSource( Shift=0.6, Angle=50, SrcName='Crab', verbose=True):
68 drive = drive_control
69
70 msg = MSG()
71 msg.output = verbose
72
73 if not drive.wait(5, 10):
74 msg.warn("drive not ready after 10sec")
75 msg.warn( drive.state()[0].rstrip('\x00') )
76 return False
77
78 SrcName += '\0'
79 drive.track_source( Shift, Angle, SrcName)
80
81 return True
82
83def WaitForTracking( CalmDownTime = 30, verbose = True):
84 drive = drive_control
85
86 msg = MSG()
87 msg.output = verbose
88
89 if not drive.wait(6, 10):
90 msg.warn("drive not in state moving after 10sec")
91 return False
92
93 if not drive.wait(7, 10):
94 msg.warn("drive not in state Tracking after 10sec")
95 return False
96
97 msg("waiting "+str(CalmDownTime)\
98 +"sec for drive to calm down and tracking to be stable")
99 time.sleep(CalmDownTime)
100 return True
101
102def PrepareBias( verbose = True):
103 msg = MSG()
104 msg.output = verbose
105 bias = bias_control
106
107 if feedback() != 12:
108 msg.warn("feedback is not in Current Control")
109 return False
110
111 bias.set_global_dac(1)
112 if not bias.wait(9, 10):
113 msg.warn("bias not in Voltage ON after 10sec")
114 return False
115 if not bias.wait(5, 10):
116 msg.warn("bias not Ramping after 10sec")
117 return False
118 if not bias.wait(9, 30):
119 msg.warn("bias not fully ramped up after 30sec")
120 return False
121
122 msg("waiting 45sec...")
123 time.sleep(45)
124 return True
125
126def TakePedestalOnRun( verbose = True ):
127 msg = MSG()
128 msg.output = verbose
129 if not IsReadyForDataTaking( verbose=False ):
130 msg.fail("System not Ready for DataTaking")
131 IsReadyForDataTaking( verbose=True )
132 return False
133 mcp.start(-1,1000,'pedestal\0')
134 if not fad.wait(8, 10):
135 msg.warn("FAD not in Writing Data after 10seconds")
136 return False
137 msg("... taking ped: 1000evts @25Hz")
138 if not fad.wait(4, 50):
139 msg.warn("FAD did not return to Connected, after 50 seconds")
140 return False
141 return True
142
143def TakeExtLpRun( verbose = True ):
144 msg = MSG()
145 msg.output = verbose
146 if not IsReadyForDataTaking( verbose=False ):
147 msg.fail("System not Ready for DataTaking")
148 IsReadyForDataTaking( verbose=True )
149 return False
150 mcp.start(-1,1000,'light-pulser-ext\0')
151 if not fad.wait(8, 10):
152 msg.warn("FAD not in Writing Data after 10seconds")
153 return False
154 msg("... taking light-pulser-ext: 1000evts @25Hz")
155 if not fad.wait(4, 50):
156 msg.warn("FAD did not return to Connected, after 50 seconds")
157 return False
158 return True
159
160def TakeData( verbose = True):
161 msg = MSG()
162 msg.output = verbose
163 TakePedestalOnRun()
164 TakeExtLpRun()
165 for i in range(4):
166 i +=1
167 msg("Taking Data Run "+str(i)+" of 4")
168 TakeDataRun()
169
170def Take( time=0, events=0, runtype='drs-pedestal', verbose=True):
171 msg = MSG()
172 msg.output = verbose
173 fad = fad_control
174 runtype += '\0'
175 if not fad.wait(4, 10):
176 msg.warn("fad not connected after 10sec")
177 return False
178 mcp.start( time, events, runtype)
179 if not fad.wait(8, 30):
180 msg.warn("fad not Writing Data after 30sec")
181 return False
182 timeout = float('inf')
183 if time != -1:
184 timeout = time*1.1
185 if not fad.wait(4, timeout):
186 msg.warn("Data Writing not finished after "+str(timeout)+"sec")
187 return False
188 return True
189
190def TakeDrsCalibration( verbose = True):
191 msg = MSG()
192 msg.output = verbose
193 bias = bias_control
194 fad = fad_control
195
196 bias.set_zero_voltage()
197 if not bias.wait(7, 10):
198 msg.warn("bias has not switched of after 10sec")
199 return False
200 fad.start_drs_calibration()
201 Take( -1, 1000, 'drs-pedestal')
202 Take( -1, 1000, 'drs-gain')
203 Take( -1, 1000, 'drs-pedestal')
204 fad.set_file_format(2)
205 Take( -1, 1000, 'drs-pedestal')
206 Take( -1, 1000, 'drs-time')
207 Take( -1, 1000, 'drs-time-upshifted')
208 fad.reset_secondary_drs_baseline()
209 Take(-1, 1000, 'pedestal')
210 fad.set_file_format(2)
211 Take(-1, 1000, 'pedestal')
212
213def BlinkenLights(verbose = True):
214 msg = MSG(verbose)
215 fad = fad_control
216
217 for i in range(10):
218 fad.set_file_format(2)
219 time.sleep(1)
220 fad.set_file_format(0)
221 time.sleep(1)
222
223def TakeAmplCalib( roi=1024, verbose=True):
224 msg = MSG(verbose)
225 bias = bias_control
226 fad = fad_control
227 if (roi!=1024) and (roi!=300):
228 raise ValueError('roi must be 300 or 1024')
229 # I do not understand, why the out put needs to be ENABLED??
230 feedback.enable_output(0)
231 bias.set_zero_voltage()
232 bias.wait(7) # VoltageOff
233 fad.start_drs_calibration
234
235 Take(-1, 1000, 'drs-pedestal')
236 Take(-1, 1000, 'drs-gain')
237 if roi == 300:
238 Take(-1, 1000, 'pedestal')
239 if roi == 1024:
240 Take(-1, 1000, 'drs-pedestal')
241
242 fad.set_file_format(2)
243 if roi == 300:
244 Take(-1, 1000, 'pedestal')
245 if roi == 1024:
246 Take(-1, 1000, 'drs-pedestal')
247
248def TakeTimeCalib( verbose=True ):
249 msg = MSG( verbose )
250 feedback.enable_output(0)
251 if bias() != 7:
252 bias.set_zero_voltage()
253 if not bias.wait(7, 10):
254 msg.warn("bias not ramped down after 10sec")
255 return False
256 fad.set_file_format(2)
257 Take(-1, 1000, 'drs-time')
258 Take(-1, 1000, 'drs-time-upshifted')
259
260
261# create introduction:
262class INTRO(object):
263 def __init__(self):
264 # nothing to do
265 pass
266
267 def __repr__(self):
268 print "welcome to PyDimCtrl V0.1:"
269 print "--------------------------"
270 print "If the hardware is ON but not all the software is connected try:"
271 print " Connect()"
272 print "If all the programs are already up and running, you might want to"
273 print " TakeDrsAmplitudeCalibration(roi=1024) or "
274 print " TakeDrsAmplitudeCalibration(roi=300)"
275 print " i.e. ped, gain, trigger_offset + extra ped(for X-check)"
276 print " TakeDrsTimeCalibration( type='upshifted' ) or "
277 print " TakeDrsTimeCalibration( type='old' ) or "
278 print " "
279 print "In case you would like to ramp up the Bias voltage try:"
280 print " VoltageOn( mode='temperature' ) or"
281 print " VoltageOn( mode='current' ) or"
282 print " VoltageOn( mode='light_pulser' )"
283 print "Switch off with:"
284 print " VoltageOff()"
285 print ""
286 print "In case you would like a Watchdog to check, if the Voltage is up"
287 print "and the BiasCrate is not disconnected, then try:"
288 print " VoltageOn( mode='--see above--', Watchdog=True )"
289 print "PLEASE NOTE: The Watchdog will monitor the State of BIAS_CONTROL"
290 print "and in case of a connection loss, it will: "
291 print " * print a warning"
292 print " * issue a the RECONNECT command"
293 print " * issue SET_ZERO_VOLTAGE - since this is the only way to get referenced"
294 print " * Ramp up again, using the same settings as before"
295 print " * possible OverCurrent situation will be treated as usual"
296 print "The Watchdog will not react on any other state change, like OverCurrent or VoltageOff"
297 print ""
298 print ""
299 return ""
300
301
302intro = INTRO()
303
304if __name__ == '__main__':
305 print "welcome:"
306 print " type: intro"
307 print " for a short introduction"
308
309
310 #IsReadyForDataTaking()
311 #TrackSource( Shift=0.6, Angle=50, SrcName='Crab', verbose=True)
312 #WaitForTracking( CalmDownTime = 30, verbose = True)
313 #TakeDataRun()
314 #StopTracking()
Note: See TracBrowser for help on using the repository browser.