libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
timsframerawdatachunck.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/vendors/tims/timsframerawdatachunck.cpp
3 * \date 18/6/2022
4 * \author Olivier Langella
5 * \brief stores raw binary tims frame
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2022 Olivier Langella
10 *<Olivier.Langella@universite-paris-saclay.fr>.
11 *
12 * This file is part of the PAPPSOms++ library.
13 *
14 * PAPPSOms++ is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * PAPPSOms++ is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
26 *
27 ******************************************************************************/
28
30#include <QDebug>
31
33
34using namespace pappso;
35
39
45
46bool
48 QFile *p_file,
49 std::size_t frameId,
50 const std::vector<pappso::TimsFrameRecord> &frame_record_list)
51{
52
53 m_frameId = frameId;
54 qint64 position = p_file->pos();
55 const pappso::TimsFrameRecord &frame_record = frame_record_list[frameId];
56 if(frameId == 1)
57 {
58 bool seekpos_ok = p_file->seek(frame_record.tims_offset);
59 if(!seekpos_ok)
60 {
61 throw PappsoException(QObject::tr("ERROR reading TIMS frame %1 "
62 "m_timsBinFile.seek(%3) failed")
63 .arg(frameId)
64 .arg(frame_record.tims_offset));
65 }
66 }
67 else
68 {
69
70 if(position == (qint64)frame_record.tims_offset)
71 {
72 // OK
73 }
74 else
75 {
76 // need to move to frame position :
77 if(position > (qint64)frame_record.tims_offset)
78 {
79 // get back
80 p_file->seek(frame_record.tims_offset);
81 position = p_file->pos();
82 }
83 else
84 {
85 const pappso::TimsFrameRecord &previous_frame_record =
86 frame_record_list[frameId - 1];
87 if(position < (qint64)previous_frame_record.tims_offset)
88 {
89
90 throw PappsoException(
91 QObject::tr("ERROR reading TIMS frame %1 "
92 "file position %2 is before previous frame %3")
93 .arg(frameId)
94 .arg(position)
95 .arg(previous_frame_record.tims_offset));
96 }
97 else
98 {
99 // catch up current position
100 qint64 move_size =
101 (qint64)frame_record.tims_offset - position;
102 p_file->read(move_size);
103 position = p_file->pos();
104 }
105 }
106 }
107 }
108
109 if(position != (qint64)frame_record.tims_offset)
110 {
111
112 throw PappsoException(
113 QObject::tr("ERROR reading TIMS frame %1 "
114 "file position %2 is different of frame offset %3")
115 .arg(frameId)
116 .arg(position)
117 .arg(frame_record.tims_offset));
118 }
119 // qDebug();
120 p_file->read((char *)&m_frameLength, 4);
121 // frame_length = qToBigEndian(frame_length);
122
123 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
124 // << " frame_length=" << frame_length;
125
126 // qDebug();
127 p_file->read((char *)&m_frameNumberOfScans, 4);
128 // scan_number = qToBigEndian(scan_number);
129
130 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
131 // << " pos=" << m_timsBinFile.pos();
132
133 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
134 // << " scan_number=" << scan_number;
135 // m_timsBinFile.seek(m_indexArray.at(timsId) + 8);
136
137
138 // qDebug();
139
140 // if (m_memoryBufferSize
141 if(mpa_memoryBuffer == nullptr)
142 {
143 qDebug() << "mpa_memoryBuffer == nullptr";
144 m_memoryBufferSize = (qint64)m_frameLength + 10;
146 }
148 {
149 if(mpa_memoryBuffer != nullptr)
150 {
151 delete[] mpa_memoryBuffer;
152 }
153 m_memoryBufferSize = (qint64)m_frameLength + 10;
155 }
156
157
158 // QByteArray frame_byte_array(mpa_memoryBuffer, m_memoryBufferSize);
159
160 // qDebug();
161 qint64 read_length =
162 p_file->read(mpa_memoryBuffer, (qint64)m_frameLength - 8);
163 // qDebug();
164
165 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
166 // << " +frame_length-1="
167 // << (quint8) * (frame_byte_array.constData() + frame_length - 1);
168 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
169 // << " +frame_length="
170 // << (quint8) * (frame_byte_array.constData() + frame_length);
171 // m_timsBinFile.seek(m_indexArray.at(timsId) + 8);
172
173 if(read_length + 8 != (qint64)m_frameLength)
174 {
175 throw PappsoException(QObject::tr("ERROR reading TIMS frame %1: "
176 "read_length=%2 != %3frame_length")
177 .arg(frameId)
178 .arg(read_length)
179 .arg(m_frameLength));
180 }
181
182 return true;
183}
184
185char *
187{
188 return mpa_memoryBuffer;
189}
190
191quint32
193{
194 return m_frameLength - 8;
195}
196
197quint32
199{
200 return m_frameNumberOfScans;
201}
202
203quint32
205{
206 return m_frameLength;
207}
208
209std::size_t
211{
212 return m_frameId;
213}
bool readTimsFrame(QFile *p_file, std::size_t frameId, const std::vector< pappso::TimsFrameRecord > &frame_record_list)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
stores raw binary tims frame