libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
msrunxicextractordiskbuffer.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/xicextractor/private/msrunxicextractordiskbuffer.cpp
3 * \date 18/05/2018
4 * \author Olivier Langella
5 * \brief proteowizard based XIC extractor featuring disk cache + write buffer
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of the PAPPSOms++ library.
12 *
13 * PAPPSOms++ 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++ 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++. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Contributors:
27 * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
28 *implementation
29 ******************************************************************************/
30
31
33#include <QDebug>
36
37namespace pappso
38{
39
41 const QDir &temporary_dir)
42 : MsRunXicExtractorDisk(msrun_reader, temporary_dir)
43{
44
45 m_sliceBufferMap.clear();
46}
47
54
58
59void
60MsRunXicExtractorDiskBuffer::storeSlices(std::map<unsigned int, MassSpectrum> &slice_vector,
61 std::size_t ipos)
62{
63
65 for(auto &&msrun_slice : slice_vector)
66 {
67 appendSliceInBuffer(msrun_slice.first, msrun_slice.second, ipos);
68 }
69
71 {
73 }
74}
75
76void
78 MassSpectrum &spectrum,
79 std::size_t ipos)
80{
81 // qDebug();
82
83 std::size_t spectrum_size = spectrum.size();
84
85 if(spectrum_size == 0)
86 return;
87 try
88 {
89 std::pair<std::map<unsigned int, QByteArray>::iterator, bool> ret =
90 m_sliceBufferMap.insert(std::pair<unsigned int, QByteArray>(slice_number, QByteArray()));
91
92
93 if(ret.second)
94 { // new buffer
95 ret.first->second.resize(0);
96 QDataStream outstream(&ret.first->second, QIODevice::WriteOnly);
97 outstream << (quint32)ipos;
98 outstream << spectrum;
99 }
100 else
101 {
102 QDataStream outstream(&ret.first->second, QIODevice::WriteOnly | QIODevice::Append);
103 outstream << (quint32)ipos;
104 outstream << spectrum;
105 }
106 }
107 catch(PappsoException &error_pappso)
108 {
109 throw pappso::PappsoException(QObject::tr("appendSliceInBuffer : error ipos=%1 :\n%2")
110 .arg(ipos)
111 .arg(error_pappso.qwhat()));
112 }
113 catch(std::exception &error)
114 {
116 QObject::tr("appendSliceInBuffer slice_number=%1 ipos=%2 error :\n%3")
117 .arg(slice_number)
118 .arg(ipos)
119 .arg(error.what()));
120 }
121 // qDebug();
122}
123
124
125void
127{
128 qDebug();
129
130 try
131 {
132 for(auto &buffer_pair : m_sliceBufferMap)
133 {
134
135 if(buffer_pair.second.size() > 0)
136 {
137 QFile slice_file(
138 QString("%1/%2").arg(mpa_temporaryDirectory->path()).arg(buffer_pair.first));
139 bool new_file = false;
140 if(!slice_file.exists())
141 {
142 new_file = true;
143
144 if(!slice_file.open(QIODevice::WriteOnly))
145 {
147 QObject::tr("unable to open file %1").arg(slice_file.fileName()));
148 }
149 }
150 else
151 {
152 if(!slice_file.open(QIODevice::WriteOnly | QIODevice::Append))
153 {
155 QObject::tr("unable to open file %1").arg(slice_file.fileName()));
156 }
157 }
158
159 QDataStream stream(&slice_file);
160
161 if(new_file)
162 {
163 stream << (quint32)buffer_pair.first;
164 stream << (quint32)m_rtSize;
165 stream.writeRawData(buffer_pair.second.constData(), buffer_pair.second.size());
166 }
167 else
168 {
169 stream.writeRawData(buffer_pair.second.constData(), buffer_pair.second.size());
170 }
171
172
173 slice_file.flush();
174 slice_file.close();
175 }
176 // buffer_pair.second = std::vector<MassSpectrum>();
177 }
178
179 m_bufferSize = 0;
180 m_sliceBufferMap.clear();
181 }
182 catch(PappsoException &error_pappso)
183 {
185 QObject::tr("flushBufferOnDisk error :\n%1").arg(error_pappso.qwhat()));
186 }
187 catch(std::exception &error)
188 {
189 throw pappso::PappsoException(QObject::tr("flushBufferOnDisk error :\n%1").arg(error.what()));
190 }
191 qDebug();
192}
193
194
195void
197{
199
200 m_sliceBufferMap.clear();
201
202 msp_msrun_reader.get()->releaseDevice();
203}
204} // namespace pappso
Class to represent a mass spectrum.
void appendSliceInBuffer(unsigned int slice_number, MassSpectrum &spectrum, std::size_t ipos)
std::map< unsigned int, QByteArray > m_sliceBufferMap
MsRunXicExtractorDiskBuffer(const MsRunXicExtractorDiskBuffer &other)
virtual void storeSlices(std::map< unsigned int, MassSpectrum > &slice_vector, std::size_t ipos) override
store MassSpectrum slices (by daltons) for a given retention time
MsRunXicExtractorDisk(MsRunReaderSPtr &msrun_reader)
virtual const QString & qwhat() const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition msrunreader.h:57