Skip to main content

Data Object Merge

Author

WhiskerToolbox Team

Published

November 13, 2026

Overview

WhiskerToolbox provides utilities for copying or merging data between objects of the same type. Merge semantics are type-specific; v1 exposes overwrite-merge for ragged spatial types (LineData, MaskData, PointData).

Overwrite-merge (RaggedTimeSeries)

RaggedTimeSeries::mergeOverwriteTo() copies all entries from a source series into a target:

  • For each time present in the source, any existing target entries at that time are removed and replaced with the source entries.
  • Times present only in the target are left unchanged.
  • Source EntityIds are preserved in the target.
  • The source is not modified.

Preconditions

  • Source and target must not be the same object.
  • getTimeFrame() on both objects must be non-null and refer to the same TimeFrame instance (shared_ptr identity).
  • The target is materialized to owning storage if it currently uses a view or lazy backend.

EntityId collision handling

Before appending, the target removes:

  1. Any entries whose EntityIds appear anywhere in the source (cross-time collision safety).
  2. Any remaining entries at each source time (per-time overwrite).

API

// Type-level (on source, mutates target)
std::optional<std::size_t> merged =
    source->mergeOverwriteTo(*target, NotifyObservers::Yes);

// DataManager: both objects already registered by key
std::string error;
auto merged = mergeOverwriteData(dm, "target_key", "source_key", error);

// DataManager: pipeline output variant into an existing key (source not in dm)
DataTypeVariant pipeline_output = /* transform result */;
auto merged = mergeOverwriteData(dm, "output_key", pipeline_output, error);

The variant overload is used by DataManagerPipelineExecutor::storeOutputData(): when the output_key already exists and the type supports merge (supportsMergeOverwrite()), pipeline output is merged in place; otherwise the previous setData replace behavior applies.

Return value: entry count on success; std::nullopt on precondition or validation failure. A successful merge of zero entries returns 0.

Supported types (v1)

Type mergeOverwriteData
LineData Yes
MaskData Yes
PointData Yes
AnalogTimeSeries Not yet
RaggedAnalogTimeSeries Not yet
DigitalEventSeries Not yet
DigitalIntervalSeries Not yet
MediaData No
TensorData No

Future work

  • AnalogTimeSeries: upsert by TimeFrameIndex (overwrite overlapping samples, append new times).
  • DigitalEventSeries: append events; duplicate times skipped by addEvent.
  • DigitalIntervalSeries: append vs union policies (addEvent merges overlaps).
  • Command wrapper: MergeOverwriteData in the Command Architecture.
  • Move variant: merge then clear merged entries from source.