Class Buffer
A MOSAIC block that buffers incoming MathNet.Numerics.LinearAlgebra.Vector<T> or MathNet.Numerics.LinearAlgebra.Matrix<T>
messages into capture segments and stores them as (Target, Data) pairs.
JSON configuration
Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.
Block entry for a larger pipeline. Params is not used. CaptureStream must send a target vector first, observation vectors or matrices next, and null to finish the segment. Results are read from dB; this block publishes no samples.
{
"Buffer": {
"Type": "buffer",
"Inputs": ["CaptureStream"]
}
}
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public class Buffer : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
This block implements a simple start/stop capture mechanism:
-
Capture starts when tempFlag is
trueand the block is not currently collecting. The first received vector is stored as theTargetand is not added to the data rows. - Subsequent received vectors are appended as data rows. If a MathNet.Numerics.LinearAlgebra.Matrix<T> is received, each row is appended individually.
-
Capture stops when
dataisnullor tempFlag becomesfalse. On stop, the buffered rows are converted to a dense matrix (one row per vector) and added to dB.
Note: This block does not produce an output stream; it only accumulates data into dB.
Constructors
Buffer(string, double)
Initializes a new instance of the Buffer class.
Declaration
public Buffer(string name, double desiredRate = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| double | desiredRate |
Fields
_collecting
Indicates whether the block is currently collecting a capture segment.
Declaration
private bool _collecting
Field Value
| Type | Description |
|---|---|
| bool |
_rows
Temporarily stored data rows of the current capture segment.
Declaration
private readonly List<Vector<double>> _rows
Field Value
| Type | Description |
|---|---|
| List<Vector<double>> |
_target
The target vector for the current capture segment.
Declaration
private Vector<double>? _target
Field Value
| Type | Description |
|---|---|
| Vector<double> |
tempFlag
External gate controlling whether the buffer should capture.
Declaration
public bool tempFlag
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
When false, the block finalizes any ongoing capture and ignores incoming data.
Properties
dB
Gets the in-memory database of captured segments.
Declaration
public List<(Vector<double> Target, Matrix<double> Data)> dB { get; }
Property Value
| Type | Description |
|---|---|
| List<(Vector<double> Target, Matrix<double> Data)> |
Remarks
Each entry is a tuple (Target, Data) where:
Targetis the first vector received when capture starts.Datais a matrix built from subsequent vectors (one vector per row).
Methods
ConfigureInput(IServiceProvider, JsonModel)
Creates a Buffer instance using dependency injection and a JSON model definition.
Declaration
public static Buffer ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | |
| JsonModel | m |
Returns
| Type | Description |
|---|---|
| Buffer |
FinalizeSegment()
Finalizes the current capture segment: builds the data matrix and appends to dB.
Declaration
private void FinalizeSegment()
HandleMatrix(Matrix<double>)
Handles an incoming matrix: on start the first row becomes the target, remaining rows (and all rows on subsequent calls) are appended as data.
Declaration
private void HandleMatrix(Matrix<double> mat)
Parameters
| Type | Name | Description |
|---|---|---|
| Matrix<double> | mat |
HandleVector(Vector<double>)
Handles a single incoming vector: either stores as target (start) or appends as data row.
Declaration
private void HandleVector(Vector<double> vec)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | vec |
OnReceive(object, object?)
Receives incoming data and performs start/stop capture logic.
Declaration
protected override void OnReceive(object sender, object? data)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | The sender that emitted the message. |
| object | data | The incoming payload. Accepts MathNet.Numerics.LinearAlgebra.Vector<T> or MathNet.Numerics.LinearAlgebra.Matrix<T>.
|
Overrides
Remarks
Stop condition: data is null or tempFlag is false.
The current segment is finalized and appended to dB.
Start condition: The first valid vector received when not collecting is stored as the target. For Matrix start data, the first row is used as the target.
Data accumulation: Vectors are appended directly as rows. Matrices have each row appended individually, preserving temporal ordering.