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
34namespace pappso
35{
36namespace cbor
37{
38CborStreamWriter::CborStreamWriter(QByteArray *data) : QCborStreamWriter(data)
39{
40}
41
42CborStreamWriter::CborStreamWriter(QIODevice *device) : QCborStreamWriter(device)
43{
44}
45
46
50
51
52const QString &
54{
55 return m_uuid;
56}
57
58void
59CborStreamWriter::writeInformations(const QString &software_name,
60 const QString &software_version,
61 const QString &type,
62 const QString &operation)
63{
64 append("informations");
65 startMap();
66 append(QLatin1String("software"));
67 append(software_name);
68 append(QLatin1String("version"));
69 append(software_version);
70 append(QLatin1String("type"));
71 append(type);
72 append(QLatin1String("operation"));
73 append(operation);
74 append(QLatin1String("cpu_used"));
75 append(QThreadPool::globalInstance()->maxThreadCount());
76 append(QLatin1String("pappsomspp_version"));
78 append(QLatin1String("sysinfo_machine_hostname"));
79 append(QSysInfo::machineHostName());
80 append(QLatin1String("sysinfo_product_name"));
81 append(QSysInfo::prettyProductName());
82 append(QLatin1String("timestamp"));
83 append(QDateTime::currentDateTime().toString(Qt::ISODate));
84
85 append(QLatin1String("uuid"));
86 m_uuid = QUuid::createUuid().toString();
87 append(m_uuid);
88 endMap();
89}
90
91
92void
93CborStreamWriter::writeArray(const std::vector<std::size_t> &int_list)
94{
95 startArray(int_list.size());
96 for(auto num : int_list)
97 {
98 append((quint64)num);
99 }
100 endArray();
101}
102
103void
104CborStreamWriter::writeArray(const std::vector<double> &double_list)
105{
106 startArray(double_list.size());
107 for(auto num : double_list)
108 {
109 append(num);
110 }
111 endArray();
112}
113
114void
115CborStreamWriter::writeArray(const std::vector<int> &positions)
116{
117
118 startArray(positions.size());
119 for(auto num : positions)
120 {
121 append(num);
122 }
123 endArray();
124}
125
126void
127CborStreamWriter::writeArray(const std::vector<std::uint8_t> &small_uint_list)
128{
129
130 startArray(small_uint_list.size());
131 for(int num : small_uint_list)
132 {
133 append(num);
134 }
135 endArray();
136}
137
138void
139CborStreamWriter::writeArray(const std::vector<qint64> &int_list)
140{
141
142 startArray(int_list.size());
143 for(auto num : int_list)
144 {
145 append(num);
146 }
147 endArray();
148}
149
150void
151CborStreamWriter::writeArray(const QStringList &str_list)
152{
153 startArray(str_list.size());
154 for(auto str_item : str_list)
155 {
156 append(str_item);
157 }
158 endArray();
159}
160
161void
162CborStreamWriter::writeArray(const std::vector<QString> &str_list)
163{
164 startArray(str_list.size());
165 for(auto str_item : str_list)
166 {
167 append(str_item);
168 }
169 endArray();
170}
171
172void
173CborStreamWriter::writeCborMap(const QCborMap &cbor_map)
174{
175 QCborValue(cbor_map).toCbor(*this);
176}
177
178void
179CborStreamWriter::writeCborArray(const QCborArray &cbor_array)
180{
181 QCborValue(cbor_array).toCbor(*this);
182}
183
184void
186 const QString &x_label,
187 const QString &y_label)
188{
189 startMap(2);
190 append(x_label);
191 writeArray(trace.xValues());
192 append(y_label);
193 writeArray(trace.yValues());
194 endMap();
195}
196
197
198void
200{
201 startMap();
202 xic_coord.writeCborStream(*this);
203
204 if(xic_coord.xicSptr.get() != nullptr)
205 {
206 append("xic");
207 writeTrace(*xic_coord.xicSptr.get(), "rt", "intensities");
208 }
209 endMap();
210}
211
212
213void
214CborStreamWriter::writeXicCoordList(const std::vector<pappso::XicCoordSPtr> &xic_coord_list)
215{
216
217 startArray(xic_coord_list.size());
218 for(auto &xic_coord_sp : xic_coord_list)
219 {
220 writeXicCoord(*xic_coord_sp.get());
221 }
222 endArray();
223}
224
225} // namespace cbor
226} // 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:650
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 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