| <large>libXpertMassCore and libXpertMassGui Developer Documentation</large>

- libXpertMassCore
- MassDataCborMassSpectrumHandler

# MsXpS::libXpertMassCore::MassDataCborMassSpectrumHandler Class

class MsXpS::libXpertMassCore::MassDataCborMassSpectrumHandler

The MassDataCborMassSpectrumHandler class provides features to handle mass spectrum data using the CBOR (Concise Binary Object Representation) container streaming classes. More...

Header: | `#include <MsXpS/libXpertMassCore/MassDataCborMassSpectrumHandler.hpp>`
Inherits: | MsXpS::libXpertMassCore::MassDataCborBaseHandler

- List of all members, including inherited members
- MassDataCborMassSpectrumHandler is part of libXpertMassCore Utilities.

## Public Functions

| MassDataCborMassSpectrumHandler(QObject *parent_p)
| MassDataCborMassSpectrumHandler(QObject *parent_p, const pappso::Trace &trace)
virtual | ~MassDataCborMassSpectrumHandler()
void | clearTrace()
pappso::Trace | getTrace() const
QString | getTraceColor() const
QString | getXLabel() const
QString | getYLabel() const
void | setTrace(const pappso::Trace &trace)
void | setTraceColor(const QString &color_name)
void | setXLabel(const QString &label)
void | setYLabel(const QString &label)

## Reimplemented Public Functions

virtual bool | readByteArray(const QByteArray &byte_array) override
virtual bool | readFile(const QString &input_file_name = QString()) override
virtual void | writeByteArray(QByteArray &byte_array) override
virtual bool | writeFile(const QString &output_file_name = QString()) override

## Reimplemented Protected Functions

virtual bool | decodeStream(MsXpS::libXpertMassCore::QCborStreamReaderSPtr &reader_sp) override

## Detailed Description

The data transported using CBOR is first qualified using the Enums::MassDataType::MASS_SPECTRUM value. The data are packed following that mass data type specification.

The format for this kind of CBOR mass spectrum data is the following:

The whole file is actually a map that contains the key/value pairs below.

All the text string values below are described in this way in the CBOR Qt implementation specification: "Major type 3: a text string, specifically a string of Unicode characters that is encoded as UTF-8 (that is, not a QByteArray, but a QString)".

The containers, map, strings and byte arrays dot not need the reader's next() call.

The simple value, like integers, do need the reader's next() call.

In this format, the whole data set in the CBOR container is a map with the following key/value pairs:

start_map

- "DATA_TYPE" / value (quint64) : this quint64 (QCborStreamReader::UnsignedInteger) value is only got as the very first data bit in the file and represents the Enums::MassDataType::MASS_SPECTRUM value describing the kind of data encoded in the CBOR container.
- "TITLE" / value (text string): the title of the mass spectrum that should be used to identify it later in a mass data visualization/exploration program like MineXpert.
- "TRACE_COLOR" / value (QByteArray)
- "X_LABEL" / value (text string): the label of the x abscissae axis.
- "X_DATA" / value (base64 QByteArray): the array of Base64-encoded m/z values (x axis)
- "Y_LABEL" / value (text string): the label of the y ordinates axis.
- "Y_DATA" / value (base64 QByteArray): the array of Base64-encoded intensity values (y axis)

end_map

All the data above fully qualify a mass spectrum in order to display it as a trace (that is, a graph) in a mass spectrometric data visualization/exploration program like MineXpert, from http://www.msxpertsuite.org/.

## Member Function Documentation

### MassDataCborMassSpectrumHandler::MassDataCborMassSpectrumHandler(QObject *parent_p)

Constructs a MassDataCborMassSpectrumHandler instance setting parent to parent_p.

### MassDataCborMassSpectrumHandler::MassDataCborMassSpectrumHandler(QObject *parent_p, const pappso::Trace &trace)

Constructs a MassDataCborMassSpectrumHandler instance initializing the member trace to trace and setting parent to parent_p.

Note: The trace is considered the mass spectrum data to be streamed to a file as a CBOR container.

