libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
cborstreamwriter.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/cborstreamwriter.cpp
3 * \date 05/07/2025
4 * \author Olivier Langella
5 * \brief PAPPSO CBOR stream writer
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10 *
11 * This file is part of PAPPSOms-tools.
12 *
13 * PAPPSOms-tools is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms-tools is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
28#include "cborstreamwriter.h"
29#include <QDateTime>
30#include <QThreadPool>
32#include <QCborValue>
33#include <qcborvalue.h>
34
35namespace pappso
36{
37namespace cbor
38{
39CborStreamWriter::CborStreamWriter(QByteArray *data) : QCborStreamWriter(data)
40{
41}
42
43CborStreamWriter::CborStreamWriter(QIODevice *device) : QCborStreamWriter(device)
44{
45}
46
47
51
52
53const QString &
55{
56 return m_uuid;
57}
58
59void
60CborStreamWriter::writeInformations(const QString &software_name,
61 const QString &software_version,
62 const QString &type,
63 const QString &operation)
64{
65 append("informations");
66 startMap();
67 append(QLatin1String("software"));
68 append(software_name);
69 append(QLatin1String("version"));
70 append(software_version);
71 append(QLatin1String("type"));
72 append(type);
73 append(QLatin1String("operation"));
74 append(operation);
75 append(QLatin1String("cpu_used"));
76 append(QThreadPool::globalInstance()->maxThreadCount());
77 append(QLatin1String("pappsomspp_version"));
79 append(QLatin1String("sysinfo_machine_hostname"));
80 append(QSysInfo::machineHostName());
81 append(QLatin1String("sysinfo_product_name"));
82 append(QSysInfo::prettyProductName());
83 append(QLatin1String("timestamp"));
84 append(QDateTime::currentDateTime().toString(Qt::ISODate));
85
86 append(QLatin1String("uuid"));
87 m_uuid = QUuid::createUuid().toString();
88 append(m_uuid);
89 endMap();
90}
91
92
93void
94CborStreamWriter::writeArray(const std::vector<std::size_t> &int_list)
95{
96 startArray(int_list.size());
97 for(auto num : int_list)
98 {
99 append((quint64)num);
100 }
101 endArray();
102}
103
104void
105CborStreamWriter::writeArray(const std::vector<double> &double_list)
106{
107 startArray(double_list.size());
108 for(auto num : double_list)
109 {
110 append(num);
111 }
112 endArray();
113}
114
115void
116CborStreamWriter::writeArray(const std::vector<int> &positions)
117{
118
119 startArray(positions.size());
120 for(auto num : positions)
121 {
122 append(num);
123 }
124 endArray();
125}
126
127void
128CborStreamWriter::writeArray(const std::vector<std::uint8_t> &small_uint_list)
129{
130
131 startArray(small_uint_list.size());
132 for(int num : small_uint_list)
133 {
134 append(num);
135 }
136 endArray();
137}
138
139void
140CborStreamWriter::writeArray(const std::vector<qint64> &int_list)
141{
142
143 startArray(int_list.size());
144 for(auto num : int_list)
145 {
146 append(num);
147 }
148 endArray();
149}
150
151void
152CborStreamWriter::writeArray(const QStringList &str_list)
153{
154 startArray(str_list.size());
155 for(auto str_item : str_list)
156 {
157 append(str_item);
158 }
159 endArray();
160}
161
162void
163CborStreamWriter::writeArray(const std::vector<QString> &str_list)
164{
165 startArray(str_list.size());
166 for(auto str_item : str_list)
167 {
168 append(str_item);
169 }
170 endArray();
171}
172void
173CborStreamWriter::writeCborValue(const QCborValue &cbor_value)
174{
175 cbor_value.toCbor(*this);
176}
177
178void
179CborStreamWriter::writeCborMap(const QCborMap &cbor_map)
180{
181 QCborValue(cbor_map).toCbor(*this);
182}
183
184void
185CborStreamWriter::writeCborArray(const QCborArray &cbor_array)
186{
187 QCborValue(cbor_array).toCbor(*this);
188}
189
190void
192 const QString &x_label,
193 const QString &y_label)
194{
195 startMap(2);
196 append(x_label);
197 writeArray(trace.xValues());
198 append(y_label);
199 writeArray(trace.yValues());
200 endMap();
201}
202
203
204void
206{
207 startMap();
208 xic_coord.writeCborStream(*this);
209
210 if(xic_coord.xicSptr.get() != nullptr)
211 {
212 append("xic");
213 writeTrace(*xic_coord.xicSptr.get(), "rt", "intensities");
214 }
215 endMap();
216}
217
218
219void
220CborStreamWriter::writeXicCoordList(const std::vector<pappso::XicCoordSPtr> &xic_coord_list)
221{
222
223 startArray(xic_coord_list.size());
224 for(auto &xic_coord_sp : xic_coord_list)
225 {
226 writeXicCoord(*xic_coord_sp.get());
227 }
228 endArray();
229}
230
231} // namespace cbor
232} // namespace pappso
A simple container of DataPoint instances.
Definition trace.h:152
std::vector< pappso_double > xValues() const
Definition trace.cpp:697
std::vector< pappso_double > yValues() const
Definition trace.cpp:711
static QString getVersion()
Definition utils.cpp:669
void writeInformations(const QString &software_name, const QString &software_version, const QString &type, const QString &operation)
automatically produces an informations CBOR map the "informations" map contains default parameters : ...
void writeXicCoord(const pappso::XicCoord &xic_coord)
serialize a PAPPSO xic coordinate object to CBOR
void writeCborValue(const QCborValue &cbor_value)
void writeArray(const std::vector< std::size_t > &int_list)
void writeXicCoordList(const std::vector< pappso::XicCoordSPtr > &xic_coord_list)
serialize a PAPPSO xic coordinate object list to CBOR
void writeTrace(const pappso::Trace &trace, const QString &x_label="x", const QString &y_label="y")
serialize a PAPPSO trace object to CBOR
const QString & getUuid() const
get UUID intialized when using writeInformations
void writeCborMap(const QCborMap &cbor_map)
void writeCborArray(const QCborArray &cbor_array)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
coordinates of the XIC to extract and the resulting XIC after extraction
Definition xiccoord.h:68
XicSPtr xicSptr
extracted xic
Definition xiccoord.h:135
virtual void writeCborStream(QCborStreamWriter &cbor_writer) const
writes xic coordinates in a cbor stream
Definition xiccoord.cpp:127