FidStorageBase

FidStorageBase extends DataStorageBase to manage free-induction decay (FID) waveforms for CP-FTMW acquisitions. It holds a fixed number of FID records per segment (d_numRecords) and implements the DataStorageBase lifecycle methods. The constructor reads any existing fid/fidparams.csv into an internal template list so that on-disk data can be accessed without re-reading the full experiment.

Three concrete subclasses cover the standard acquisition modes:

  • FidSingleStorage — a single persistent FID segment with optional backup snapshots (single-segment and target-shots modes).

  • FidMultiStorage — multiple FID segments for LO-scan and DR-scan acquisitions.

  • FidPeakUpStorage — a transient rolling-average store for peak-up mode (d_number is -1; no disk I/O).

These subclasses live in their own headers and are not documented on this page; they each implement the pure-virtual loadDifferentialFidList and getCurrentIndex methods.

FID I/O surface

addFids() co-averages an incoming Fid list into the current segment, applying an optional time-domain sample shift. setFidsData() replaces the current list unconditionally (used for background-subtraction updates where the new list is not simply additive). getCurrentFidList() returns a mutex-protected copy of the in-progress accumulation. loadFidList() reads segment i from the in-memory cache if available, or from fid/<i>.csv on disk; it is safe to call from any thread. The pure-virtual loadDifferentialFidList() returns the background-subtracted list and is implemented by each concrete subclass.

Cache

Loaded FidList objects are stored in d_cache, keyed by segment index, up to d_maxCacheSize bytes (approximately 200 MB by default). The insertion order of segment indices is tracked in d_cacheKeys; when the cache is full, the oldest entry is evicted before inserting a new one. Cache updates are serialized by an internal pu_baseMutex (separate from pu_mutex in the base class, which guards the current FID list).

Backup interface

The virtual backup() method saves a point-in-time snapshot of the current FID list. The default implementation is a no-op; FidSingleStorage overrides it. numBackups() returns the number of snapshots available.

Processing settings

writeProcessingSettings() serializes a FtWorker::FidProcessingSettings struct to fid/processing.csv using the keys in BC::Key::FidStorage:

Key

Meaning

fidStart

Processing window start (μs)

fidEnd

Processing window end (μs)

fidExp

Exponential apodization time constant (μs)

zpf

Zero-padding multiplier

rdc

DC removal flag

units

Output magnitude units

autoscaleIgnore

LO exclusion half-width (MHz)

winf

Apodization window function

readProcessingSettings() deserializes the same file back into a FidProcessingSettings struct. getLORange() returns the [min, max] probe-frequency range across all stored FID segments, which is used by LO-scan deconvolution in FtWorker.

The FID data format and the broader FTMW acquisition workflow are described in Data Storage.

API Reference

class FidStorageBase : public DataStorageBase

Abstract base class for FID data storage in FTMW acquisitions.

Extends DataStorageBase with the storage model for free-induction decay (FID) waveforms. Holds a fixed number of FID records per segment (d_numRecords) and implements the lifecycle methods: start() and finish() toggle an internal acquiring flag, save() writes the current FID list to disk (skipped for peak-up instances where d_number < 1), and advance() calls save() then delegates to the virtual _advance() hook for subclass-specific segment transitions.

Three concrete subclasses cover the standard acquisition modes: FidSingleStorage (single-segment), FidMultiStorage (multi-segment / LO-scan), and FidPeakUpStorage (peak-up / rolling-average mode).

Subclassed by FidMultiStorage, FidPeakUpStorage, FidSingleStorage

Public Functions

FidStorageBase(int numRecords, int number = -1, QString path = "")

Construct the storage manager.

Parameters:
  • numRecords – Number of FID records in each segment.

  • numberExperiment number; pass -1 for a transient (peak-up) instance.

  • path – Base path of the experiment data directory.

virtual ~FidStorageBase()

Destructor.

virtual void advance() override

Flush the current segment and invoke the subclass transition hook.