### `[virtual noexcept]` MassDataCborMassSpectrumHandler::~MassDataCborMassSpectrumHandler()

Destructs the MassDataCborMassSpectrumHandler instance.

### void MassDataCborMassSpectrumHandler::clearTrace()

Clears the mass spectrum data.

### `[override virtual protected]` bool MassDataCborMassSpectrumHandler::decodeStream(MsXpS::libXpertMassCore::QCborStreamReaderSPtr &reader_sp)

Reimplements: MassDataCborBaseHandler::decodeStream(MsXpS::libXpertMassCore::QCborStreamReaderSPtr &reader_sp).

Decodes the data stream from reader_sp.

The CBOR container consists in a succession of map key/value pairs. The very first key/value pair is "DATA_TYPE"/Enums::MassDataType::MASS_SPECTRUM. The following key/value pairs contain data like the title of the mass spectrum, the color for tracing the mass spectrum, the x (m/z) data and the y (intensity) data. See the class documentation for details.

Data decoded from the reader_sp stream are set to member data for later consumption.

Returns true if the decoding was successful, false otherwise.

See also writeFile().

### pappso::Trace MassDataCborMassSpectrumHandler::getTrace() const

Returns the mass spectrum data.

### QString MassDataCborMassSpectrumHandler::getTraceColor() const

Returns the color with which the mass spectrum data must be displayed.

### QString MassDataCborMassSpectrumHandler::getXLabel() const

Returns the abscissae label for the mass spectrum data.

### QString MassDataCborMassSpectrumHandler::getYLabel() const

Returns the ordinates label for the mass spectrum data.

### `[override virtual]` bool MassDataCborMassSpectrumHandler::readByteArray(const QByteArray &byte_array)

Reimplements: MassDataCborBaseHandler::readByteArray(const QByteArray &byte_array).

Reads data from the byte array byte_array.

The data in byte_array are packed in a CBOR container. These data have typically travelled over the network and the receiving end needs to unpack the data in that byte_array. This is what this function does.

The data unpacked from byte_array are stored in this object member variables for later consumption by the user of this function.

A CBOR stream reader is allocated and set to decode byte_array. The actual decoding occurs in decodeStream().

Returns true if the operations was successful, false otherwise.

### `[override virtual]` bool MassDataCborMassSpectrumHandler::readFile(const QString &input_file_name = QString())

Reimplements: MassDataCborBaseHandler::readFile(const QString &input_file_name).

Reads the data in file input_file_name by decoding the data stream read from it. This function first decodes the data in the CBOR container stored in the file. Then it decodes the Base64-encoded x and y axis data into the member pappso::Trace object.

Returns true if the operation was successful, false, otherwise.

See also decodeStream() and readByteArray().

### void MassDataCborMassSpectrumHandler::setTrace(const pappso::Trace &trace)

Sets the mass spectrum data to trace.

### void MassDataCborMassSpectrumHandler::setTraceColor(const QString &color_name)

Sets the color with which the mass spectrum data must be displayed. The color is encoded as its name color_name.

### void MassDataCborMassSpectrumHandler::setXLabel(const QString &label)

Sets the abscissae label for the mass spectrum data.

### void MassDataCborMassSpectrumHandler::setYLabel(const QString &label)

Sets the ordinates label for the mass spectrum data.

### `[override virtual]` void MassDataCborMassSpectrumHandler::writeByteArray(QByteArray &byte_array)

Reimplements: MassDataCborBaseHandler::writeByteArray(QByteArray &byte_array).

Writes member data to byte array byte_array.

Note: The member data are packed in a CBOR container and streamed to the byte array as a set of key/value pairs that form the CBOR map being streamed to the byte array.

### `[override virtual]` bool MassDataCborMassSpectrumHandler::writeFile(const QString &output_file_name = QString())

Reimplements: MassDataCborBaseHandler::writeFile(const QString &output_file_name).

Writes member data to file output_file_name.

Note: The member data are packed in a CBOR container and streamed to the file as a set of key/value pairs that form the CBOR map being streamed to the file.

Returns true if the operation was successful, false, otherwise.