simtools.data.async
Class StreamingTSDataSource

java.lang.Object
  extended by simtools.data.ValueProvider
      extended by simtools.data.DataSource
          extended by simtools.data.async.TimeStampedDataSource
              extended by simtools.data.async.StreamingTSDataSource
Direct Known Subclasses:
StreamingMSDataSource

public class StreamingTSDataSource
extends TimeStampedDataSource

A streaming time stamped data source is a time stamped data source where the values are collected dynamically The source is updated using add(time, value). It keeps in memory in minimum number of time/values pairs according to constructor parameters

Author:
Claude Cazenave

Nested Class Summary
protected  class StreamingTSDataSource.AuxiliaryCollection
           
 class StreamingTSDataSource.StreamingTimeSource
           
 
Nested classes/interfaces inherited from class simtools.data.async.TimeStampedDataSource
TimeStampedDataSource.TimeSource
 
Field Summary
protected  double _dmax
           
protected  double _dmin
           
protected  int _lastIndex
           
protected  int _maxSize
          A maximal size for buffer buffer size
protected  double _minDuration
          The minimum duration is used to check when the buffer is filled if we have enough samples according to the time elpased between the first and the last sample.
protected  int _size
          The buffer size
protected  int _startIndex
           
protected  double[] _t
           
protected  double[] _t2
           
protected  TimeStampedDataSource.TimeSource _time2
          Auxiliary dataSource time2
protected  double[] _v
           
 
Fields inherited from class simtools.data.async.TimeStampedDataSource
_auxiliaries
 
Fields inherited from class simtools.data.DataSource
endNotificationListeners, listeners, sortedOrder
 
Fields inherited from class simtools.data.ValueProvider
ByteProvider, DoubleProvider, FloatProvider, IntegerProvider, kind, LongProvider, ObjectProvider, ShortProvider
 
Constructor Summary
StreamingTSDataSource(java.lang.String label, java.lang.String id, StreamingTSDataSourceCollection c, int minSize, int maxSize, double minDuration)
          Create a new data source with the following parameters
StreamingTSDataSource(java.lang.String label, java.lang.String id, StreamingTSDataSourceCollection c, int minSize, int maxSize, double minDuration, boolean withTime2)
          Create a new data source with the following parameters
 
Method Summary
 void add(double t, double v)
          Add a new pair of time,value and notify listeners
 void add(double t, double v, double t2)
          Add a new time,value,time2 and notify listeners
 void addValues(double t, double v, double t2)
          Add a new time,value,time2
protected  void computeMinMax()
           
 double getDoubleMax()
           
 double getDoubleMin()
           
 double getDoubleValue(long index)
          Optimized accessor for double values.
 double getEnd()
           
 long getLastIndex()
           
 java.lang.Object getMax()
           
 java.lang.Object getMin()
          Return values if possibly only, without expensive computations.
 double getStart()
           
 long getStartIndex()
           
 TimeStampedDataSource.TimeSource getTime2()
           
 java.lang.Object getValue(long index)
           
protected  void initialiseIndex(int minSize)
          Method initialiseIndex Summary: This method initialise the DataSource index.
 boolean isValid()
           
 void notifyAllEndNotificationListeners()
           
 void setTime2(TimeStampedDataSource.TimeSource time2)
           
 
Methods inherited from class simtools.data.async.TimeStampedDataSource
createEmptyDataSource, getAuxiliarySources, getCollection, getDataSourceInformationClass, getInfo, getInformation, getName, getTime, isCompound, setInfo, setMax, setMin, setMinmax, setTime, toString
 
Methods inherited from class simtools.data.DataSource
addEndNotificationListener, addListener, computeLastIndex, computeMax, computeMin, computeSortedOrder, computeStartIndex, equals, getByteMax, getByteMin, getChoiceFormat, getFloatMax, getFloatMin, getIntegerMax, getIntegerMin, getLongMax, getLongMin, getShortMax, getShortMin, getSortedOrder, getSourceDependencies, isAuxiliary, isComparable, notifyEndNotificationListeners, notifyListenersForDataReplaced, notifyListenersForDataReplaced, notifyListenersForIndexRangeChange, notifyListenersForInfoChange, notifyListenersForOrderChange, notifyListenersForValueChange, notifyListenersForValueRangeChange, removeEndNotificationListener, removeListener, setSlice, sortedOrder, updateSortedOrder
 
Methods inherited from class simtools.data.ValueProvider
getByteValue, getFloatValue, getIntegerValue, getKind, getLongValue, getObjectValue, getShortValue, valueClass
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_startIndex

protected int _startIndex

_lastIndex

protected int _lastIndex

_t

protected double[] _t

_t2

protected double[] _t2

_v

protected double[] _v

_dmin

protected double _dmin

_dmax

protected double _dmax

_size

protected int _size
The buffer size


_time2

protected TimeStampedDataSource.TimeSource _time2
Auxiliary dataSource time2


