Changeset 14466 for fact/tools/PyDimCtrl/ScriptsForPyDimCtrl.py
- Timestamp:
- 10/04/12 19:04:19 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/PyDimCtrl/ScriptsForPyDimCtrl.py
r14464 r14466 13 13 14 14 report_length = 0 15 16 source_list = [ 17 ['Crab', 0.6, 50, -130], 18 ["1ES 2344+51.4", 0.6, 90, -90 ], 19 ["Mrk 501", 0.6, -22, -22+180 ], 20 ["Mrk 421", 0.6, 90, -90 ], 21 ["1ES 1218+304", 0.6, -5, -5+180 ], 22 ["1ES 1959+650", 0.6, 155, 155-180 ], 23 ["Dark Patch 2", 0.6, 90, -90 ], 24 ["Dark Patch 3", 0.6, 90, -90 ], 25 ["H 1426+428", 0.6, 90, -90 ], 26 ["IC 310", 0.6, -18, -18+180 ], 27 ["PKS 2155-304", 0.6, 90, -90 ] ] 28 29 sourcedict = {} 30 def make_sourcedict(): 31 for s in source_list: 32 sourcedict[s[0]] = {} 33 sourcedict[s[0]]['wobble_offset'] = s[1] 34 sourcedict[s[0]]['wobble_angle1'] = s[2] 35 sourcedict[s[0]]['wobble_angle2'] = s[3] 36 37 38 39 15 40 16 41 def wait_nice(self, state_num, timeout=None): … … 98 123 99 124 100 def IsReadyForDataTaking( ):125 def IsReadyForDataTaking( verbose=False ): 101 126 """ Checking the system statuses if they are ready for data taking 102 127 """ 103 104 print "--------------------------------------"105 print "Checking the system statuses of:"106 print "FEEDBACK, BIAS, FAD and DRIVE_CONTROL"107 print "--------------------------------------"108 109 print "...waiting for FEEDBACK"110 print " to be in state 12: CurrentControl"128 if verbose: 129 print "--------------------------------------" 130 print "Checking the system statuses of:" 131 print "FEEDBACK, BIAS, FAD and DRIVE_CONTROL" 132 print "--------------------------------------" 133 134 print "...waiting for FEEDBACK" 135 print " to be in state 12: CurrentControl" 111 136 feedback.wait(12) 112 137 113 print "...waiting for BIAS_CONTROL" 114 print " to be in state 9: VoltageOn" 138 if verbose: 139 print "...waiting for BIAS_CONTROL" 140 print " to be in state 9: VoltageOn" 115 141 bias_control.wait(9) 116 142 117 print "...waiting for FAD_CONTROL" 118 print " to be in state 4: Connected" 143 if verbose: 144 print "...waiting for FAD_CONTROL" 145 print " to be in state 4: Connected" 119 146 fad_control.wait(4) 120 147 121 print "...waiting for drive_CONTROL" 122 print " to be in state 8: Tracking" 148 if verbose: 149 print "...waiting for drive_CONTROL" 150 print " to be in state 8: Tracking" 123 151 drive_control.wait(8) 124 152 125 print "...system statuses OK" 126 print "--------------------------------------" 153 if verbose: 154 print "...system statuses OK" 155 print "--------------------------------------" 127 156 128 157 def NotReadyForDataTaking( servers_n_targets = [ (feedback, 12), … … 286 315 """ 287 316 runtype += '\0' 288 317 289 318 if verbose: 290 319 print ' taking', runtype,'. ', num_events, 'events in', time, 'seconds' … … 299 328 if verbose: 300 329 print '... done' 330 331 def TakeBetter( time, num_events, runtype, 332 Bias = None, 333 Drive = None, 334 335 verbose=False): 336 """ 337 """ 338 if Bias not in [None, 'On', 'Off']: 339 raise ValueError('Bias needs to be one of [None, 'On', 'Off']') 340 return False 341 342 343 runtype += '\0' 344 345 # FAD: 346 # 347 # It makes no sense to try to take data, when the FADs are not well connected. 348 # Also I think it makes no sense to start datataking, when FAD is in WritingData 349 # and when MCP is not in an Idle state... 350 # 351 # we will check if FAD is in Connected(4), if in Writing_Data(8), we will send: close_all_open_files() 352 # if in one of the configuring states(5,6,7) we will send reset_configure 353 # if in Connecting(3), we will try to find which board is making problems... 354 # and disconnect and connect it --> THREE TIMES 355 # if it doesn't help. 356 # we abort. 357 # 358 # 359 360 361 # FTM: 362 # the ftm is not so critcal, since it makes no problems normally... 363 # It can be in triggerON(4) or Idle(3) 364 # Connected(2) is not good here we need a power cycle 365 # Any of the Configured States (5,6,7) should be treated with reset_configure() 366 # 367 # we will anyway check if in Connected(2) before starting. 368 369 # DRIVE_CONTROL: 370 # in case *Drive* is a valid sourcename from sourcedict, 371 # we will give the command to point to that source in ON mode 372 # in case *Drive* is a tuple of ('sourcename', 1 || 2) 373 # We will point to that soource in wobble mode. 374 # 375 # If Drive is 'Stop. The Drive will be stopped 376 # 377 # In anycase The Drive will be checked for not beeing in the state ERROR 378 # in that case we will send DRIVE_CONTROL/STOP and the last tracking 379 # command or nothing in case Drive = 'Stop' 380 # 381 # In case Drive is None no commands will be send to DRIVE_CONTROL at allow 382 383 # RATE_CTRL 384 # 385 # Rate_control should be in Connected(4) and not lower 386 # 5,6,7 should not be the case ... STOP will help, I hope 387 # 388 # we will try to get it into Connected, by sending STOP once 389 # if not successful we abort 390 391 start_time = time.time() 392 duration = 10. 393 while fad_control.stn != 4: 394 if fad_control.stn in [5,6,7]: # Configure State --> Reset_Configure 395 fad_control.reset_configure() 396 elif fad_control.stn == 8: #WritingData --> Close_all_open_files() 397 fad_control.close_open_files() 398 elif fad_control.stn == 3: #Connecting --> try to find 'bad' board and reconnect 399 duration = 60. 400 print 'fad_control in state Connecting ... trying to find "bad" board' 401 print 'timeout increased to 60.sec' 402 conn = GetFadConnections() 403 bad = np.where( conn != 0x42 )[0] 404 print 'possible bad boards', bad 405 print 'disconnecting' 406 for b in bad: 407 fad_control.disconnect(b) 408 time.sleep(3.) 409 for b in bad: 410 fad_control.connect(b) 411 else: # really bad .. abort 412 print 'ERROR: FAD_CTRL in state', fad_control.stn, fad_control.sts 413 print 'I do not know how to treat that ... aborting' 414 return False 415 416 time.sleep(1.) 417 if time.time() - start_time > duration: 418 print 'Timeout during try to get FAD into Connected' 419 return False 420 421 # BIAS 422 # 423 # As well it makes no sense to try to take data, when the Bias control is in an 424 # undefined state. 425 # When *Bias* is 'On' we will take care that the Bias voltage is on, and stays on 426 # When *Bias* is 'Off' we will shut bias down and do nothing more 427 # When *Bias* is None -default- then no commands will be send to BiasCtrl 428 429 start_time = time.time() 430 duration = 20. 431 if Bias == 'On': 432 if (bias_control.voltage()[0:320].mean() > 60) and 433 ( (bias_control.stn == 5) or (bias_control.stn == 9) ) 434 435 elif Bias == 'Off': 436 437 438 if verbose: 439 print ' taking', runtype,'. ', num_events, 'events in', time, 'seconds' 440 mcp.start(time, num_events, runtype) 441 442 if verbose: 443 print '...waiting for FAD to be in state 8: Writing Data' 444 fad_control.wait(8) # Writing Data 445 if verbose: 446 print '...waiting for FAD to be in state 4: Connected' 447 fad_control.wait_nice(4) # Connected 448 if verbose: 449 print '... done' 450 301 451 302 452 … … 464 614 # this 10sec wait is needed in order for the bias not to disconect all the time... 465 615 print " ... current calibration done" 466 time.sleep(10)616 #time.sleep(10) 467 617 468 618 print " switching off bias" 469 619 bias_control.set_zero_voltage() 470 time.sleep(5)620 #time.sleep(5) 471 621 print " ...waiting for BIAS to be in state 7: VoltageOff" 472 622 bias_control.wait(7) … … 486 636 487 637 fad_control.start_drs_calibration() 488 time.sleep(0.5)638 #time.sleep(0.5) 489 639 Take( -1, 1000, 'drs-pedestal') 490 640 … … 803 953 print '... done' 804 954 805 source_list = [806 ['Crab', 0.6 , 50, -130],807 ["1ES 2344+51.4", 0.6 , 90, -90 ],808 ["Mrk 501", 0.6, -22, -22+180 ],809 ["Mrk 421", 0.6, 90, -90 ],810 ["1ES 1218+304", 0.6, -5, -5+180 ],811 ["1ES 1959+650", 0.6, 155, 155-180 ],812 ["Dark Patch 2", 0.6 , 90, -90 ],813 ["Dark Patch 3", 0.6 , 90, -90 ],814 ["H 1426+428", 0.6 , 90, -90 ],815 ["IC 310", 0.6, -18, -18+180 ],816 ["PKS 2155-304", 0.6, 90, -90 ] ]817 818 sourcedict = {}819 820 def make_sourcedict():821 for s in source_list:822 sourcedict[s[0]] = {}823 sourcedict[s[0]]['wobble_offset'] = s[1]824 sourcedict[s[0]]['wobble_angle1'] = s[2]825 sourcedict[s[0]]['wobble_angle2'] = s[3]826 827 828 955 def TakeSource( name ): 829 956 if name not in sourcedict: … … 860 987 861 988 989 990 def GetFadConnections( verbose = False ): 991 """ return np.array(40) with bitmaps, showing the FADs connection status: 992 apperently this is the meaning: 993 0x43 -- well connected and well configured -- green with white tick mark 994 0x42 -- well connected -- green 995 0x09 -- something is wrong with the connection -- orange or red? 996 0x00 -- not connected, and not attempting to connect -- grey 997 """ 998 999 conn = np.array(map( ord, fad_control.connections()[0] )) 1000 if verbose: 1001 for crate in range(4): 1002 print map( hex, conn[crate*10: (crate+1) *10 ] ) 1003 return conn 1004 1005 1006 862 1007 if __name__ == '__main__': 863 1008 print 'Welcome to PyDimCtrl' … … 871 1016 print dim.name, 872 1017 print 1018 1019
Note:
See TracChangeset
for help on using the changeset viewer.