Changeset 13789 for fact/tools/PyDimCtrl/service.py
- Timestamp:
- 05/18/12 23:16:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/PyDimCtrl/service.py
r13770 r13789 1 #!/usr/bin/python -tt 2 from fpydim import * 1 #!/usr/bin/python -tti 2 #from fpydim import * 3 4 3 5 4 6 def IsReadyForDataTaking( verbose = True ): 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 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 31 33 32 34 def StopTracking( verbose = True ): 33 34 35 36 37 38 39 40 41 42 43 44 45 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 46 48 47 49 def TakeDataRun( verbose = True ): 48 fad = fad_control 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 64 66 65 67 def TrackSource( Shift=0.6, Angle=50, SrcName='Crab', verbose=True): 66 67 68 69 70 71 72 73 74 75 76 77 78 79 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 80 82 81 83 def WaitForTracking( CalmDownTime = 30, verbose = True): 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 zoreturn True84 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 99 101 100 102 def PrepareBias( verbose = True): 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 msg("waiting 45sec...") 121 122 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 123 125 124 126 def TakePedestalOnRun( verbose = True ): 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 141 143 def TakeExtLpRun( verbose = True ): 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 zoreturn True144 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 157 159 158 160 def TakeData( verbose = True): 159 160 161 162 163 164 165 166 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() 167 169 168 170 def Take( time=0, events=0, runtype='drs-pedestal', verbose=True): 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 187 189 188 190 def TakeDrsCalibration( verbose = True): 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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') 210 212 211 213 def BlinkenLights(verbose = True): 212 213 214 215 216 217 218 219 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) 220 222 221 223 def TakeAmplCalib( roi=1024, verbose=True): 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 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') 245 247 246 248 def 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') 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: 262 class 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 302 intro = INTRO() 257 303 258 304 if __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() 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 TracChangeset
for help on using the changeset viewer.