General hooks, conditions and on_stop function

It is possible to customize all scans in a general way. The features included are: hooks, repeat-a-point-in-condition and on_stop. Hooks and repeat-a-point-in-condition have to be implemented as standard sardana macros, while on_stop has to be implemented as a function.

We recommend to define the hooks and repeat-a-point-in-condition macros in a file called

$HOME/sardanaMacros/general_features.py

and the on_stop function in a file called

$HOME/sardanaMacros/generalFunctions/general_functions.py

The file where the on_stop function is defined has to be in the directory

$HOME/sardanaMacros/generalFunctions
If this is not the case, the directory where it is defined has to be included in the property PythonPath of the Macroserver device, otherwise the function can not be loaded.

Names of the macros and on_stop functions are arbitrary, but we suggest to use the following names:

for the hooks (the order in which the macros will be run, corresponds to the one given above),

for implementing the repeat-a-point-in-condition (this macro has to have a return value: 0 if the point do not have to be repeated and 1 if it has),

for the function implemented the on_stop feature (to be run if the scan is stopped with ctrl-C).

Hooks and repeat-a-point-in-condition macros can get arguments, the general on_stop function has to be defined without arguments. If a macro is set as a general hook but it is not defined or not found, the scan will continue and a warning printout will be shown in the spock session. If the macro set as repeat-a-point-in-condition macro is not defined or not found, the scan will stop with an error.

The following macros, defined in

/usr/share/pyshared/sardana/sardana-macros/DESY_general/handleGeneralFeatures.py,

allow to activate/deactivate these general features and display information about the status:

The general features are set in environment variables in spock, one can set/unset this variables for selecting these features or checking the selected ones:

p09/door/haso111n.01 [2]: lsenv General.*
                    Name                                                          Value   Type
 ----------------------- -------------------------------------------------------------- ------
        GeneralCondition                                                       gc_macro    str
            GeneralHooks   {'post-scan': ['gh_post_scan'], 'post-step': ['gh_post [...]   dict
   GeneralOnStopFunction                              general_functions.general_on_stop    str

On new systems (Debian-9, 21.8.2018) it looks like this:

p09/door/haso113u.01 [8]: lsenv .*Gen.*
                    Name                                                          Value   Type
 ----------------------- -------------------------------------------------------------- ------
           _GeneralHooks   [('gh_post_scan', ['post-scan']), ('gh_post_step', ['p [...]   list
        GeneralCondition                                                       gc_macro    str
   GeneralOnStopFunction                              general_functions.general_on_stop    str

The macros described in this section are DESY-specific. They have been created to provide am common interface to all hook-like features and to maintain continuity moving from Debian-8 to Debian-9. The current system macros are lsdef, defgh and udefgh.

2019-11-13