_minDuration

protected final double _minDuration
The minimum duration is used to check when the buffer is filled if we have enough samples according to the time elpased between the first and the last sample. If it is not the case the new buffer size is twice the previous size. Caution, since the duration criterion is met at buffer filling, the buffer size is no more modified and the buffer behaves as a ring buffer


_maxSize

protected int _maxSize
A maximal size for buffer buffer size

Constructor Detail

StreamingTSDataSource

public StreamingTSDataSource(java.lang.String label,
                             java.lang.String id,
                             StreamingTSDataSourceCollection c,
                             int minSize,
                             int maxSize,
                             double minDuration,
                             boolean withTime2)
                      throws java.io.IOException,
                             TimeStampedDataSourceCollection.InvalidFormatException
Create a new data source with the following parameters

Parameters:
label - The data source name
id - The data source id
c - Its collection parent
minSize - The minimum number of values to keep
maxSize - The maximum number of values to keep
minDuration - The minimun duration of value to keep
withTime2 - If true time2 values are also stored
Throws:
java.io.IOException
TimeStampedDataSourceCollection.InvalidFormatException

StreamingTSDataSource

public StreamingTSDataSource(java.lang.String label,
                             java.lang.String id,
                             StreamingTSDataSourceCollection c,
                             int minSize,
                             int maxSize,
                             double minDuration)
                      throws java.io.IOException,
                             TimeStampedDataSourceCollection.InvalidFormatException
Create a new data source with the following parameters

Parameters:
label - The data source name
id - The data source id
c - Its collection parent
minSize - The minimum number of values to keep
maxSize - The maximum number of values to keep
minDuration - The minimun duration of value to keep
Throws:
java.io.IOException
TimeStampedDataSourceCollection.InvalidFormatException
Method Detail

initialiseIndex

protected void initialiseIndex(int minSize)
Method initialiseIndex Summary: This method initialise the DataSource index.

Parameters:
minSize - The minSize to use at initialisation.

getStart

public double getStart()
                throws DataException
Specified by:
getStart in class TimeStampedDataSource
Throws:
DataException

getEnd

public double getEnd()
              throws DataException
Specified by:
getEnd in class TimeStampedDataSource
Throws:
DataException

computeMinMax

protected void computeMinMax()
                      throws UnsupportedOperation
Specified by:
computeMinMax in class TimeStampedDataSource
Throws:
UnsupportedOperation

getDoubleMin

public double getDoubleMin()
                    throws DataException
Overrides:
getDoubleMin in class TimeStampedDataSource
Throws:
DataException

getMin

public java.lang.Object getMin()
Description copied from class: DataSource
Return values if possibly only, without expensive computations.

Overrides:
getMin in class TimeStampedDataSource
Returns:
Returns the min.

getDoubleMax

public double getDoubleMax()
                    throws DataException
Overrides:
getDoubleMax in class TimeStampedDataSource
Throws:
DataException

getMax

public java.lang.Object getMax()
Overrides:
getMax in class TimeStampedDataSource
Returns:
Returns the max.

getValue

public java.lang.Object getValue(long index)
                          throws DataException
Specified by:
getValue in class TimeStampedDataSource
Throws:
DataException

getDoubleValue

public double getDoubleValue(long index)
                      throws DataException
Description copied from class: ValueProvider
Optimized accessor for double values. If the provider can provide doubles directly, then it should override this method. Otherwise, the default implementation will do its best to convert the Object returned by getValue() to a double. This conversion also parses strings, and returns 0 if it failed. An exception is thrown if, and only if, getValue throws it.

Specified by:
getDoubleValue in class TimeStampedDataSource
Throws:
DataException

getStartIndex

public long getStartIndex()
                   throws UnsupportedOperation
Specified by:
getStartIndex in class TimeStampedDataSource
Throws:
UnsupportedOperation

getLastIndex

public long getLastIndex()
                  throws UnsupportedOperation
Specified by:
getLastIndex in class TimeStampedDataSource
Throws:
UnsupportedOperation

isValid

public boolean isValid()
Specified by:
isValid in class TimeStampedDataSource
Returns:
true if it is valid

add

public void add(double t,
                double v)
Add a new pair of time,value and notify listeners

Parameters:
t -
v -

add

public void add(double t,
                double v,
                double t2)
Add a new time,value,time2 and notify listeners

Parameters:
t -
v -
t2 -
t2Enabled -

addValues

public void addValues(double t,
                      double v,
                      double t2)
Add a new time,value,time2

Parameters:
t -
v -
t2 -
t2Enabled -

notifyAllEndNotificationListeners

public void notifyAllEndNotificationListeners()

setTime2

public void setTime2(TimeStampedDataSource.TimeSource time2)
Parameters:
time - The time to set.

getTime2

public TimeStampedDataSource.TimeSource getTime2()
Returns:
Returns the _label.