enhance simulation

This commit is contained in:
2023-06-29 10:02:42 +02:00
parent bd7d71b0b0
commit 681b8f2953
2 changed files with 43 additions and 33 deletions

View File

@@ -60,30 +60,30 @@ class Shutter:
_log.info('shutter closed') _log.info('shutter closed')
class Deltatau: class Deltatau:
def __init__(self): def __init__(self,sim=False):
app=QApplication.instance() app=QApplication.instance()
cfg=app._cfg cfg=app._cfg
host=cfg.value(AppCfg.DT_HOST) host=cfg.value(AppCfg.DT_HOST)
if sim:
hpp=host.split(':')
param={'host':hpp[0]}
if len(hpp)>1:
param['port']=int(hpp[1])
if len(hpp)>2:
param['fast_gather_port']=int(hpp[2])
_log.info(' -> ssh-tunneling PPComm({host}:{port} {host}:{fast_gather_port})'.format(**param))
try:
self._comm=comm=PPComm(**param,timeout=2.0)
self._gather=gather=Gather(comm)
except (socket.timeout,socket.gaierror) as e:
_log.critical(f'can not connect to deltatau:"{host}" -> {e}')
self._comm=comm=None self._comm=comm=None
self._gather=gather=None self._gather=gather=None
#return else:
hpp=host.split(':')
param={'host':hpp[0]}
if len(hpp)>1:
param['port']=int(hpp[1])
if len(hpp)>2:
param['fast_gather_port']=int(hpp[2])
_log.info(' -> ssh-tunneling PPComm({host}:{port} {host}:{fast_gather_port})'.format(**param))
try:
self._comm=comm=PPComm(**param,timeout=2.0)
self._gather=gather=Gather(comm)
except (socket.timeout,socket.gaierror) as e:
_log.critical(f'can not connect to deltatau:"{host}" -> {e}')
self._shapepath=sp=shapepath.ShapePath(comm, gather, verbose=0xff, sync_mode=1, sync_flag=3) self._shapepath=sp=shapepath.ShapePath(comm, gather, verbose=0xff, sync_mode=1, sync_flag=3)
class Jungfrau: class Jungfrau:
def __init__(self): def __init__(self,sim=False):
#python /sf/jungfrau/applications/daq_client/daq_client.py -h #python /sf/jungfrau/applications/daq_client/daq_client.py -h
#python /sf/jungfrau/applications/daq_client/daq_client.py -p p19739 -t no_beam_test #python /sf/jungfrau/applications/daq_client/daq_client.py -p p19739 -t no_beam_test
# -c/sf/cristallina/config/channel_lists/channel_list_bs-e/sf/cristallina/config/channel_lists/channel_list_ca # -c/sf/cristallina/config/channel_lists/channel_list_bs-e/sf/cristallina/config/channel_lists/channel_list_ca
@@ -91,6 +91,9 @@ class Jungfrau:
# --start_pulseid 15382163895 --stop_pulseid 15382163905 # --start_pulseid 15382163895 --stop_pulseid 15382163905
#rsync -vai gac-cristall@saresc-cons-03:/sf/jungfrau/applications/daq_client/daq_client.py . #rsync -vai gac-cristall@saresc-cons-03:/sf/jungfrau/applications/daq_client/daq_client.py .
# setup slic parameters # setup slic parameters
if sim:
self._daq=None
return
app=QApplication.instance() app=QApplication.instance()
cfg=app._cfg cfg=app._cfg
detectors = [ cfg.value(AppCfg.DAQ_DET) ] detectors = [ cfg.value(AppCfg.DAQ_DET) ]
@@ -103,13 +106,15 @@ class Jungfrau:
default_detectors=detectors, default_channels=bs_channels, default_pvs=pv_channels, default_detectors=detectors, default_channels=bs_channels, default_pvs=pv_channels,
rate_multiplicator=1, append_user_tag_to_data_dir=True rate_multiplicator=1, append_user_tag_to_data_dir=True
) )
self._pv_pulse_id=epics.PV('SAR-EXPMX-EVR0:RX-PULSEID')
self._pv_pulse_id.connect()
except NameError as e: except NameError as e:
_log.warning(f'Jungfrau not connected: {e}') _log.critical(f'Jungfrau not connected: {e}')
self._daq=None
self._pv_pulse_id=epics.PV('SAR-EXPMX-EVR0:RX-PULSEID')
self._pv_pulse_id.connect()
def acquire(self, n_pulses, wait=False): def acquire(self, n_pulses, wait=False):
if self._daq is None:
_log.info(f'simulated')
return
app=QApplication.instance() app=QApplication.instance()
cfg=app._cfg cfg=app._cfg
run=cfg.value(AppCfg.DAQ_RUN) run=cfg.value(AppCfg.DAQ_RUN)
@@ -118,14 +123,17 @@ class Jungfrau:
except TypeError as e: except TypeError as e:
_log.warning(f'failed to get _pulse_id_start: {e}') _log.warning(f'failed to get _pulse_id_start: {e}')
if self._daq is not None: if self._daq is not None:
#n_pulses_run = n_pulses + run['padding'] n_pulses_run = n_pulses + run['padding']
#self._daq.acquire(run['prefix'], n_pulses=min(n_pulses_run, 5000), n_repeat=ceil(n_pulses_run/5000), wait=False, cell_name=run['cell_name']) self._daq.acquire(run['prefix'], n_pulses=min(n_pulses_run, 5000), n_repeat=ceil(n_pulses_run/5000), wait=False, cell_name=run['cell_name'])
self._daq.acquire(run['prefix'], n_pulses=n_pulses, wait=False) #self._daq.acquire(run['prefix'], n_pulses=n_pulses, wait=False)
pass pass
#run['id']+=1 #run['id']+=1
cfg.setValue(AppCfg.DAQ_RUN,run) cfg.setValue(AppCfg.DAQ_RUN,run)
def gather_upload(self): def gather_upload(self):
if self._daq is None:
_log.info(f'simulated')
return
try: try:
self._pulse_id_end=int(self._pv_pulse_id.value) self._pulse_id_end=int(self._pv_pulse_id.value)
except TypeError as e: except TypeError as e:

