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')
class Deltatau:
def __init__(self):
def __init__(self,sim=False):
app=QApplication.instance()
cfg=app._cfg
host=cfg.value(AppCfg.DT_HOST)
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}')
if sim:
self._comm=comm=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)
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 -p p19739 -t no_beam_test
# -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
#rsync -vai gac-cristall@saresc-cons-03:/sf/jungfrau/applications/daq_client/daq_client.py .
# setup slic parameters
if sim:
self._daq=None
return
app=QApplication.instance()
cfg=app._cfg
detectors = [ cfg.value(AppCfg.DAQ_DET) ]
@@ -103,13 +106,15 @@ class Jungfrau:
default_detectors=detectors, default_channels=bs_channels, default_pvs=pv_channels,
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:
_log.warning(f'Jungfrau not connected: {e}')
self._daq=None
self._pv_pulse_id=epics.PV('SAR-EXPMX-EVR0:RX-PULSEID')
self._pv_pulse_id.connect()
_log.critical(f'Jungfrau not connected: {e}')
def acquire(self, n_pulses, wait=False):
if self._daq is None:
_log.info(f'simulated')
return
app=QApplication.instance()
cfg=app._cfg
run=cfg.value(AppCfg.DAQ_RUN)
@@ -118,14 +123,17 @@ class Jungfrau:
except TypeError as e:
_log.warning(f'failed to get _pulse_id_start: {e}')
if self._daq is not None:
#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=n_pulses, wait=False)
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=n_pulses, wait=False)
pass
#run['id']+=1
cfg.setValue(AppCfg.DAQ_RUN,run)
def gather_upload(self):
if self._daq is None:
_log.info(f'simulated')
return
try:
self._pulse_id_end=int(self._pv_pulse_id.value)
except TypeError as e:

View File

@@ -15,9 +15,10 @@ bitmask for simulation:
0x02: illumination
0x04: zoom
0x08: camera
0x10: Deltatau motors
0x10: Deltatau motors and motion code
0x20: SmarAct motors
0x40: shutter
0x80: Jungfrau
"""
import logging
@@ -2217,11 +2218,11 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
try:
dt=app._deltatau
except AttributeError:
app._deltatau=dt=psi_device.Deltatau()
app._deltatau=dt=psi_device.Deltatau(app._args.sim&0x10!=0)
try:
jf=app._jungfrau
except AttributeError:
app._jungfrau=jf=psi_device.Jungfrau()
app._jungfrau=jf=psi_device.Jungfrau(app._args.sim&0x80!=0)
sp=dt._shapepath
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
try:
sp.comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg)
except AttributeError:
pass
comm=sp.comm
if comm is None:
_log.info('simulated')
else:
comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg)
if dlg.wasCanceled():
return
@@ -2300,9 +2302,9 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
jf.acquire(num_pts)
sp.trigger(0.5) # send a start trigger (if needed) after given time
if dt._comm is None:
dlg.setLabelText("run motion/acquisition")
dlg.setLabelText("run motion/acquisition (simulated)")
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}')
dlg.setValue(p)
time.sleep(.1)