Class MostRecent

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    Register

    public class MostRecent
    extends Transformer
    Output the most recent input token when the trigger port receives a token. If no token has been received on the input port when a token is received on the trigger port, then the value of the initialValue parameter is produced. If, however, the initialValue parameter contains no value, then no output is produced. The inputs can be of any token type, but the output port is constrained to be of a type at least that of the input port and the initialValue parameter (if it has a value).

    Both the input port and the output port are multiports. Generally, their widths should match. Otherwise, if the width of the input is greater than the width of the output, the extra input tokens will not appear on any output, although they will be consumed from the input port. If the width of the output is greater than that of the input, then the last few channels of the output will never emit tokens.

    The trigger port is a multiport. Whenever a trigger is received on any channel the actor fires and produces an output. Multiple triggers with the same timestamp are considered as one trigger.

    Note: If the width of the input changes during execution, then the most recent inputs are forgotten, as if the execution of the model were starting over.

    This actor is similar to the Inhibit actor in that it modifies a stream of events based on the presence or absence of events from another input. This actor reacts to the presence of the other event, whereas Inhibit reacts to the absence of it.

    This actor is different from the Register actor in that the input tokens are consumed from the input ports before the outputs are generated. Note that this actor is also different from the Sampler actor, which produces the current input on the output when a trigger input is present, rather than the most recently received input signal.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Jie Liu, Edward A. Lee, Steve Neuendorffer, Elaine Cheong
    See Also:
    Inhibit, Register
    Pt.AcceptedRating:
    Yellow (eal)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • trigger

        public TypedIOPort trigger
        The trigger port, which has undeclared type. If this port receives a token, then the most recent token from the input port will be emitted on the output port.
      • initialValue

        public Parameter initialValue
        The value that is output when no input has yet been received. If this is changed during execution, then the output will match the new value until another input is received. The type should be the same as the input port.
        See Also:
        TypedAtomicActor.typeConstraints()
      • _lastInputs

        protected Token[] _lastInputs
        The recorded inputs last seen.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        If the initialValue parameter is the argument, then reset the current output to match the new value.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If the change is not acceptable to this container (not thrown in this base class).
      • fire

        public void fire()
                  throws IllegalActionException
        Consume all the tokens in the input ports and record them. If there is a token in the trigger port, emit the most recent token from the input port. If there has been no input token, but the initialValue parameter has been set, emit the value of the initialValue parameter. Otherwise, emit nothing.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If there is no director.
      • prefire

        public boolean prefire()
                        throws IllegalActionException
        If there is no input on the trigger port, return false, indicating that this actor does not want to fire. This has the effect of leaving input values in the input ports, if there are any.
        Specified by:
        prefire in interface Executable
        Overrides:
        prefire in class AtomicActor<TypedIOPort>
        Returns:
        True if this actor is ready for firing, false otherwise.
        Throws:
        IllegalActionException - If there is no director.
      • _containedTypeConstraints

        public java.util.Set<Inequality> _containedTypeConstraints()
        Adds two inequalities to the set returned by the overridden method that together constrain the input to be equal to the type of the initial value.
        Overrides:
        _containedTypeConstraints in class TypedAtomicActor
        Returns:
        A set of type constraints
      • readInputs

        protected void readInputs​(int commonWidth,
                                  int inputWidth)
                           throws IllegalActionException
        Consume inputs and save them. Discard inputs on input channels that do not have corresponding output channels.
        Parameters:
        commonWidth - The minimum of the input and the output width.
        inputWidth - The width of the input port.
        Throws:
        IllegalActionException - Thrown if port tokens cannot be accessed.
      • sendOutputIfTriggered

        protected void sendOutputIfTriggered​(int commonWidth)
                                      throws IllegalActionException
        Send output tokens if any input on the trigger port has a token. All trigger tokens are consumed.
        Parameters:
        commonWidth - The minimum of the input and the output port width.
        Throws:
        IllegalActionException - Thrown if the width or the token of the trigger port cannot be accessed or if tokens cannot be sent on the output port.