PamguardMVC
Class PamProcess

java.lang.Object
  extended by PamguardMVC.PamProcess
All Implemented Interfaces:
PamObserver
Direct Known Subclasses:
AcquireNmeaData, AcquisitionProcess, AirgunProcess, AmpProcess, AngleProcess, BeakedProcess, ClickDetector, ClickTrainDetector, DBProcess, DecimatorProcess, DepthProcess, EdgeProcess, FilterProcess, IshDetFnProcess, IshLocProcess, IshPeakProcess, KernelSmoothingProcess, LikelihoodFFTProcess, LinearAverageSpectraProcess, ListeningProcess, MapProcess, NormalizerProcess, PamFFTProcess, PatchPanelProcess, PeakDetector, PlaybackProcess, ProcessAISData, ProcessIshmaelData, ProcessNmeaData, RecorderProcess, SimProcess, SpectralEtiProcess, SpectrogramMarkProcess, SpectrogramNoiseProcess, TerrellaProcess, ThresholdDetectorProcess, TowedArray3DProcess, TrackedClickLocaliser, UserInputProcess, VetoProcess, VRProcess, WhistleClassifierProcess, WhistleDetector, WhistleEventDetector, WhistleLinker, WorkshopProcess

public abstract class PamProcess
extends Object
implements PamObserver

Author:
Doug Gillespie

PamProcess is an abstract class used as a supertype for the creation of processes which either convert one type of PamData into a new type or add existing information to already existing data

All PamProcesses are Listeners and implement the Observer Class from java.util

The first PamProcess to be created will often be something which generates raw data (either by reading an input device or by reading chunks of data from a file).

Each PamProcess will require a source of data, which apart from the top level processes which acquire data, will be a PamDataBlock. The PamProcess will generally subscribe to the PamDataBlock so that it is notified of any changes (i.e. new data) being added to that block.

The PamController ...


Field Summary
protected  ArrayList<PamDataBlock> outputDataBlocks
           
protected  String processName
           
protected  float sampleRate
           
 
Constructor Summary
PamProcess(PamControlledUnit pamControlledUnit, PamDataBlock parentDataBlock)
           
PamProcess(PamControlledUnit pamControlledUnit, PamDataBlock parentDataBlock, String processName)
           
 
Method Summary
 long absMillisecondsToSamples(long millis)
          Convert a time in milli seconds to a number of samples.
 long absSamplesToMilliseconds(long samples)
          Convert am ADC sample number to a millisecond time.
 void addOutputDataBlock(PamDataBlock outputDataBlock)
          Adds an additional PamDataBlock to the process
 void changedThreading()
          Function that gets called in every process (or all processes that are listed in PamControlledUnits) and re-sets up the data source using the correct threading model.
 void clearOldData()
          Clears all data from all output data blocks of this process
 void destroyProcess()
          Called from the PamControlled unit when a PamControlled unit is removed from the model.
 PamDataBlock getAncestorDataBlock(Class unitDataType)
          Useful function to go back through the chain of data blocks and data units upstream of this process and look for a data block which has a particular data type.
 int getChainPosition()
           
 double getCpuPercent()
           
 int getNumOutputDataBlocks()
           
 String getObserverName()
           
 PamDataBlock getOutputDataBlock(int block)
          Each process may produce multiple data blocks.
 PamControlledUnit getPamControlledUnit()
           
 PamDataBlock getParentDataBlock()
           
 PamProcess getParentProcess()
           
 String getProcessName()
           
 PamRawDataBlock getRawSourceDataBlock(float sampleRate)
          Find the absolute source of raw audio data if one exists
 long getRequiredDataHistory(PamObservable o, Object arg)
           
 float getSampleRate()
           
 PamDataBlock<PamDataUnit> getSourceDataBlock()
          find the absolute source of data, if one exists.
 PamProcess getSourceProcess()
           
 void makePamProcess(PamControlledUnit pamControlledUnit, PamDataBlock parentDataBlock, String processName)
           
 void masterClockUpdate(long timeMilliseconds, long sampleNumber)
           
 void newData(PamObservable o, PamDataUnit arg)
           
 void noteNewSettings()
           
