ptable Package¶
The devsup.ptable
module provides the means to define a Parameter Table,
which is something like a dictionary (parameter name <-> dict key)
where a parameter may be associated (attached) with zero or more EPICS records.
Changes to a parameter may be reflected in the attached records. A change in an attached record will update the parameter value, and optionally, involve some functions (actions) to make some use of the new value.
The basis of all tables is the TableBase
class. User code
will typically sub-class TableBase
.
Defining Parameters¶
-
class
devsup.ptable.
Parameter
(name=None, iointr=False)¶ Define a parameter in a table.
When a sub-class of TableBase is instantiated, parameters become py:class:_ParamInstance instances.
>>> class MyTable(TableBase): A = Parameter() B = Parameter(name='bb') C = Parameter(iointr=True) >>>
Defines a table with three parameters. The second ‘B’ defines a different parameter name and attribute name. The parameter name ‘bb’ will be used in .db files, which self.B will be used for access from the table instance.
When _iointr_ is True, then attached device support may use SCAN=’I/O Intr’, which is triggered with the method self.B.notify().
This class has several methods which may be used decorate member functions as actions when the value of a parameter is (possibly) changed.
-
isnotvalid
(fn)¶ Decorator to run an action when the value is not valid
-
isvalid
(fn)¶ Decorator to run an action when the value is valid
-
onchange
(fn)¶ Decorator to run an action when the value of a parameter is changed.
-
oncondition
(cond)¶ Decorator which allows a custom condition function to be specified.
This function will be invoked with two argument cond(newval,oldval) and is expected to retur a bool.
>>> class MyTable(TableBase): A = Parameter() @A.oncondition(lambda n,o:n<5) def action(self, oldval): print self.A.value,'is less than 5'
-
onproc
(fn)¶ Decorator run a member function action whenever an attached device support processes.
>>> class MyTable(TableBase): A = Parameter() @A.onproc def action(self, oldval): print 'A changed from',oldval,'to',self.A.value
-
-
class
devsup.ptable.
ParameterGroup
(params, name=None)¶ A helper for defining actions on groups of parameters
When a sub-class of TableBase is instantiated, parameter groups become py:class:_ParamGroupInstance instances.
>>> class MyTable(TableBase): A = Parameter() B = Parameter(name='bb') grp = ParameterGroup([A,B]) >>>
This class has several methods which may be used decorate member functions as actions based on the value of parameters in this group.
-
allvalid
(fn)¶ Decorator to run an action when all parameters have valid values
-
anynotvalid
(fn)¶ Decorator to run an action when any parameters has an invalid value
-
oncondition
(fmap, freduce=<built-in function all>)¶ Decorator for a custom condition.
The condition is specified in two parts, a map function, and a reduce function. The map function is applied to each parameter in the group. Then a list of the results is passed to the reduce function. If not specified, the default reducing function is all (map func must return bool).
>>> class MyTable(TableBase): A, B = Parameter(), Parameter() grp = ParameterGroup([A,B]) @grp.oncondition(lambda v:v>5, any) def action(self): # either A or B is greater than 5 print self.A.value, self.B.value
-
onproc
(fn)¶ Decorator run a member function action whenever a device support attached to any parameter in the group processes.
>>> class MyTable(TableBase): A, B = Parameter(), Parameter() grp = ParameterGroup([A,B]) @grp.onproc def action(self): print self.A.value, self.B.value
-
-
class
devsup.ptable.
TableBase
(**kws)¶ Base class for all parameter tables.
Sub-class this and populate with
Parameter
andParameterGroup
.#When a table is instantiated it must be given a unique name.
>>> class MyTable(TableBase): ... >>> x=MyTable(name='xyz') >>>
Runtime Access¶
-
class
devsup.ptable.
_ParamInstance
(table, name, scan)¶ Access to a parameter at runtime.
-
addAction
(fn, cond=None)¶ Add an arbitrary action at runtime
-
isvalid
¶ Is the parameter value valid (not None and no INVALID_ALARM)
-
notify
()¶ Notify attached records of parameter value change. A no-op unless Parameter(iointr=True)
-
value
¶ The current parameter value
-
Device Support¶
A general purpose device support is provided to access table parameters. The input/output link format is “@devsup.ptable <tablename> set|get <param> [optional]”