diff --git a/src/sardana/macroserver/recorders/output.py b/src/sardana/macroserver/recorders/output.py index f1ff24f55..53fcbc3c8 100644 --- a/src/sardana/macroserver/recorders/output.py +++ b/src/sardana/macroserver/recorders/output.py @@ -141,6 +141,7 @@ def __init__(self, stream, cols=None, number_fmt='%8.4f', col_width=8, cols = None self._columns = cols self._output_block = output_block + self._header_shown = False def _startRecordList(self, recordlist): starttime = recordlist.getEnvironValue('starttime').ctime() @@ -215,9 +216,7 @@ def _startRecordList(self, recordlist): self._scan_line_t = [(col_names[0], '%%(%s)8d' % col_names[0])] self._scan_line_t += [(name, cell_t_number % name) for name in col_names[1:]] - - self._stream()._output(header) - self._stream()._flushOutput() + self._header = header def _endRecordList(self, recordlist): self._stream()._flushOutput() @@ -245,9 +244,14 @@ def _endRecordList(self, recordlist): info_string = 'Scan #%s ended at %s, taking %s. ' + \ 'Dead time %.1f%% (setup time %.1f%%, motion dead time %.1f%%)' self._stream().info(info_string % (serialno, endtime, totaltime, - deadtime_perc, setuptime_perc, motiontime_perc)) + deadtime_perc, setuptime_perc, motiontime_perc)) def _writeRecord(self, record): + if not self._header_shown: + # show column headers + self._stream()._output(self._header) + self._stream()._flushOutput() + self._header_shown = True cells = [] for i, (name, cell) in enumerate(self._scan_line_t): cell_data = record.data[name] diff --git a/src/sardana/macroserver/scan/gscan.py b/src/sardana/macroserver/scan/gscan.py index bc12957bb..cc23edb82 100644 --- a/src/sardana/macroserver/scan/gscan.py +++ b/src/sardana/macroserver/scan/gscan.py @@ -52,6 +52,8 @@ from taurus.core.util.threadpool import ThreadPool from taurus.core.util.event import CallableRef from taurus.core.tango.tangovalidator import TangoDeviceNameValidator +from taurus.console import Alignment +from taurus.console.list import List from sardana.sardanathreadpool import OmniWorker from sardana.util.tree import BranchNode, LeafNode, Tree @@ -2477,6 +2479,14 @@ def _go_through_waypoints(self): self.on_waypoints_end() return + # a table of motor settings + # ("u" is short for "unit", to save space) + motor_table = List(["Motor", "Velocity[u/s]", "Acceleration[s]", + "Deceleration[s]", "Start[u]", "End[u]"], + header_separator=None, + text_alignment=[Alignment.HCenter] * 6, + max_col_width=[-1] * 6) + # prepare motor(s) to move with their maximum velocity for path in motion_paths: motor = path.moveable @@ -2487,6 +2497,13 @@ def _go_through_waypoints(self): 'end: %f; ' % path.final_pos + 'ds: %f' % (path.final_pos - path.initial_pos)) + cell_format = "%g" # TODO is this the proper format to use? + motor_table.appendRow([motor.getName(), + cell_format % path.max_vel, + cell_format % path.max_vel_time, + cell_format % path.min_vel_time, + cell_format % path.initial_pos, + cell_format % path.final_pos]) attributes = OrderedDict(velocity=path.max_vel, acceleration=path.max_vel_time, deceleration=path.min_vel_time) @@ -2500,6 +2517,11 @@ def _go_through_waypoints(self): msg = "Error when configuring scan motion (%s)" % e raise ScanException(msg) + self.macro.output("") + for line in motor_table.genOutput(): + self.macro.output(line) + self.macro.output("") + if macro.isStopped(): self.on_waypoints_end() return @@ -2610,6 +2632,25 @@ def on_waypoints_end(self, restore_positions=None): self.join_thread_pool() self.macro.debug("All data events are processed") + # Note: The commented out code below works, but due to an issue with + # output of the last measurement point, it should not be enabled yet. + # See https://github.com/sardana-org/sardana/issues/1651 + + # # Output the restored motor settings + # out = List(["Motor", "Velocity", "Acceleration", "Deceleration"], + # header_separator=None, + # text_alignment=[Alignment.HCenter] * 4, + # max_col_width=[-1] * 4) + # cell_format = "%g" + # for motor_backup in self._backup: + # out.appendRow([motor_backup["moveable"].getName(), + # cell_format % motor_backup["velocity"], + # cell_format % motor_backup["acceleration"], + # cell_format % motor_backup["deceleration"]]) + # self.macro.output("") + # for line in out.genOutput(): + # self.macro.output(line) + def scan_loop(self): macro = self.macro # manager = macro.getManager()