Calls save() then _advance() so subclasses can update their segment index or perform other per-segment bookkeeping.

virtual void save() override

Write the current FID list to disk.

Skips silently if d_number < 1 (peak-up / dummy experiment).

virtual void start() override

Mark the start of acquisition.

virtual void finish() override

Mark the end of acquisition.

FidList loadFidList(int i)

Load the FID list for segment i from cache or disk.

Parameters:

i – Segment index.

Returns:

The stored FidList, or an empty list if i is out of range.

virtual FidList loadDifferentialFidList(int i) = 0

Load the background-subtracted FID list for segment i.

Parameters:

i – Segment index.

Returns:

Differential FidList; implementation is subclass-specific.

virtual quint64 currentSegmentShots()

Return the shot count accumulated in the current segment.

Returns:

Shot count of the first FID in the current list, or 0 if empty.

virtual bool addFids(const FidList other, int shift = 0)

Co-average other into the current segment.

Parameters:
  • other – FID list to accumulate.

  • shift – Optional time-domain sample shift applied to other.

Returns:

false if the sizes are incompatible.

virtual bool setFidsData(const FidList other)

Replace the current FID list with other.

Parameters:

other – Replacement FID list.

Returns:

false if other has a different size from the existing list.

virtual FidList getCurrentFidList()

Return a thread-safe copy of the current in-progress FID list.

Returns:

Copy of d_currentFidList under the mutex.

inline virtual void backup()

Save a backup of the current FID list (no-op in the base; overridden by FidSingleStorage).

inline virtual int numBackups()

Return the number of backups available (0 in the base; overridden by FidSingleStorage).

Returns:

Backup count.

virtual int getCurrentIndex() = 0

Return the index of the segment being accumulated.

Returns:

Current segment index; must be implemented by each concrete subclass.

void writeProcessingSettings(const FtWorker::FidProcessingSettings &c)

Serialize a FtWorker::FidProcessingSettings struct to fid/processing.csv.

Parameters:

c – Processing settings to write.

bool readProcessingSettings(FtWorker::FidProcessingSettings &out)

Deserialize a FtWorker::FidProcessingSettings struct from fid/processing.csv.

Parameters:

out – Processing settings populated on success.

Returns:

true if the file was found and parsed successfully.

void writePeakFindSettings(const PeakFindSettings &c)

Serialize a PeakFindSettings struct to fid/peakfind.csv.

Parameters:

c – Peak-finder settings to write.

bool readPeakFindSettings(PeakFindSettings &out)

Deserialize a PeakFindSettings struct from fid/peakfind.csv.

Parameters:

out – Peak-finder settings populated on success.

Returns:

true if the file was found and parsed successfully.

std::pair<double, double> getLORange()

Return the [min, max] probe-frequency range across all stored FID segments.

Returns:

Pair of (minimum, maximum) probe frequency in MHz, or (-1, -1) if no data.

Public Members

const int d_numRecords

Number of FID records per segment (set at construction).

Protected Functions

inline virtual void _advance()

Subclass hook called by advance() after save(); default implementation is a no-op.

void saveFidList(const FidList l, int i)

Write l to disk as segment i and update the cache.

Parameters:
  • l – FID list to persist.

  • i – Segment index.

Protected Attributes

FidList d_currentFidList

In-progress co-averaged FID list for the current segment.

Private Functions

void updateCache(const FidList fl, int i)

Insert or update fl in the cache, evicting the oldest entry when full.

Parameters:
  • fl – FID list to cache.

  • i – Segment index.

Private Members

bool d_acquiring = {false}
int d_currentSegment = {0}
std::size_t d_maxCacheSize = {1 << 28}

Maximum cache size in bytes (~256 MB).

QVector<Fid> d_templateList
std::unique_ptr<QMutex> pu_baseMutex
std::queue<int> d_cacheKeys

Insertion-ordered queue of cached segment indices.

std::map<int, FidList> d_cache

In-memory cache mapping segment index to FID list.