OpenMS
Loading...
Searching...
No Matches
CachedmzML Class Reference

Random-access reader/writer for the OpenMS on-disk cache format. More...

#include <OpenMS/FORMAT/CachedMzML.h>

Inheritance diagram for CachedmzML:
[legend]
Collaboration diagram for CachedmzML:
[legend]

Constructors and Destructor

MSExperiment meta_ms_experiment_
 Meta data.
 
std::ifstream ifs_
 Internal filestream.
 
std::string filename_
 Name of the mzML file.
 
std::string filename_cached_
 Name of the cached mzML file.
 
std::vector< std::streampos > spectra_index_
 Indices.
 
std::vector< std::streampos > chrom_index_
 
 CachedmzML ()
 Default constructor.
 
 CachedmzML (const std::string &filename)
 Construct and load metadata + side-car index from filename in one step.
 
 CachedmzML (const CachedmzML &rhs)
 Copy constructor.
 
 ~CachedmzML ()
 Destructor.
 
MSSpectrum getSpectrum (Size id)
 Read one spectrum from the side-car file.
 
MSChromatogram getChromatogram (Size id)
 Read one chromatogram from the side-car file.
 
size_t getNrSpectra () const
 Number of spectra in the loaded experiment.
 
size_t getNrChromatograms () const
 Number of chromatograms in the loaded experiment.
 
const MSExperimentgetMetaData () const
 Experiment-level metadata loaded from the .mzML file.
 
static void store (const std::string &filename, const PeakMap &map)
 Write map to disk as a cached .mzML pair.
 
static void load (const std::string &filename, CachedmzML &map)
 Load a cached .mzML pair into map.
 
void load_ (const std::string &filename)
 

Detailed Description

Random-access reader/writer for the OpenMS on-disk cache format.

Spectra and chromatograms are split across two files: an .mzML file holding the experiment-level metadata and a side-car .mzML.cached binary file holding the per-spectrum / per-chromatogram payload. After load (or constructing with a filename) the side-car's stream offsets are kept in an in-memory index, so single spectra or chromatograms can be fetched in any order from disk without scanning the full file.

Constructor & Destructor Documentation

◆ CachedmzML() [1/3]

Default constructor.

Produces an empty instance with no associated file.

◆ CachedmzML() [2/3]

CachedmzML ( const std::string &  filename)

Construct and load metadata + side-car index from filename in one step.

Equivalent to default-constructing and then calling load. See load for the exact behaviour, file layout and exceptions.

Parameters
[in]filenamePath of the .mzML metadata file; the side-car is expected next to it as filename + ".cached".

◆ CachedmzML() [3/3]

CachedmzML ( const CachedmzML rhs)

Copy constructor.

Each instance keeps its own file handle on the .mzML.cached side-car, so the copy opens a fresh stream on the same path – the original's stream is not shared.

Parameters
[in]rhsInstance to copy.

◆ ~CachedmzML()

~CachedmzML ( )

Destructor.

Closes the open file stream on the .mzML.cached side-car.

Member Function Documentation

◆ getChromatogram()

MSChromatogram getChromatogram ( Size  id)

Read one chromatogram from the side-car file.

Parameters
[in]idIndex of the chromatogram to read; must be smaller than getNrChromatograms. Out-of-range access is a programming error (checked in debug builds).
Returns
Decoded chromatogram.
Exceptions
Exception::ParseErrorwhen seekg on the side-car stream fails.

◆ getMetaData()

const MSExperiment & getMetaData ( ) const
inline

Experiment-level metadata loaded from the .mzML file.

The returned experiment contains instrument and acquisition settings as well as the per-spectrum / per-chromatogram headers. Empty until load has been called.

Returns
Const reference to the loaded metadata experiment.

◆ getNrChromatograms()

size_t getNrChromatograms ( ) const

Number of chromatograms in the loaded experiment.

Returns
Chromatogram count.

◆ getNrSpectra()

size_t getNrSpectra ( ) const

Number of spectra in the loaded experiment.

Returns
Spectrum count.

◆ getSpectrum()

MSSpectrum getSpectrum ( Size  id)

Read one spectrum from the side-car file.

Seeks the cached stream to the indexed offset for id, parses the binary payload and returns the resulting MSSpectrum. The metadata for the spectrum (instrument settings, native id, ...) is taken from the in-memory experiment loaded at load time.

Parameters
[in]idIndex of the spectrum to read; must be smaller than getNrSpectra. Out-of-range access is a programming error (checked in debug builds).
Returns
Decoded spectrum.
Exceptions
Exception::ParseErrorwhen seekg on the side-car stream fails (e.g. a 32-bit-system overflow on a > 2 GB cache file).

◆ load()

static void load ( const std::string &  filename,
CachedmzML map 
)
static

Load a cached .mzML pair into map.

Reads the metadata from filename and builds the in-memory index for the side-car at filename + ".cached"; subsequent calls to getSpectrum / getChromatogram on map fetch the payload from the side-car on demand.

Parameters
[in]filenamePath of the .mzML metadata file (the side-car is expected next to it as filename + ".cached").
[out]mapDestination instance; previous contents are replaced.
Exceptions
Exception::FileNotFoundwhen either file cannot be opened.
Exception::ParseErrorwhen parsing the metadata or building the side-car index fails.

◆ load_()

void load_ ( const std::string &  filename)
protected

◆ store()

static void store ( const std::string &  filename,
const PeakMap map 
)
static

Write map to disk as a cached .mzML pair.

Produces two files: a binary side-car at filename + ".cached" holding the spectrum / chromatogram payload, and an .mzML file at filename holding the metadata.

Parameters
[in]filenamePath of the metadata file (should end in .mzML); the side-car is written next to it as filename + ".cached".
[in]mapExperiment to write.
Exceptions
Exception::UnableToCreateFilewhen either output file cannot be created.

Member Data Documentation

◆ chrom_index_

std::vector<std::streampos> chrom_index_
protected

◆ filename_

std::string filename_
protected

Name of the mzML file.

◆ filename_cached_

std::string filename_cached_
protected

Name of the cached mzML file.

◆ ifs_

std::ifstream ifs_
protected

Internal filestream.

◆ meta_ms_experiment_

MSExperiment meta_ms_experiment_
protected

Meta data.

◆ spectra_index_

std::vector<std::streampos> spectra_index_
protected

Indices.