View File

@@ -15,9 +15,10 @@ bitmask for simulation:
0x02: illumination 0x02: illumination
0x04: zoom 0x04: zoom
0x08: camera 0x08: camera
0x10: Deltatau motors 0x10: Deltatau motors and motion code
0x20: SmarAct motors 0x20: SmarAct motors
0x40: shutter 0x40: shutter
0x80: Jungfrau
""" """
import logging import logging
@@ -2217,11 +2218,11 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
try: try:
dt=app._deltatau dt=app._deltatau
except AttributeError: except AttributeError:
app._deltatau=dt=psi_device.Deltatau() app._deltatau=dt=psi_device.Deltatau(app._args.sim&0x10!=0)
try: try:
jf=app._jungfrau jf=app._jungfrau
except AttributeError: except AttributeError:
app._jungfrau=jf=psi_device.Jungfrau() app._jungfrau=jf=psi_device.Jungfrau(app._args.sim&0x80!=0)
sp=dt._shapepath sp=dt._shapepath
sp.verbose=dt_misc['verbose'] sp.verbose=dt_misc['verbose']
@@ -2285,10 +2286,11 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
sp.setup_coord_trf(fx, fy, cz) # reset to shape path system sp.setup_coord_trf(fx, fy, cz) # reset to shape path system
try: comm=sp.comm
sp.comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg) if comm is None:
except AttributeError: _log.info('simulated')
pass else:
comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg)
if dlg.wasCanceled(): if dlg.wasCanceled():
return return
@@ -2300,9 +2302,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
jf.acquire(num_pts) jf.acquire(num_pts)
sp.trigger(0.5) # send a start trigger (if needed) after given time sp.trigger(0.5) # send a start trigger (if needed) after given time
if dt._comm is None: if dt._comm is None:
dlg.setLabelText("run motion/acquisition") dlg.setLabelText("run motion/acquisition (simulated)")
dlg.setMaximum(num_pts) dlg.setMaximum(num_pts)
for p in range(0,num_pts,int(num_pts/1000)): for p in range(0,num_pts,int(num_pts/100)):
#_log.info(f'progress {p}/{num_pts}') #_log.info(f'progress {p}/{num_pts}')
dlg.setValue(p) dlg.setValue(p)
time.sleep(.1) time.sleep(.1)