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_numberis-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 |
|---|---|
|
Processing window start (μs) |
|
Processing window end (μs) |
|
Exponential apodization time constant (μs) |
|
Zero-padding multiplier |
|
DC removal flag |
|
Output magnitude units |
|
LO exclusion half-width (MHz) |
|
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
DataStorageBasewith 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()andfinish()toggle an internal acquiring flag,save()writes the current FID list to disk (skipped for peak-up instances whered_number< 1), andadvance()callssave()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), andFidPeakUpStorage(peak-up / rolling-average mode).See also
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.
number – Experiment number; pass
-1for 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:
falseif the sizes are incompatible.
-
virtual bool setFidsData(const FidList other)
Replace the current FID list with other.
- Parameters:
other – Replacement FID list.
- Returns:
falseif 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_currentFidListunder 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::FidProcessingSettingsstruct tofid/processing.csv.- Parameters:
c – Processing settings to write.
-
bool readProcessingSettings(FtWorker::FidProcessingSettings &out)
Deserialize a
FtWorker::FidProcessingSettingsstruct fromfid/processing.csv.- Parameters:
out – Processing settings populated on success.
- Returns:
trueif the file was found and parsed successfully.
-
void writePeakFindSettings(const PeakFindSettings &c)
Serialize a
PeakFindSettingsstruct tofid/peakfind.csv.- Parameters:
c – Peak-finder settings to write.
-
bool readPeakFindSettings(PeakFindSettings &out)
Deserialize a
PeakFindSettingsstruct fromfid/peakfind.csv.- Parameters:
out – Peak-finder settings populated on success.
- Returns:
trueif 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()aftersave(); 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).
-
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.
-
FidStorageBase(int numRecords, int number = -1, QString path = "")