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

Last change on this file since 13770 was 13770, checked in by neise, 12 years ago
initial commit
  • Property svn:executable set to *
File size: 6.3 KB
Line 
1#!/usr/bin/python -tt
2 from fpydim import *
3
4def IsReadyForDataTaking( verbose = True ):
5 drive = drive_control
6 bias = bias_control
7 fad = fad_control
8
9 msg = MSG()
10 msg.output = verbose
11 msg("Checking if System isready for data taking... ")
12
13 ok = True
14 if not drive() == 7:
15 msg.warn( drive.state()[0] + " NOT ok")
16 ok = False
17 if not feedback() == 12:
18 msg.warn( feedback.state()[0] + " NOT ok")
19 ok = False
20 if not bias() == 9:
21 msg.warn( bias.state()[0] + " NOT ok")
22 ok = False
23 if not fad() == 4:
24 msg.warn( fad.state()[0] + " NOT ok")
25 ok = False
26
27 if ok:
28 msg.ok( " all ok " )
29
30 return ok
31
32def StopTracking( verbose = True ):
33 msg = MSG()
34 msg.output = verbose
35
36 # defining a shortcut
37 drive = drive_control
38
39 drive.stop()
40 if not drive.wait(5, 10):
41 msg.warn("drive did not reach state 5 after 10 seconds")
42 msg.warn( drive.state()[0].rstrip('\x00') )
43 return False
44
45 return True
46
47def TakeDataRun( verbose = True ):
48 fad = fad_control
49 msg = MSG()
50 msg.output = verbose
51 if not IsReadyForDataTaking( verbose=False ):
52 msg.fail("System not Ready for DataTaking")
53 IsReadyForDataTaking( verbose=True )
54 return False
55 mcp.start(300,-1,'data\0')
56 if not fad.wait(8, 10):
57 msg.warn("FAD not in Writing Data after 10seconds")
58 return False
59 msg("... taking data: 300 seconds - normal data run")
60 if not fad.wait(4, 330):
61 msg.warn("FAD did not return to Connected, after 330 seconds")
62 return False
63 return True
64
65def TrackSource( Shift=0.6, Angle=50, SrcName='Crab', verbose=True):
66 drive = drive_control
67
68 msg = MSG()
69 msg.output = verbose
70
71 if not drive.wait(5, 10):
72 msg.warn("drive not ready after 10sec")
73 msg.warn( drive.state()[0].rstrip('\x00') )
74 return False
75
76 SrcName += '\0'
77 drive.track_source( Shift, Angle, SrcName)
78
79 return True
80
81def WaitForTracking( CalmDownTime = 30, verbose = True):
82 drive = drive_control
83
84 msg = MSG()
85 msg.output = verbose
86
87 if not drive.wait(6, 10):
88 msg.warn("drive not in state moving after 10sec")
89 return False
90
91 if not drive.wait(7, 10):
92 msg.warn("drive not in state Tracking after 10sec")
93 return False
94
95 msg("waiting "+str(CalmDownTime)\
96 +"sec for drive to calm down and tracking to be stable")
97 time.sleep(CalmDownTime)
98 zoreturn True
99
100def PrepareBias( verbose = True):
101 msg = MSG()
102 msg.output = verbose
103 bias = bias_control
104
105 if feedback() != 12:
106 msg.warn("feedback is not in Current Control")
107 return False
108
109 bias.set_global_dac(1)
110 if not bias.wait(9, 10):
111 msg.warn("bias not in Voltage ON after 10sec")
112 return False
113 if not bias.wait(5, 10):
114 msg.warn("bias not Ramping after 10sec")
115 return False
116 if not bias.wait(9, 30):
117 msg.warn("bias not fully ramped up after 30sec")
118 return False
119
120 msg("waiting 45sec...")
121 time.sleep(45)
122 return True
123
124def TakePedestalOnRun( verbose = True ):
125 msg = MSG()
126 msg.output = verbose
127 if not IsReadyForDataTaking( verbose=False ):
128 msg.fail("System not Ready for DataTaking")
129 IsReadyForDataTaking( verbose=True )
130 return False
131 mcp.start(-1,1000,'pedestal\0')
132 if not fad.wait(8, 10):
133 msg.warn("FAD not in Writing Data after 10seconds")
134 return False
135 msg("... taking ped: 1000evts @25Hz")
136 if not fad.wait(4, 50):
137 msg.warn("FAD did not return to Connected, after 50 seconds")
138 return False
139 return True
140
141def TakeExtLpRun( verbose = True ):
142 msg = MSG()
143 msg.output = verbose
144 if not IsReadyForDataTaking( verbose=False ):
145 msg.fail("System not Ready for DataTaking")
146 IsReadyForDataTaking( verbose=True )
147 return False
148 mcp.start(-1,1000,'light-pulser-ext\0')
149 if not fad.wait(8, 10):
150 msg.warn("FAD not in Writing Data after 10seconds")
151 return False
152 msg("... taking light-pulser-ext: 1000evts @25Hz")
153 if not fad.wait(4, 50):
154 msg.warn("FAD did not return to Connected, after 50 seconds")
155 return False
156 zoreturn True
157
158def TakeData( verbose = True):
159 msg = MSG()
160 msg.output = verbose
161 TakePedestalOnRun()
162 TakeExtLpRun()
163 for i in range(4):
164 i +=1
165 msg("Taking Data Run "+str(i)+" of 4")
166 TakeDataRun()
167
168def Take( time=0, events=0, runtype='drs-pedestal', verbose=True):
169 msg = MSG()
170 msg.output = verbose
171 fad = fad_control
172 runtype += '\0'
173 if not fad.wait(4, 10):
174 msg.warn("fad not connected after 10sec")
175 return False
176 mcp.start( time, events, runtype)
177 if not fad.wait(8, 30):
178 msg.warn("fad not Writing Data after 30sec")
179 return False
180 timeout = float('inf')
181 if time != -1:
182 timeout = time*1.1
183 if not fad.wait(4, timeout):
184 msg.warn("Data Writing not finished after "+str(timeout)+"sec")
185 return False
186 return True
187
188def TakeDrsCalibration( verbose = True):
189 msg = MSG()
190 msg.output = verbose
191 bias = bias_control
192 fad = fad_control
193
194 bias.set_zero_voltage()
195 if not bias.wait(7, 10):
196 msg.warn("bias has not switched of after 10sec")
197 return False
198 fad.start_drs_calibration()
199 Take( -1, 1000, 'drs-pedestal')
200 Take( -1, 1000, 'drs-gain')
201 Take( -1, 1000, 'drs-pedestal')
202 fad.set_file_format(2)
203 Take( -1, 1000, 'drs-pedestal')
204 Take( -1, 1000, 'drs-time')
205 Take( -1, 1000, 'drs-time-upshifted')
206 fad.reset_secondary_drs_baseline()
207 Take(-1, 1000, 'pedestal')
208 fad.set_file_format(2)
209 Take(-1, 1000, 'pedestal')
210
211def BlinkenLights(verbose = True):
212 msg = MSG(verbose)
213 fad = fad_control
214
215 for i in range(10):
216 fad.set_file_format(2)
217 time.sleep(1)
218 fad.set_file_format(0)
219 time.sleep(1)
220
221def TakeAmplCalib( roi=1024, verbose=True):
222 msg = MSG(verbose)
223 bias = bias_control
224 fad = fad_control
225 if (roi!=1024) and (roi!=300):
226 raise ValueError('roi must be 300 or 1024')
227 # I do not understand, why the out put needs to be ENABLED??
228 feedback.enable_output(0)
229 bias.set_zero_voltage()
230 bias.wait(7) # VoltageOff
231 fad.start_drs_calibration
232
233 Take(-1, 1000, 'drs-pedestal')
234 Take(-1, 1000, 'drs-gain')
235 if roi == 300:
236 Take(-1, 1000, 'pedestal')
237 if roi == 1024:
238 Take(-1, 1000, 'drs-pedestal')
239
240 fad.set_file_format(2)
241 if roi == 300:
242 Take(-1, 1000, 'pedestal')
243 if roi == 1024:
244 Take(-1, 1000, 'drs-pedestal')
245
246def TakeTimeCalib( verbose=True ):
247 msg = MSG( verbose )
248 feedback.enable_output(0)
249 if bias() != 7:
250 bias.set_zero_voltage()
251 if not bias.wait(7, 10):
252 msg.warn("bias not ramped down after 10sec")
253 return False
254 fad.set_file_format(2)
255 Take(-1, 1000, 'drs-time')
256 Take(-1, 1000, 'drs-time-upshifted')
257
258if __name__ == '__main__':
259 IsReadyForDataTaking()
260 TrackSource( Shift=0.6, Angle=50, SrcName='Crab', verbose=True)
261 WaitForTracking( CalmDownTime = 30, verbose = True)
262 TakeDataRun()
263 StopTracking()
Note: See TracBrowser for help on using the repository browser.