ptolemy.actor.lib
Class Recorder

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Sink
                              extended by ptolemy.actor.lib.Recorder
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class Recorder
extends Sink

Record all input tokens for later querying. This actor can be used for testing configurations of actors. It can also be used in programs that invoke Ptolemy models and wish to query the results after the model is run. The input tokens are read in the postfire() method so that in domains with fixed-point semantics, only the final, settled value is recorded. The current time is also recorded for each value.

The capacity parameter limits the size of the record. If the capacity is set to zero, then no tokens are recorded, but the total number of input tokens is counted. You can access the count via the getCount() method. If the capacity is 1, then only the most recently seen token on each channel is recorded. If the capacity is negative (the default), then the capacity is infinite.

Since:
Ptolemy II 0.3
Version:
$Id: Recorder.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Green (bilung)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private static Token _bottom
           
private  int _count
           
(package private)  Token[] _latest
           
private  java.util.List _records
           
private  java.util.List _timeRecord
           
 Parameter capacity
          The capacity of the record for each channel.
 
Fields inherited from class ptolemy.actor.lib.Sink
input
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Recorder(CompositeEntity container, java.lang.String name)
          Construct an actor with an input multiport that can accept any Token.
 
Method Summary
 int getCount()
          Get the total number of events seen so far.
 java.util.List getHistory(int channel)
          Get the history for the specified channel number.
 Token getLatest(int channel)
          Get the latest input for the specified channel.
 java.util.Enumeration getRecord(int channel)
          Deprecated. This method is deprecated. Use getHistory().
 java.util.List getTimeHistory()
          Get the history of the time of each invocation of postfire().
 java.util.Enumeration getTimeRecord()
          Deprecated. This method is deprecated. Use getTimeHistory().
 void initialize()
          Initialize the lists used to record input data.
 boolean postfire()
          Read at most one token from each input channel and record its value.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

capacity

public Parameter capacity
The capacity of the record for each channel. This parameter must contain an IntToken.


_count

private int _count

_records

private java.util.List _records

_latest

Token[] _latest

_timeRecord

private java.util.List _timeRecord

_bottom

private static Token _bottom
Constructor Detail

Recorder

public Recorder(CompositeEntity container,
                java.lang.String name)
         throws NameDuplicationException,
                IllegalActionException
Construct an actor with an input multiport that can accept any Token.

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

getCount

public int getCount()
Get the total number of events seen so far.

Returns:
The total number of events seen so far.

getHistory

public java.util.List getHistory(int channel)
Get the history for the specified channel number. If in any firing there is no such channel, or no token was read on that channel, then a string token with value "_" is returned in the position of the list corresponding to that firing. If nothing has been recorded (there have been no firings), then return an empty list.

Parameters:
channel - The input channel for which the history is desired.
Returns:
A list of Token objects.

getLatest

public Token getLatest(int channel)
Get the latest input for the specified channel. If there has been no record yet for the specified channel, then return the string token "_", representing "bottom".

Parameters:
channel - The input channel for the record is desired.
Returns:
The latest input token.

getRecord

public java.util.Enumeration getRecord(int channel)
Deprecated. This method is deprecated. Use getHistory().

Get the record for the specified channel number. If in any firing there is no such channel, or no token was read on that channel, then a string token with value "_" is returned. If nothing has been recorded (there have been no firings), then return an empty enumeration.

Parameters:
channel - The input channel for the record is desired.
Returns:
An enumeration of Token objects.

getTimeHistory

public java.util.List getTimeHistory()
Get the history of the time of each invocation of postfire().

Returns:
A list of Double objects.

getTimeRecord

public java.util.Enumeration getTimeRecord()
Deprecated. This method is deprecated. Use getTimeHistory().

Get the record of the current time of each invocation of postfire().

Returns:
An enumeration of Double objects.

initialize

public void initialize()
                throws IllegalActionException
Initialize the lists used to record input data.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it.

postfire

public boolean postfire()
                 throws IllegalActionException
Read at most one token from each input channel and record its value.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If there is no director.