Acquisition
Class AcquisitionProcess

java.lang.Object
  extended by PamguardMVC.PamProcess
      extended by Acquisition.AcquisitionProcess
All Implemented Interfaces:
Annotator, PamObserver

public class AcquisitionProcess
extends PamProcess

Data acquisition process for all types of input device. This arranges the output data block and starts and stops the device in the detected DaqSystem. Each DaqSystem should operate a different thread to read the device / file and add its data to the volatile Vector newDataUnits. AcquisitonProcess will poll newDataUnits on a timer and when new data is found, put that data into PamDataUnits and PamRawDataBlocks to be sent out for processing.

Author:
Doug Gillespie
See Also:
DaqSystem, PamRawDataBlock, PamDataUnit

Nested Class Summary
(package private)  class AcquisitionProcess.BufferTimerTest
           
(package private)  class AcquisitionProcess.ReallyStart
           
(package private)  class AcquisitionProcess.RestartTimerFunction
           
(package private)  class AcquisitionProcess.WaitForData
           
 
Field Summary
(package private)  AcquisitionControl acquisitionControl
           
(package private)  AcquisitionProcess acquisitionProcess
           
private  boolean bufferOverflow
           
(package private)  javax.swing.Timer bufferTimer
           
(package private)  java.lang.Thread collectDataThread
           
(package private)  int counts
           
private  PamDataBlock<DaqStatusDataUnit> daqStatusDataBlock
           
private  int dataBlockLength
           
(package private)  double fixedAmplitudeConstantTerm
          A Constant used for fast amplitude calculations when things like preamp gain will remain constant.
private  boolean keepRunning
           
private  double lastError
           
(package private)  long levelSamples
           
(package private)  double maxLevel
           
private  java.util.List<RawDataUnit> newDataUnits
           
(package private)  double[] rawData
           
private  PamRawDataBlock rawDataBlock
           
private  javax.swing.Timer restartTimer
           
private  java.lang.Object runingSynchObject
           
private  DaqSystem runningSystem
           
private  double sqrt2
           
private  boolean systemPrepared
           
(package private)  long[] totalSamples
           
(package private)  int trials
           
 
Fields inherited from class PamguardMVC.PamProcess
outputDataBlocks, processName, sampleRate
 
Constructor Summary
protected AcquisitionProcess(AcquisitionControl acquisitionControl)
           
protected AcquisitionProcess(AcquisitionControl acquisitionControl, boolean isSimulator)
           
 
Method Summary
private  boolean acquireData()
           
 void acquisitionStopped()
           
private  double checkClockSpeed(long totalSamples, int print)
          Check and optionally display clock speed error
private  void clearData()
           
 double dbMicropascalToSignal(int channel, double dBMuPascal)
           
 double[] fftAmplitude2dB(double[] fftAmplitude, int channel, int fftLength, boolean isSquared)
          Convert the amplitude of fft data into a spectrum level measurement in dB re 1 micropacal / sqrt(Hz) for an array of double values.
 double fftAmplitude2dB(double fftAmplitude, int channel, int fftLength, boolean isSquared, boolean fast)
          Convert the amplitude of fft data into a spectrum level measurement in dB re 1 micropacal / sqrt(Hz).
 double fftBandAmplitude2dB(double fftAmplitude, int channel, int fftLength, boolean isSquared, boolean fast)
          Convert the amplitude of fft data into a level measurement in dB re 1 micropacal / sqrt(Hz).
 AcquisitionControl getAcquisitionControl()
           
private  double getAmplitudeConstantTerm(int channel)
          Gets the fixedAmplitudeConstantTerm based on channel and hydrophone numbers.
 double getBufferSeconds()
           
 double getMaxBufferSeconds()
           
 java.util.List<RawDataUnit> getNewDataUnits()
           
 int getOfflineData(PamDataBlock dataBlock, PamObserver endUser, long startMillis, long endMillis)
          Request offline data.
 double getPeak2PeakVoltage(int swChannel)
          Some devices may be setting this per channel.
 PamRawDataBlock getRawDataBlock()
           
 DaqSystem getRunningSystem()
           
 boolean needRestart()
           
 void newData(PamObservable o, PamDataUnit arg)
           
 void pamStart()
          Interval between daq checks in milliseconds
 void pamStop()
          Stops the process.
 void pamStop(java.lang.String reason)
           
 void prepareFastAmplitudeCalculation(int channel)
          Prepares for fast amplitude calculations
 void prepareProcess()
          Called for each process before any of them receive the PamStart command
 double[] rawAmplitude2dB(double[] rawAmplitude, int channel)
          Convert a raw amplitude to dB re 1 micropascal based on calibration information held in the AcquisitionController for an array of double data
 double rawAmplitude2dB(double rawAmplitude, int channel, boolean fast)
          Convert a raw amplitude to dB re 1 micropascal based on calibration information held in the AcquisitionController
 void setNumChannels(int numChannels)
           
 void setNumChannels(int numChannels, int[] channelList)
          Set up channels when using a channel list - note that hardware channels are no longer passed through the system so software channels are now used throughout.
 void setSampleRate(float sampleRate, boolean notify)
          New sample rate
 void setupDataBlock()
          called when acquisition parameters change.
