Skip to content
Snippets Groups Projects
Commit 74b0eba3 authored by bliss administrator's avatar bliss administrator
Browse files

Added code for watchdog. Needs to be tested.

parent 7772b343
No related branches found
No related tags found
No related merge requests found
......@@ -98,8 +98,14 @@ class ScanDisplay(object):
scan -- is the scan object
info -- is the dict of information about this scan
"""
print(self.HEADER.format(**info))
# displays scan number / total number of scans to see the acquisition progression
if info.get('technique').get('scan').get('sequence') == 'tomo:zseries':
SCAN_NB = f"{info.get('scan_nb')} / {int(info.get('scan_nb'))+self.NB_SCANS}"
else:
SCAN_NB = info.get('scan_nb')
print(self.HEADER.format(SCAN_NB,**info))
self.__state = None
self.__infos = dict()
for name in self.__motor_names:
......@@ -113,6 +119,11 @@ class ScanDisplay(object):
self.__last_saved = 0
self.__data_saving_rate = 0
self.__new_trigger = False
if info.get('technique').get('scan').get('scan_type')== 'SWEEP':
self.__data_per_point = 2
else:
self.__data_per_point = 1
def on_scan_end(self, info):
"""
......@@ -178,7 +189,7 @@ class ScanDisplay(object):
last_pos = data_node.get(-1)
self.__infos[name] = "{0:8.3f}".format(last_pos)
if channel_name == self.__trig_name:
self.__infos["trig"] = len(data_node)
self.__infos["trig"] = len(data_node)//self.__data_per_point
self.__new_trigger = True
# print last images acquired and saved
......@@ -248,7 +259,81 @@ class ScanDisplay(object):
print(msg + "\r", end="")
return
class ScanWatchdog(object):
def __init__(self, musst_card, trigger_name=None, limas=list()):
"""
watchdog_timeout -- is the maximum calling frequency of **on_timeout**
method.
"""
self.__watchdog_timeout = 15.0
self.__musst = musst_card
self.__limas = limas
self.__trig_name = trigger_name
self.__stop_reason = ''
@property
def timeout(self):
return self.__watchdog_timeout
def on_timeout(self):
"""
This method is called when **watchdog_timeout** elapsed it means
that no data event is received for the time specified by
**watchdog_timeout**
"""
for cam in self.__limas:
if cam._proxy.acq_status != 'Ready':
if 'dimax' in cam.name:
last_acq = cam.camera.last_img_recorded + 1
else:
last_acq = cam._proxy.last_image_ready + 1
diff_trigger = self.__trig - last_acq
if diff_trigger > 1 and self.__musst.STATE != 3:
self.__stop_reason = f'\nSYNCHRO LOST: Detector {cam.name} did not record all images({last_acq}/{cam.proxy.acq_nb_frames})\n'
raise StopIteration
#self.__stop_reason = f'No data received since {self.__watchdog_timeout} seconds'
#raise StopIteration
def on_scan_new(self, scan, scan_info):
"""
Called when scan is starting
"""
self.__state = None
self.__trig = 0
def on_scan_data(self, data_events, nodes, scan_info):
"""
Called when new data are emitted by the scan. This method should
raise en exception to stop the scan. All exception will
bubble-up exception the **StopIteration**. This one will just
stop the scan.
"""
# look for scan state
state = scan_info.get("state", None)
if state != self.__state:
self.__state = state
if self.__state == ScanState.STARTING or self.__state == ScanState.STOPPING:
# print last motor pos recorded
for acqdev, signals in data_events.items():
for signal in signals:
# print("... {0}".format(signal))
node = nodes.get(acqdev)
if is_zerod(node):
channel_name = node.name
# print(" data_name {0}".format(channel_name))
prefix,_,name = channel_name.rpartition(":")
if channel_name == self.__trig_name:
self.__trig = len(node)
return
def on_scan_end(self, scan_info):
if len(self.__stop_reason):
print(BOLD(self.__stop_reason) + "\n")
class LimaTakeDisplay(DataWatchCallback):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment