libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
spectrumtube.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/core/processing/cbor/mzcbor/copyreplace/spectrumtube.cpp
3 * \date 3/10/2026
4 * \author Olivier Langella
5 * \brief buffer to store a whole spectrum list
6 * */
7
8/*******************************************************************************
9 * Copyright (c) 2026 Olivier Langella <Olivier.Langella@cnrs.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
29#include "spectrumtube.h"
30#include <QtCore>
31#include <qcborarray.h>
32#include <qcbormap.h>
33#include <qcborvalue.h>
34#include <qdebug.h>
35#include <qlogging.h>
36
37namespace pappso
38{
39namespace cbor
40{
41namespace mzcbor
42{
44{
45 mpa_buffer = new QTemporaryFile();
46 mpa_buffer->open();
47 qDebug() << mpa_buffer->fileName();
49}
50
52{
53
54 if(mpa_buffer != nullptr)
55 {
56 delete mpa_buffer;
57 }
58 if(mpa_bufferWriter != nullptr)
59 {
60 delete mpa_bufferWriter;
61 }
62}
63std::size_t
65{
66 return m_size;
67}
68const QString
70{
71 qDebug() << m_size;
72 std::size_t index = m_size;
73
74 spectrum.setIndex(index);
75
76 // replace scan number in native id
77 const QString native_id(spectrum.getId());
78 QString new_native_id;
79 // controllerType=0 controllerNumber=1 scan=2995
80 //
81 QStringList native_id_list = native_id.split(" scan=");
82 if(native_id_list.size() < 2)
83 {
84 new_native_id = QString("%1 index=%2").arg(native_id).arg(index);
85 }
86 else
87 {
88 new_native_id = QString("%1 scan=%2").arg(native_id_list[0]).arg(index + 1);
89 }
90
91 // spectrum.addUserParam();
92
93 spectrum.setId(new_native_id);
94
95 qDebug();
96
97 writeQcborSpectrumInBuffer(spectrum, native_id);
98 // qDebug() << mpa_buffer->data().length();
99 m_size++;
100 return native_id;
101}
102
103void
105 const QString &old_native_id)
106{
107
108 // "id": "controllerType=0 controllerNumber=1 scan=3001",
109 // "index": 3000,
110 // "defaultArrayLength": 235,
111 // "cvParam": [],
112 // "userParam": [
113 // {
114 // "name": "[PAPPSO]original spectrum native id",
115 // "type": "xsd:string",
116 // "value": old_native_id
117 // }
118 // ],
119 QCborMap new_user_param;
120 new_user_param.insert(QString("name"), "[PAPPSO]original spectrum native id");
121 new_user_param.insert(QString("type"), "xsd:string");
122 new_user_param.insert(QString("value"), old_native_id);
123 //"scanList": {},
124 //"precursorList": {},
125 //"binaryDataArray": []
126 mpa_bufferWriter->startMap();
127 bool write_user_param = false;
128 for(auto it_cbor = spectrum.begin(); it_cbor != spectrum.end(); it_cbor++)
129 {
130 QString current_key = it_cbor.key().toString();
131
132 if(write_user_param)
133 {
134 if(current_key == "userParam")
135 {
136 QCborArray user_param_array = it_cbor.value().toArray();
137 user_param_array.append(new_user_param);
138 mpa_bufferWriter->writeCborValue(it_cbor.key());
139 mpa_bufferWriter->writeCborValue(user_param_array);
140 continue;
141 }
142 else
143 {
144 mpa_bufferWriter->append("userParam");
145 mpa_bufferWriter->startArray();
146 mpa_bufferWriter->writeCborMap(new_user_param);
147 mpa_bufferWriter->endArray();
148 }
149 write_user_param = false;
150 }
151
152 if(current_key == "cvParam")
153 {
154 // write cvParam
155 mpa_bufferWriter->writeCborValue(it_cbor.key());
156 mpa_bufferWriter->writeCborValue(it_cbor.value());
157 write_user_param = true;
158 }
159 else
160 {
161 mpa_bufferWriter->writeCborValue(it_cbor.key());
162 mpa_bufferWriter->writeCborValue(it_cbor.value());
163 }
164 }
165 mpa_bufferWriter->endMap();
166 // mpa_bufferWriter->writeCborMap(spectrum);
167}
168
169void
171{
172 mpa_buffer->close();
173 mpa_buffer->open();
174 while(!mpa_buffer->atEnd())
175 {
176 cbor_writer_p->device()->write(mpa_buffer->read(1000));
177 }
178}
179} // namespace mzcbor
180} // namespace cbor
181} // namespace pappso
overrides QCborStreamWriter base class to provide convenient functions
void writeQcborSpectrumInBuffer(const QcborSpectrum &spectrum, const QString &old_native_id)
const QString push_back(QcborSpectrum &spectrum)
pappso::cbor::CborStreamWriter * mpa_bufferWriter
void flush(pappso::cbor::CborStreamWriter *cbor_writer_p)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
buffer to store a whole spectrum list