private  boolean shouldPrintSoundCardError(double error)
           
 void streamClosed()
           
 void streamEnded()
           
 void streamOpen()
           
 void streamPaused()
           
 
Methods inherited from class PamguardMVC.PamProcess
absMillisecondsToSamples, absSamplesToMilliseconds, addOutputDataBlock, changedThreading, clearOldData, createAnnotations, destroyProcess, fillXMLElement, fillXMLParameters, getAncestorDataBlock, getAnnotation, getBackendProcess, getChainPosition, getCpuPercent, getNumAnnotations, getNumOutputDataBlocks, getObserverName, getObserverObject, getOutputDataBlock, getPamControlledUnit, getParentDataBlock, getParentProcess, getProcessName, getRawSourceDataBlock, getRequiredDataHistory, getSampleRate, getSourceDataBlock, getSourceProcess, isCanMultiThread, makePamProcess, masterClockUpdate, noteNewSettings, notifyModelChanged, relMillisecondsToSamples, relSamplesToMilliseconds, removeObservable, removeOutputDatablock, saveViewerData, setBackendProcess, setCanMultiThread, setParentDataBlock, setParentDataBlock, setProcessName, setupProcess, toString, update, updateData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

acquisitionControl

AcquisitionControl acquisitionControl

runningSystem

private volatile DaqSystem runningSystem

rawDataBlock

private PamRawDataBlock rawDataBlock

daqStatusDataBlock

private PamDataBlock<DaqStatusDataUnit> daqStatusDataBlock

newDataUnits

private volatile java.util.List<RawDataUnit> newDataUnits

acquisitionProcess

AcquisitionProcess acquisitionProcess

dataBlockLength

private int dataBlockLength

totalSamples

long[] totalSamples

keepRunning

private volatile boolean keepRunning

bufferOverflow

private volatile boolean bufferOverflow

restartTimer

private javax.swing.Timer restartTimer

sqrt2

private final double sqrt2

runingSynchObject

private java.lang.Object runingSynchObject

systemPrepared

private boolean systemPrepared

collectDataThread

java.lang.Thread collectDataThread

bufferTimer

javax.swing.Timer bufferTimer

trials

int trials

counts

int counts

maxLevel

double maxLevel

levelSamples

long levelSamples

rawData

double[] rawData

lastError

private double lastError

fixedAmplitudeConstantTerm

double fixedAmplitudeConstantTerm
A Constant used for fast amplitude calculations when things like preamp gain will remain constant. Contains a constant term in the SPL calculations bases on preamp gains and hdrophone sensitivities.

Constructor Detail

AcquisitionProcess

protected AcquisitionProcess(AcquisitionControl acquisitionControl)

AcquisitionProcess

protected AcquisitionProcess(AcquisitionControl acquisitionControl,
                             boolean isSimulator)
Method Detail

setupDataBlock

public void setupDataBlock()
called when acquisition parameters change.


pamStart

public void pamStart()
Interval between daq checks in milliseconds

Specified by:
pamStart in class PamProcess

pamStop

public void pamStop()
Description copied from class: PamProcess
Stops the process.

Specified by:
pamStop in class PamProcess

pamStop

public void pamStop(java.lang.String reason)

acquisitionStopped

public void acquisitionStopped()

prepareProcess

public void prepareProcess()
Description copied from class: PamProcess
Called for each process before any of them receive the PamStart command

Overrides:
prepareProcess in class PamProcess

setSampleRate

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

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

setNumChannels

public void setNumChannels(int numChannels)

setNumChannels

public void setNumChannels(int numChannels,
                           int[] channelList)
Set up channels when using a channel list - note that hardware channels are no longer passed through the system so software channels are now used throughout.

Parameters:
numChannels -
channelList -

streamClosed

public void streamClosed()

streamEnded

public void streamEnded()

streamOpen

public void streamOpen()

streamPaused

public void streamPaused()

acquireData

private boolean acquireData()

clearData

private void clearData()

checkClockSpeed

private double checkClockSpeed(long totalSamples,
                               int print)
Check and optionally display clock speed error

Parameters:
totalSamples - total samples acquired
print - 0 = never, 1 = if the error is > .2%, 2 always
Returns:
% clock speed error

shouldPrintSoundCardError

private boolean shouldPrintSoundCardError(double error)