abstract  void pamStart()
          Called for each process to tell it to start (may not be necessary for processes which are listening for data anyway.
abstract  void pamStop()
          Stops the process.
 void prepareProcess()
          Called for each process before any of them receive the PamStart command
 long relMillisecondsToSamples(double millis)
          Convert a number of milliseconds to a number of samples.
 long relSamplesToMilliseconds(long samples)
          Convert a number of samples into a number of milliseconds
 void removeObservable(PamObservable observable)
          Called when a PamDataBlock observed by this PamProcess is removed.
 void removeOutputDatablock(PamDataBlock outputDataBlock)
           
 void setParentDataBlock(PamDataBlock newParentDataBlock)
           
 void setProcessName(String processName)
           
 void setSampleRate(float sampleRate, boolean notify)
          New sample rate
 void setupProcess()
          called for every process once the systemmodel has been created.
 String toString()
           
 void update(PamObservable o, PamDataUnit arg)
          Informs the PamObserver that new data have been added to the Observable class
 void updateData(PamObservable o, PamDataUnit arg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

outputDataBlocks

protected ArrayList<PamDataBlock> outputDataBlocks

processName

protected String processName

sampleRate

protected float sampleRate
Constructor Detail

PamProcess

public PamProcess(PamControlledUnit pamControlledUnit,
                  PamDataBlock parentDataBlock)
Parameters:
pamControlledUnit - Reference to the PamControlledUnit containing this process (PamProcesses can only exist within PamControlledUnits, but a PamControlledUnit can contain multiple PamProcesses)
parentDataBlock - Source data block for this process (can be null for raw data input devices)

PamProcess

public PamProcess(PamControlledUnit pamControlledUnit,
                  PamDataBlock parentDataBlock,
                  String processName)
Method Detail

destroyProcess

public void destroyProcess()
Called from the PamControlled unit when a PamControlled unit is removed from the model. Offers an opportunity to disconnect individual processed from the rest of the model. May be necessary to override to clean up some processes.


makePamProcess

public void makePamProcess(PamControlledUnit pamControlledUnit,
                           PamDataBlock parentDataBlock,
                           String processName)

getParentDataBlock

public PamDataBlock getParentDataBlock()
Returns:
Returns the parentDataBlock.

getParentProcess

public PamProcess getParentProcess()

getAncestorDataBlock

public PamDataBlock getAncestorDataBlock(Class unitDataType)
Useful function to go back through the chain of data blocks and data units upstream of this process and look for a data block which has a particular data type. For instance, you may want the raw audio data upstream of FFT data. This may not be the data input to the FFT source, since you may be looking at some secondary FFT data source (smoothed, or noise supressed spectrogram data for instance).

Parameters:
unitDataType - class type of data in the sought after data block (e.g. RawDataUnit.class
Returns:
reference to data block or null if none found
See Also:
PamDataBlock

setParentDataBlock

public void setParentDataBlock(PamDataBlock newParentDataBlock)
Parameters:
newParentDataBlock - The parentDataBlock to set.

changedThreading

public void changedThreading()
Function that gets called in every process (or all processes that are listed in PamControlledUnits) and re-sets up the data source using the correct threading model. All this actually involves is resubscribing to the same data since everything else is handled in setParentDataBlock;


setProcessName

public void setProcessName(String processName)
Parameters:
processName - Sets the name of the process

getProcessName

public String getProcessName()
Returns:
Name of the PamProcess

getObserverName

public String getObserverName()
Specified by:
getObserverName in interface PamObserver

setSampleRate

public void setSampleRate(float sampleRate,
                          boolean notify)
Description copied from interface: PamObserver
New sample rate

Specified by:
setSampleRate in interface PamObserver
notify - Notify other PamObservers and PamObservables in the chain.

masterClockUpdate

public void masterClockUpdate(long timeMilliseconds,
                              long sampleNumber)
Specified by:
masterClockUpdate in interface PamObserver

relSamplesToMilliseconds

public long relSamplesToMilliseconds(long samples)
Convert a number of samples into a number of milliseconds

Parameters:
samples - Number of ADC samples
Returns:
equivalent number of milliseconds

absSamplesToMilliseconds

public long absSamplesToMilliseconds(long samples)
Convert am ADC sample number to a millisecond time. This function was re-written on 11/11/08 to deal with problems of sound card clocks not running at same speed as PC clock, so milliseconds from PC clock and milliseconds based on samples would drift apart. This new system bases the calculation on the times of the most recently received data unit.

Parameters:
samples - sample number (from start of run)
Returns:
Millisecond time (UTC milliseconds from the epoch - the standard Java way)

absMillisecondsToSamples

public long absMillisecondsToSamples(long millis)
Convert a time in milli seconds to a number of samples.

Parameters:
millis - Current time in milliseconds (UTC millseconds from the epoch - the standard Java way)
Returns:
ADC Samples since the run start.
See Also:
relMillisecondsToSamples(double)

relMillisecondsToSamples

public long relMillisecondsToSamples(double millis)
Convert a number of milliseconds to a number of samples.

Parameters:
millis - number of milliseconds
Returns:
number of ADC samples corresponding to millis milliseconds.
See Also:
absMillisecondsToSamples(long)

noteNewSettings

public void noteNewSettings()
Specified by:
noteNewSettings in interface PamObserver

getSampleRate

public float getSampleRate()
Returns:
The sample rate in the process

getSourceProcess

public PamProcess getSourceProcess()
Returns:
The original data source process, i.e. the one reading the soundcard or the file, the one that doesn't have a parentDataBlock

getSourceDataBlock

public PamDataBlock<PamDataUnit> getSourceDataBlock()
find the absolute source of data, if one exists. i.e. the data output of a process that has no data input.

If this is called from within acquisition, it will return null

It there is no raw data source, i.e. if the type is not PamRawDataBlock, then return null.

Returns:
a PamRawDataBlock or null

getRawSourceDataBlock

public PamRawDataBlock getRawSourceDataBlock(float sampleRate)
Find the absolute source of raw audio data if one exists

Returns:
a PamRawDataBlock or null

getChainPosition

public int getChainPosition()

getOutputDataBlock

public PamDataBlock getOutputDataBlock(int block)
Each process may produce multiple data blocks. This returns the reference to a specific block

Parameters:
block - Index of the required block
Returns:
PamDataBlock

getNumOutputDataBlocks

public int getNumOutputDataBlocks()
Returns:
Total number of PamDataBlocks created by this process

addOutputDataBlock

public void addOutputDataBlock(PamDataBlock outputDataBlock)
Adds an additional PamDataBlock to the process

Parameters:
outputDataBlock - Reference to a PamDataBlock

removeOutputDatablock

public void removeOutputDatablock(PamDataBlock outputDataBlock)

toString

public String toString()
Overrides:
toString in class Object

clearOldData

public void clearOldData()
Clears all data from all output data blocks of this process


prepareProcess

public void prepareProcess()
Called for each process before any of them receive the PamStart command


getRequiredDataHistory

public long getRequiredDataHistory(PamObservable o,
                                   Object arg)
Specified by:
getRequiredDataHistory in interface PamObserver
Parameters:
o - PamObservable class requiring the data
arg - optional argument from PamObservable
Returns:
time in milliseconds requried by data held in PamObservable

update

public final void update(PamObservable o,
                         PamDataUnit arg)
Description copied from interface: PamObserver
Informs the PamObserver that new data have been added to the Observable class

Specified by:
update in interface PamObserver
Parameters:
o - Reference to the Observable (a PamDataBlock)
arg - Reference to the new PamDataUnit

newData

public void newData(PamObservable o,
                    PamDataUnit arg)

updateData

public void updateData(PamObservable o,
                       PamDataUnit arg)

setupProcess

public void setupProcess()
called for every process once the systemmodel has been created. this is a good time to check out and find input data blocks and similar tasks.


getCpuPercent

public double getCpuPercent()

pamStart

public abstract void pamStart()
Called for each process to tell it to start (may not be necessary for processes which are listening for data anyway.


pamStop

public abstract void pamStop()
Stops the process.


removeObservable

public void removeObservable(PamObservable observable)
Called when a PamDataBlock observed by this PamProcess is removed.

Specified by:
removeObservable in interface PamObserver

getPamControlledUnit

public PamControlledUnit getPamControlledUnit()