The Macro base class. All macros should inherit directly or indirectly from this class.
Macro API. Adds the given object to the list of controlled objects of this macro. In practice it means that if a stop is executed the stop method of the given object will be called.
Parameters: |
---|
Macro API. Adds the given objects to the list of controlled objects of this macro. In practice it means that if a stop is executed the stop method of the given object will be called.
Parameters: | obj_list (sequence) – list of objects to be controlled |
---|
Macro API. Empty method that just performs a checkpoint. This can be used to check for the stop. Usually you won’t need to call this method
Macro API. Creates a hook that executes the macro given as a sequence of strings where the first string is macro name and the following strings the macro parameters
Parameters: |
|
---|---|
Returns: | a ExecMacroHook object (which is a callable object) |
Macro API. Create a new macro and prepare it for execution Several different parameter formats are supported:
# several parameters:
self.createMacro('ascan', 'th', '0', '100', '10', '1.0')
self.createMacro('ascan', 'th', 0, 100, 10, 1.0)
th = self.getObj('th')
self.createMacro('ascan', th, 0, 100, 10, 1.0)
# a sequence of parameters:
self.createMacro(['ascan', 'th', '0', '100', '10', '1.0')
self.createMacro(('ascan', 'th', 0, 100, 10, 1.0))
th = self.getObj('th')
self.createMacro(['ascan', th, 0, 100, 10, 1.0])
# a space separated string of parameters:
self.createMacro('ascan th 0 100 10 1.0')
Parameters: | pars – the command parameters as explained above |
---|---|
Returns: | a sequence of two elemetns: the macro class and a sequence of parameters |
Return type: | tuple<Macro, seq<obj>> |
Macro API. Record a critical message in this object’s logger. Accepted args and kwargs are the same as logging.Logger.critical(). Example:
self.critical("this is a log message for macro %s", self.getName())
Parameters: |
|
---|
macro data
Macro API. Record a debug message in this object’s logger. Accepted args and kwargs are the same as logging.Logger.debug(). Example:
self.debug("this is a log message for macro %s", self.getName())
Parameters: |
|
---|
Unofficial Macro API. Alternative to getDescription() that does not throw StopException in case of a Stop. This should be called only internally by the Executor
Unofficial Macro API. Alternative to getDoorObj() that does not throw StopException in case of a Stop. This should be called only internally
Macro API. Record an error message in this object’s logger. Accepted args and kwargs are the same as logging.Logger.error(). Example:
self.error("this is a log message for macro %s", self.getName())
Parameters: |
|
---|
Macro API. Execute a macro in this macro. The method only returns after the macro is completed or an exception is thrown. Several different parameter formats are supported:
# several parameters:
self.execMacro('ascan', 'th', '0', '100', '10', '1.0')
self.execMacro('ascan', 'th', 0, 100, 10, 1.0)
th = self.getObj('th')
self.execMacro('ascan', th, 0, 100, 10, 1.0)
# a sequence of parameters:
self.execMacro(['ascan', 'th', '0', '100', '10', '1.0')
self.execMacro(('ascan', 'th', 0, 100, 10, 1.0))
th = self.getObj('th')
self.execMacro(['ascan', th, 0, 100, 10, 1.0])
# a space separated string of parameters:
self.execMacro('ascan th 0 100 10 1.0')
Parameters: | pars – the command parameters as explained above |
---|---|
Returns: | a macro object |
Macro API. Execute a macro in this macro. The method only returns after the macro is completed or an exception is thrown. This is a higher level version of runMacro method. It is the same as:
macro = self.prepareMacroObjs(name, *args, **kwargs)
self.runMacro(macro)
return macro
Parameters: |
|
---|---|
Returns: | a macro object |
Unofficial Macro API. Alternative to getExecutor() that does not throw StopException in case of a Stop. This should be called only internally
Macro API. Gets the objects of the given type belonging to the given pool with the given names. The objects (if found) will automatically become controlled by the macro.
Parameters: |
|
---|---|
Returns: | a list of objects or empty list if no compatible object is found |
Macro API. Returns the enviroment for the door where the macro is running.
Returns: | a dict containing the environment |
---|---|
Return type: | dict |
Macro API. Returns the enviroment for the macro.
Returns: | a dict containing the environment for the macro |
---|---|
Return type: | dict |
Macro API. Returns the string used to execute the macro. Ex.: ‘ascan M1 0 1000 100 0.8’
Returns: | the macro command. |
---|---|
Return type: | str |
Macro API. Returns the data produced by the macro.
Raises : | Exception if no data has been set before on this macro |
---|---|
Returns: | the data produced by the macro |
Return type: | object |
Macro API. Helper method. Returns the current date in a string.
Parameters: | time_format (str) – the format in which the date should be returned (optional, default value is ‘%a %b %d %H:%M:%S %Y’ |
---|---|
Returns: | the current date |
Return type: | str |
Macro API. Returns a string description of the macro.
Returns: | the string description of the macro |
---|---|
Return type: | str |
Macro API. Helper method that returns the device for the given device name
Returns: | the taurus device for the given device name |
---|---|
Return type: | TaurusDevice |
Macro API. Returns the string with the name of the Door that invoked this macro.
Returns: | the string with the name of the Door that invoked this macro. |
---|---|
Return type: | str |
Macro API. Returns the reference to the Door that invoked this macro.
Returns: | the reference to the Door that invoked this macro. |
---|---|
Rype : | Door |
Macro API. Gets the local environment matching the given parameters:
- door_name and macro_name define the context where to look for the environment. If both are None, the global environment is used. If door name is None but macro name not, the given macro environment is used and so on...
- If key is None it returns the complete environment, otherwise key must be a string containing the environment variable name.
Raises : | UnknownEnv |
---|---|
Parameters: | |
Returns: | a dict containing the environment |
Return type: |
Macro API. Returns the reference to the object that invoked this macro. Usually is a MacroExecutor object.
Returns: | the reference to the object that invoked this macro |
---|---|
Return type: | MacroExecutor |
Macro API. Returns the global environment.
Returns: | a dict containing the global environment |
---|---|
Return type: | dict |
Macro API. Returns this macro id
Returns: | the macro id |
---|---|
Return type: | str |
Macro API. Returns the corresponding MacroClass /MacroFunction object.
Parameters: | macro_name (str) – a string with the desired macro name. |
---|---|
Returns: | a MacroClass /MacroFunction object or None if the macro with the given name was not found |
Return type: | MacroClass /MacroFunction |
Macro API. Returns a MacroLibrary object for the given library name.
Parameters: | lib_name (str) – library name |
---|---|
Returns: | a macro library MacroLibrary |
Return type: | MacroLibrary |
Macro API. Returns a sequence of MacroLibrary objects for all known macros that obey the filter expression.
Parameters: | filter – a regular expression for the macro library [default: None meaning match all macro libraries) |
---|---|
Returns: | a sequence of MacroLibrary objects |
Return type: | seq<MacroLibrary> |
Macro API. Returns a MacroLibrary object for the given library name.
Parameters: | lib_name (str) – library name |
---|---|
Returns: | a macro library MacroLibrary |
Return type: | MacroLibrary |
Macro API. Returns a sequence of MacroLibrary objects for all known macros that obey the filter expression.
Parameters: | filter – a regular expression for the macro library [default: None meaning match all macro libraries) |
---|---|
Returns: | a sequence of MacroLibrary objects |
Return type: | seq<MacroLibrary> |
Macro API. Returns a list of strings containing the names of all known macros
Returns: | a sequence of macro names |
---|---|
Return type: | seq<str> |
Macro API. Returns the MacroServer for this macro
Returns: | the MacroServer |
---|---|
Return type: | MacroServer |
Macro API. Returns the current macro status. Macro status is a dict where keys are the strings:
- id - macro ID (internal usage only)
- range - the full progress range of a macro (usually a tuple of two numbers (0, 100))
- state - the current macro state, a string which can have values start, step, stop and abort
- step - the current step in macro. Should be a value inside the allowed macro range
Returns: | the macro status |
---|---|
Return type: | dict |
Macro API. Returns the python thread where this macro is running
Returns: | the python thread where this macro is running |
---|---|
Return type: | threading.Thread |
Macro API. Returns the python thread id where this macro is running
Returns: | the python thread id where this macro is running |
---|---|
Return type: | int |
Macro API. Returns a sequence of MacroClass /MacroFunction objects for all known macros that obey the filter expression.
Parameters: | filter – a regular expression for the macro name (optional, default is None meaning match all macros) |
---|---|
Returns: | a sequence of MacroClass /MacroFunction objects |
Return type: | seq<MacroClass /MacroFunction> |
Macro API. Returns the manager for this macro (usually a MacroServer)
Returns: | the MacroServer |
---|---|
Return type: | MacroServer |
Macro API. Returns a new Motion object containing the given elements.
Raises : | Exception if no elements are defined or the elems is not recognized as valid, or an element is not found or an element appears more than once |
---|---|
Parameters: |
|
Returns: | a Motion object |
Macro API. Returns this macro name
Returns: | the macro name |
---|---|
Return type: | str |
Macro API. Gets the object of the given type belonging to the given pool with the given name. The object (if found) will automatically become controlled by the macro.
Raises : | MacroWrongParameterType if name is not a string |
---|---|
Raises : | AttributeError if more than one matching object is found |
Parameters: |
|
Returns: | the object or None if no compatible object is found |
Macro API. Gets the objects of the given type belonging to the given pool with the given names. The objects (if found) will automatically become controlled by the macro.
Parameters: |
|
---|---|
Returns: | a list of objects or empty list if no compatible object is found |
Macro API. Returns a the macro parameters. It returns a list containning the parameters with which the macro was executed
Returns: | the macro parameters |
---|---|
Return type: | list |
Macro API. Returns the parent macro reference.
Returns: | the parent macro reference or None if there is no parent macro |
---|---|
Return type: | Macro |
Macro API. Returns the list of known device pools.
Returns: | the list of known device pools |
---|---|
Return type: | seq<Pool> |
Unofficial Macro API. Returns the macro result object (if any)
Returns: | the macro result object or None |
---|
Macro API. Helper method that returns the tango factory.
Returns: | the tango factory singleton |
---|---|
Return type: | TangoFactory |
Unofficial Macro API. Returns True if the macro should return a result or False otherwise
Returns: | True if the macro should return a result or False otherwise |
---|---|
Return type: | bool |
Macro API. Record an info message in this object’s logger. Accepted args and kwargs are the same as logging.Logger.info(). Example:
self.info("this is a log message for macro %s", self.getName())
Parameters: |
|
---|
Macro API. If args is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.
Depending on which type of application you are running, some of the keywords may have no effect (ex.: spock ignores decimals when a number is asked).
Recognized kwargs:
- data_type : [default: Type.String] specific input type. Can also specify a sequence of strings with possible values (use allow_multiple=True to say multiple values can be selected)
- key : [default: no default] variable/label to assign to this input
- unit: [default: no default] units (useful for GUIs)
- timeout : [default: None, meaning wait forever for input]
- default_value : [default: None, meaning no default value] When given, it must be compatible with data_type
- allow_multiple : [default: False] in case data_type is a sequence of values, allow multiple selection
- minimum : [default: None] When given, must be compatible with data_type (useful for GUIs)
- maximum : [default: None] When given, must be compatible with data_type (useful for GUIs)
- step : [default: None] When given, must be compatible with data_type (useful for GUIs)
- decimals : [default: None] When given, must be compatible with data_type (useful for GUIs)
Examples:
device_name = self.input("Which device name (%s)?", "tab separated")
point_nb = self.input("How many points?", data_type=Type.Integer)
calc_mode = self.input("Which algorithm?", data_type=["Average", "Integral", "Sum"],
default_value="Average", allow_multiple=False)
Macro API. Record a log message in this object’s logger. Accepted args and kwargs are the same as logging.Logger.log(). Example:
self.debug(logging.INFO, "this is a info log message for macro %s", self.getName())
Parameters: |
---|
Macro API. Returns the MacroServer for this macro
Returns: | the MacroServer |
---|---|
Return type: | MacroServer |
Macro API. An object that contains all macro classes as members. With the returning object you can invoke other macros. Example:
m = self.macros.ascan('th', '0', '90', '10', '2')
scan_data = m.data
Macro API. Returns the manager for this macro (usually a MacroServer)
Returns: | the MacroServer |
---|---|
Return type: | MacroServer |
Macro API. Hook executed when an abort occurs. Overwrite as necessary. Default implementation does nothing
Macro API. Hook executed when a pause occurs. Overwrite as necessary. Default implementation does nothing
Macro API. Hook executed when a stop occurs. Overwrite as necessary. Default implementation calls on_abort()
Macro API. Record a log message in this object’s output. Accepted args and kwargs are the same as logging.Logger.log(). Example:
self.output("this is a print for macro %s", self.getName())
Parameters: |
|
---|
Macro API. Sends an line tagged as a block to the output
Parameters: | line (str) – line to be sent |
---|
Macro API. Helper method. Outputs the current date into the output buffer
Parameters: | time_format (str) – (str) the format in which the date should be returned (optional, default value is ‘%a %b %d %H:%M:%S %Y’ |
---|
Unofficial Macro API. Alternative to getParentMacro that does not throw StopException in case of a Stop. This should be called only internally by the Executor
Internal method. Pauses the macro execution. To be called by the Door running the macro to pause the current macro
Macro API. Will establish a pause point where called. If an external source as invoked a pause then, when this this method is called, it will be block until the external source calls resume. You may want to call this method if your macro takes a considerable time to execute and you may whish to pause it at some time. Example:
for i in range(10000):
time.sleep(0.1)
self.output("At step %d/10000", i)
self.pausePoint()
Parameters: | timeout (float) – timeout in seconds [default: None, meaning wait forever] |
---|
Macro API. Sends the plot command to the client using the ‘RecordData’ DevEncoded attribute. The data is encoded using the pickle -> BZ2 codec.
Parameters: |
|
---|
Macro API. Prepare phase. Overwrite as necessary. Default implementation does nothing
Macro API. Prepare a new macro for execution Several different parameter formats are supported:
# several parameters:
executor.prepareMacro('ascan', 'th', '0', '100', '10', '1.0')
executor.prepareMacro('ascan', 'th', 0, 100, 10, 1.0)
th = self.getObj('th')
executor.prepareMacro('ascan', th, 0, 100, 10, 1.0)
# a sequence of parameters:
executor.prepareMacro(['ascan', 'th', '0', '100', '10', '1.0')
executor.prepareMacro(('ascan', 'th', 0, 100, 10, 1.0))
th = self.getObj('th')
executor.prepareMacro(['ascan', th, 0, 100, 10, 1.0])
# a space separated string of parameters:
executor._prepareMacro('ascan th 0 100 10 1.0')
Parameters: |
|
---|---|
Returns: | a sequence of two elements: the macro object and the result of preparing the macro |
Macro API. Prepare a new macro for execution
Parameters: |
|
---|---|
Returns: | a sequence of two elements: the macro object and the result of preparing the macro |
Macro API. Prints a message. Accepted args and kwargs are the same as print(). Example:
self.print("this is a print for macro", self.getName())
Note
you will need python >= 3.0. If you have python 2.x then you must include at the top of your file the statement:
from __future__ import print_function
Macro API. Reloads the given library(=module) names
Raises : | ImportError in case the reload process is not successfull |
---|---|
Parameters: | lib_name (str) – library(=module) name |
Returns: | the reloaded python module object |
Macro API. Reloads the module corresponding to the given macro name
Raises : | MacroServerExceptionList in case the macro is unknown or the reload process is not successfull |
---|---|
Parameters: | macro_name (str) – macro name |
Macro API. Reloads the given library(=module) names
Raises : | MacroServerExceptionList in case the reload process is not successfull |
---|---|
Parameters: | lib_name (str) – library(=module) name |
Returns: | the MacroLibrary for the reloaded library |
Return type: | MacroLibrary |
Macro API. Reloads the given library(=module) names
Raises : | MacroServerExceptionList in case the reload process is not successfull for at least one lib |
---|
param lib_names: a list of library(=module) names :type lib_name: seq<str>
Returns: | a sequence of MacroLibrary objects for the reloaded libraries |
---|---|
Return type: | seq<MacroLibrary> |
Macro API. Reloads the given library(=module) names
Raises : | MacroServerExceptionList in case the reload process is not successfull |
---|---|
Parameters: | lib_name (str) – library(=module) name |
Returns: | the MacroLibrary for the reloaded library |
Return type: | MacroLibrary |
Macro API. Reloads the given library(=module) names
Raises : | MacroServerExceptionList in case the reload process is not successfull for at least one lib |
---|
param lib_names: a list of library(=module) names :type lib_name: seq<str>
Returns: | a sequence of MacroLibrary objects for the reloaded libraries |
---|---|
Return type: | seq<MacroLibrary> |
Macro API. Reloads the modules corresponding to the given macro names.
Raises : | MacroServerExceptionList in case the macro(s) are unknown or the reload process is not successfull |
---|---|
Parameters: | macro_names (sequence<str>) – a list of macro names |
Macro API. Record a log message in the sardana report (if enabled) with default level INFO. The msg is the message format string, and the args are the arguments which are merged into msg using the string formatting operator. (Note that this means that you can use keywords in the format string, together with a single dictionary argument.)
kwargs are the same as logging.Logger.debug() plus an optional level kwargs which has default value INFO
Example:
self.report("this is an official report of macro %s", self.getName())
Parameters: |
|
---|
Internal method. Resumes the macro execution. To be called by the Door running the macro to resume the current macro
Removes the given objects to the list of controlled objects of this macro.
Parameters: | obj – object to be released from the control |
---|---|
Return type: | object |
Macro API. Runs the macro. Overwrite MANDATORY! Default implementation raises RuntimeError.
Raises : | RuntimeError |
---|
Macro API. Runs the macro. This the lower level version of execMacro(). The method only returns after the macro is completed or an exception is thrown. It should be used instead of execMacro when some operation needs to be done between the macro preparation and the macro execution. Example:
macro = self.prepareMacro("mymacro", "myparam")
self.do_my_stuff_with_macro(macro)
self.runMacro(macro)
Parameters: | macro_obj – macro object |
---|---|
Returns: | the output of the macro |
Macro API. Sends the given data to the RecordData attribute of the Door
Parameters: | data – (sequence) the data to be sent |
---|
Macro API. Sets the data for this macro
Parameters: | data (object) – new data to be associated with this macro |
---|
Macro API. Sets the environment key to the new value and stores it persistently.
Returns: | a tuple with the key and value objects stored |
---|---|
Return type: | tuple<str, object> |
Macro API. Specifies the end of a block of data. Basically it outputs the ‘/BLOCK’ tag
Macro API. Specifies the begining of a block of data. Basically it outputs the ‘BLOCK’ tag
Unofficial Macro API. Sets the result of this macro
Parameters: | result – (object) the result for this macro |
---|
Macro API. Record a trace message in this object’s logger.
Parameters: |
|
---|
Macro API. Logs the traceback with level TRACE on the macro logger.
Macro API. Unsets the given environment variable.
Parameters: | key (str) – the environment variable name |
---|
Macro API. Record a warning message in this object’s logger. Accepted args and kwargs are the same as logging.Logger.warning(). Example:
self.warning("this is a log message for macro %s", self.getName())
Parameters: |
|
---|
Class designed to decorate a python function to transform it into a macro. Examples:
@macro()
def my_macro1(self):
self.output("Executing %s", self.getName())
@macro([ ["moveable", Type.Moveable, None, "motor to watch"] ])
def where_moveable(self, moveable):
self.output("Moveable %s is at %s", moveable.getName(), moveable.getPosition())