AbstractFormatReader
Namespace: BIDSLIB · Library: BIDS Library
#include <bids/bids_abstract_format_reader.h>
class BIDSLIB::AbstractFormatReader
The AbstractFormatReader class provides a common interface for reading raw neurophysiology data from various file formats (EDF, BrainVision, etc.) used in BIDS datasets.
Subclasses implement format-specific parsing and expose the data uniformly as FIFF structures.
std::unique_ptr<AbstractFormatReader> edf = BidsRawData::createReader(".edf"); // or construct EDFReader directly
const bool edfOpen = edf->open(BIDSPath(root, "02", "01", "rest", "eeg", "eeg", ".edf").filePath());
const FIFFLIB::FiffInfo edfInfo = edf->getInfo();
const MatrixXf edfHead = edf->readRawSegment(0, 201);
Inheritance
Public Methods
~AbstractFormatReader()
Virtual destructor.
open(sFilePath)
Open and parse the file header.
Must be called before reading data.
Parameters:
- sFilePath : const QString & Absolute path to the primary data file.
Returns:
- bool — True if the file was opened and parsed successfully.
getInfo()
Return measurement metadata as FiffInfo.
Returns:
- FiffInfo — FiffInfo populated from the native format header.
readRawSegment(iStartSampleIdx, iEndSampleIdx)
Read a segment of raw data.
Parameters:
-
iStartSampleIdx : int First sample index (0-based, inclusive).
-
iEndSampleIdx : int Last sample index (0-based, exclusive).
Returns:
- Eigen::MatrixXf — Matrix of shape (n_channels x n_samples) with calibrated physical values.
getSampleCount()
Return total number of samples across the recording.
Returns:
- long — Number of samples per channel in the whole recording.
getFrequency()
Return the sampling frequency in Hz.
Returns:
- float — Sampling frequency in Hz.
getChannelCount()
Return the number of measurement channels.
Returns:
- int — Number of measurement channels (rows returned by readRawSegment).
toFiffRawData()
Convert the entire dataset to a FiffRawData structure.
Returns:
- FiffRawData — FiffRawData populated with info, calibrations, and sample bounds.
formatName()
Return a descriptive name for the format (e.g.
"EDF", "BrainVision").
Returns:
- QString — Human-readable format name.
supportsExtension(sExtension)
Check whether this reader can handle the given file extension.
Parameters:
- sExtension : const QString & File extension including dot (e.g. ".edf", ".vhdr").
Returns:
- bool — True if this reader supports the extension.
Example
- Full source:
src/examples/ex_bids/main.cpp - Build target:
ex_bids(runs under CTest) - Data: mne-cpp-test-data
Used in examples
ex_bids
BIDS library: paths, sidecar TSVs, BrainVision/EDF readers and a raw-data round trip.
std::unique_ptr<AbstractFormatReader> edf = BidsRawData::createReader(".edf"); // or construct EDFReader directly
const bool edfOpen = edf->open(BIDSPath(root, "02", "01", "rest", "eeg", "eeg", ".edf").filePath());
const FIFFLIB::FiffInfo edfInfo = edf->getInfo();
const MatrixXf edfHead = edf->readRawSegment(0, 201);
// mne.io.read_raw_edf: 25 channels at 128 Hz, 1228 samples, first channel "EEG Fp1"; data[3, 200] = 0.1757724
ok &= expect(edfOpen && dynamic_cast<EDFReader*>(edf.get()) != nullptr && edf->formatName() == "EDF" && edfInfo.nchan == 25 && edfInfo.ch_names.first() == "EEG Fp1" && edf->getSampleCount() == 1228 && near(edfHead(0, 0), 0.17594066, 1e-5) && near(edfHead(3, 200), 0.17577240650034331, 1e-5),
QString("EDF: %1 channels, %2 samples, (3,200) = %3 match mne").arg(edfInfo.nchan).arg(edf->getSampleCount()).arg(edfHead(3, 200), 0, 'g', 8));
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>