ptolemy.domains.de.lib
Class Sampler

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.domains.de.kernel.DEActor
                              extended byptolemy.domains.de.lib.DETransformer
                                  extended byptolemy.domains.de.lib.Sampler
All Implemented Interfaces:
Actor, Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, SequenceActor, java.io.Serializable, TimedActor, TypedActor

public class Sampler
extends DETransformer

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, and the output is constrained to be of a type at least that of the input.

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.

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.

Since:
Ptolemy II 0.3
Version:
$Id: Sampler.java,v 1.34 2004/04/13 05:13:06 cxh Exp $
Author:
Jie Liu, Edward A. Lee, Steve Neuendorffer, Elaine Cheong
See Also:
Inhibit, Serialized Form
Accepted Rating:
Yellow (eal)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
 Parameter initialValue
          The value that is output when no input has yet been received.
 TypedIOPort trigger
          The trigger port, which has undeclared type.
 
Fields inherited from class ptolemy.domains.de.lib.DETransformer
input, output
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Sampler(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          If there is a token in the trigger port, emit the most recent token from the input port.
 boolean prefire()
          If there is no input on the trigger port, return false, indicating that this actor does not want to fire.
 void preinitialize()
          Clear the cached input tokens.
 java.util.List typeConstraintList()
          Override the method in the base class so that the type constraint for the initialValue parameter will be set if it contains a value.
 
Methods inherited from class ptolemy.domains.de.kernel.DEActor
newPort
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, postfire, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
initialize, iterate, postfire, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

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. The type should be the same as the input port.

See Also:
typeConstraintList()
Constructor Detail

Sampler

public Sampler(CompositeEntity container,
               java.lang.String name)
        throws NameDuplicationException,
               IllegalActionException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the ports.

Overrides:
clone in class AtomicActor
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class has has an attribute that cannot be cloned.

fire

public void fire()
          throws IllegalActionException
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
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
Returns:
True if this actor is ready for firing, false otherwise.
Throws:
IllegalActionException - If there is no director.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Clear the cached input tokens.

Specified by:
preinitialize in interface Executable
Overrides:
preinitialize in class AtomicActor
Throws:
IllegalActionException - If there is no director.

typeConstraintList

public java.util.List typeConstraintList()
Override the method in the base class so that the type constraint for the initialValue parameter will be set if it contains a value.

Specified by:
typeConstraintList in interface TypedActor
Overrides:
typeConstraintList in class TypedAtomicActor
Returns:
a list of Inequality objects.
See Also:
Inequality