This parameter creates an associated port that can be used to update the current value of the parameter. This parameter has two values, which may not be equal, a current value and a persistent value. The persistent value is returned by getExpression() and is set by any of three different mechanisms:
- calling setExpression();
- calling setToken(); and
- specifying a value as a constructor argument.
All three of these will also set the current value, which is then equal to the persistent value. The current value is returned by get getToken() and is set by any of three different mechanisms:
- calling setCurrentValue();
- calling update() sets the current value if there is an associated port, and that port has a token to consume; and
These three techniques do not change the persistent value, so after these are used, the persistent value and current value may be different.
When using this parameter in an actor, care must be exercised to call update() exactly once per firing prior to calling getToken(). Each time update() is called, a new token will be consumed from the associated port (if the port is connected and has a token). If this is called multiple times in an iteration, it may result in consuming tokens that were intended for subsequent iterations. Thus, for example, update() should not be called in fire() and then again in postfire(). Moreover, in some domains (such as DE), it is essential that if a token is provided on a port, that it is consumed. In DE, the actor will be repeatedly fired until the token is consumed. Thus, it is an error to not call update() once per iteration. For an example of an actor that uses this mechanism, see Ramp.
If this actor is placed in a container that does not implement the TypedActor interface, then no associated port is created, and it functions as an ordinary parameter. This is useful, for example, if this is put in a library, where one would not want the associated port to appear.
There are a few situations where PortParameter might not do what you expect:
- If it is used in a transparent composite actor, then a token provided to a PortParameter will never be read. A transparent composite actor is one without a director.
Workaround: Put a director in the composite. - Certain actors (such as the Integrator in CT) read parameter values only during initialization. During initialization, a PortParameter can only have a value set via the parameter (it can't have yet received a token). So if the initial value of the Integrator is set to the value of the PortParameter, then it will see only the parameter value, never the value provided via the port.
Workaround: Use a RunCompositeActor to contain the model with the Integrator.
@see ptolemy.actor.lib.Ramp
@see ParameterPort
@author Edward A. Lee
@version $Id: PortParameter.java,v 1.46 2007/02/04 07:34:35 cxh Exp $
@since Ptolemy II 3.0
@Pt.ProposedRating Green (eal)
@Pt.AcceptedRating Yellow (neuendor)