getBufferSeconds

public double getBufferSeconds()

getMaxBufferSeconds

public double getMaxBufferSeconds()
Returns:
the maximum number of seconds of data which can be buffered. This used to be fixed at 3, but now that individual raw data blocks contain >> 1s of data for low frequency DAQ, this can be exceeded in a single data unit, which causes continual resets.

needRestart

public boolean needRestart()

newData

public void newData(PamObservable o,
                    PamDataUnit arg)
Overrides:
newData in class PamProcess

getNewDataUnits

public java.util.List<RawDataUnit> getNewDataUnits()

getRunningSystem

public DaqSystem getRunningSystem()

rawAmplitude2dB

public double rawAmplitude2dB(double rawAmplitude,
                              int channel,
                              boolean fast)
Convert a raw amplitude to dB re 1 micropascal based on calibration information held in the AcquisitionController

Parameters:
rawAmplitude - raw amplitude (should be -1 < rawAmplitude < 1)
Returns:
amplitude in dB re 1 uPa.

getPeak2PeakVoltage

public double getPeak2PeakVoltage(int swChannel)
Some devices may be setting this per channel.

Parameters:
swChannel - software channel number
Returns:
peak to peak voltage range.

getAmplitudeConstantTerm

private double getAmplitudeConstantTerm(int channel)
Gets the fixedAmplitudeConstantTerm based on channel and hydrophone numbers.

Parameters:
channel - = single software channel
Returns:
constant term for amplitude calculations

prepareFastAmplitudeCalculation

public void prepareFastAmplitudeCalculation(int channel)
Prepares for fast amplitude calculations

Parameters:
channel -

rawAmplitude2dB

public double[] rawAmplitude2dB(double[] rawAmplitude,
                                int channel)
Convert a raw amplitude to dB re 1 micropascal based on calibration information held in the AcquisitionController for an array of double data

Parameters:
rawAmplitude - raw amplitude (should be -1 < rawAmplitude < 1)
Returns:
amplitude in dB re 1 uPa.

fftAmplitude2dB

public double fftAmplitude2dB(double fftAmplitude,
                              int channel,
                              int fftLength,
                              boolean isSquared,
                              boolean fast)
Convert the amplitude of fft data into a spectrum level measurement in dB re 1 micropacal / sqrt(Hz).

Parameters:
fftAmplitude - magnitude of the fft data (not the magnitude squared !)
fftLength - lengthof the fft (needed for Parsevals correction)
Returns:
spectrum level amplitude.

fftBandAmplitude2dB

public double fftBandAmplitude2dB(double fftAmplitude,
                                  int channel,
                                  int fftLength,
                                  boolean isSquared,
                                  boolean fast)
Convert the amplitude of fft data into a level measurement in dB re 1 micropacal / sqrt(Hz).

Note that this function differs from fftAmplitude2dB in that this one used the FFT length to correct for Parsevals theorum and integratin over the length of the FFT, but it does NOT convert the result to a spectrum level measurement.

Parameters:
fftAmplitude - magnitude of the fft data (not the magnitude squared !)
fftLength - lengthof the fft (needed for Parsevals correction)
Returns:
level amplitude in dB

fftAmplitude2dB

public double[] fftAmplitude2dB(double[] fftAmplitude,
                                int channel,
                                int fftLength,
                                boolean isSquared)
Convert the amplitude of fft data into a spectrum level measurement in dB re 1 micropacal / sqrt(Hz) for an array of double values.

Parameters:
fftAmplitude - magnitude of the fft data (not the magnitude squared !)
fftLength - lengthof the fft (needed for Parsevals correction)
Returns:
spectrum level amplitude.

dbMicropascalToSignal

public double dbMicropascalToSignal(int channel,
                                    double dBMuPascal)

getAcquisitionControl

public AcquisitionControl getAcquisitionControl()
Returns:
Returns the acquisitionControl.

getRawDataBlock

public PamRawDataBlock getRawDataBlock()
Returns:
the rawDataBlock

getOfflineData

public int getOfflineData(PamDataBlock dataBlock,
                          PamObserver endUser,
                          long startMillis,
                          long endMillis)
Description copied from class: PamProcess
Request offline data.

This will be called from a PamDatablock in offline viewer mode from requestOfflineData(PamObserver observer, long startMillis, long endMillis).

this is used to request data from upstream processes, e.g. o get raw data to turn into FFT data units to go to the spectrogram display (possible going via decimators and any other processes before spitting out the right data.

Overrides:
getOfflineData in class PamProcess
Parameters:
dataBlock - data block making the request.
endUser - observer which made the original data request.
startMillis - start time in milliseconds
endMillis - end time in milliseconds.
Returns:
true if request can be satisfied (or partially satisfied).