#!/usr/bin/env python3 # # This script is used both to register what the atmospheric # pressure was at the start of the last run and to periodically # update the pressure difference that has occured since then. # # This is run from two places: # # 1. The run_prestart (run_prestart.local) script with the # "PRESTART" argument # # 2. A cronjob from the hdops account on gluon47 with no # arguments # # # For case 1. all PVs listed below are updated # # For case 2. only the hb, p_diff, and t_diff variables # are updated # # # The HD:coda:atm_pressure:p_diff value is used to alarm # which provides notification to the shoft worker when # it goes out of range (currently >0.1). The alarm only # makes sense when a run is in progress. Thus, the # the value of HD:coda:daq:status is checked to be non-zero. # If it is not, then a value of 0 is written to p_diff # to avoid alarming. # # n.b. HD:coda:daq:status is set to 0 at run end, 1 at # prestart, and 2 at go. The value is set in the CODA # state transition scripts found in $DAQ_HOME/scripts. # # # HD:coda:atm_pressure:hb # HD:coda:atm_pressure:p0 # HD:coda:atm_pressure:p_diff # HD:coda:atm_pressure:t0 # HD:coda:atm_pressure:t_diff # # # The pressure does not need to be checked more than once # every few minutes. However, the heartbeat should occur # every 2 seconds. The choice is whether to have this # script run continuously or to be run periodically via # cronjob. It is considered more robust to have cron run # this script periodically. Thus, this will set the PVs # appropriately upon startup, but then continue to update # the heartbeat for 2 minutes before exiting. This will # all detection if the heartbeat is failing which indicates # an issue with this script, while still allowing cron to # run the script. # # Note: This means the time this script lives for while # updating the heartbeat should match the period in the # crontab! # import sys import time from epics import * # Total time to live for this script. Script will continue # to update heartbeat until this amount of time has passed # and then exit. This should match cronjob period (see # above). max_time_to_live = 119.0 # seconds tstart = time.time() # Timeout for epics operations timeout = 2.0 # TODO: The calls to caget() below are protected via timeout, # TODO: but nothing checks for if this actually happens. # TODO: (does caget return None in this case?) # Set p0 and t0 if 'PRESTART' in sys.argv[1:]: # Set pressure and time print('atm_pressure_monitor: setting p0 and t0') caput('HD:coda:atm_pressure:p0', caget('RESET:i:GasPanelBarPress1', timeout=timeout), timeout=timeout ) caput('HD:coda:atm_pressure:t0', time.time(), timeout=timeout ) print('atm_pressure_monitor: done') # Set p_diff and t_diff print('atm_pressure_monitor: setting p_diff and t_diff') p_diff = caget('RESET:i:GasPanelBarPress1', timeout=timeout) - caget('HD:coda:atm_pressure:p0', timeout=timeout ) t_diff = time.time() - caget('HD:coda:atm_pressure:t0', timeout=timeout ) coda_status = caget('HD:coda:daq:status', timeout=timeout) if int(coda_status) == 0: p_diff=0.0 caput('HD:coda:atm_pressure:p_diff', abs(p_diff), timeout=timeout) caput('HD:coda:atm_pressure:t_diff', t_diff , timeout=timeout) print('atm_pressure_monitor: done') # Sleep for two seconds at a time, updating heartbeat, # until we have lived for max_time_to_live while (time.time()-tstart) < max_time_to_live: # update heartbeat print('atm_pressure_monitor: heartbeat ...') caput('HD:coda:atm_pressure:hb', caget('HD:coda:atm_pressure:hb')+1) # sleep for 2 seconds time.sleep(2.0) # n.b. This script seems to seg. fault on exit. This is an issue # with pyepics.