29 #include "../../../pappsomspp/pappsoexception.h"
30 #include <QDataStream>
36 : m_timsBinFile(timsBinFile.absoluteFilePath())
39 if(timsCompressionType != 2)
42 QObject::tr(
"compression type %1 not handled by this library")
43 .arg(timsCompressionType));
48 QObject::tr(
"No TIMS binary file name specified"));
51 if(!file.open(QIODevice::ReadOnly))
54 QObject::tr(
"ERROR opening TIMS binary file %1 for read")
55 .arg(timsBinFile.absoluteFilePath()));
61 : m_timsBinFile(other.m_timsBinFile)
74 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__;
76 QDataStream bin_in(&file);
77 bin_in.setByteOrder(QDataStream::ByteOrder::LittleEndian);
85 while(!bin_in.atEnd())
87 while((!bin_in.atEnd()) && (position % 4 != 0))
101 quint32 frame_len(0);
102 while((!bin_in.atEnd()) && (frame_len == 0))
124 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__
125 <<
" number_in(nb scans)=" << number_in
126 <<
" position=" << position;
139 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__;
144 std::size_t timsOffset)
const
146 qDebug() <<
"timsId:" << timsId <<
"timsOffset:" << timsOffset;
150 if(!file.open(QIODevice::ReadOnly))
153 QObject::tr(
"ERROR opening TIMS binary file %1 for read")
157 bool seekpos_ok = file.seek(timsOffset);
161 QObject::tr(
"ERROR reading TIMS frame %1 TIMS binary file %2: "
162 "m_timsBinFile.seek(%3) failed")
168 quint32 frame_length;
169 file.read((
char *)&frame_length, 4);
176 file.read((
char *)&scan_number, 4);
190 QByteArray frame_byte_array = file.read((qint64)frame_length + 2);
202 if(frame_byte_array.size() - 2 != (qint64)frame_length)
205 QObject::tr(
"ERROR reading TIMS frame %1 TIMS binary file %2: "
206 "frame_byte_array.size()%3 != %4frame_length")
209 .arg(frame_byte_array.size())
215 auto decompressed_size2 =
216 ZSTD_getFrameContentSize(frame_byte_array.constData(), frame_length);
218 if(decompressed_size2 == ZSTD_CONTENTSIZE_UNKNOWN)
221 QObject::tr(
"ERROR reading TIMS frame %1 TIMS binary file %2: "
222 " decompressed_size2 == ZSTD_CONTENTSIZE_UNKNOWN, "
229 if(decompressed_size2 == ZSTD_CONTENTSIZE_ERROR)
233 "ERROR reading TIMS frame %1 TIMS binary file %2: "
234 " decompressed_size2 == ZSTD_CONTENTSIZE_ERROR, frame_length=%3")
239 qDebug() << __FILE__ <<
" " << __FUNCTION__ <<
" " << __LINE__
240 <<
" decompressed_size2=" << decompressed_size2;
242 char *uncompress =
new char[decompressed_size2 + 10];
243 std::size_t decompressed_size =
244 ZSTD_decompress(uncompress,
245 decompressed_size2 + 10,
246 frame_byte_array.constData(),
250 if(decompressed_size != decompressed_size2)
253 QObject::tr(
"ERROR reading TIMS frame %1 TIMS binary file %2: "
254 "decompressed_size != decompressed_size2")
257 .arg(decompressed_size)
258 .arg(decompressed_size2));
263 frame_sptr = std::make_shared<TimsFrame>(
264 timsId, scan_number, uncompress, decompressed_size);
270 frame_sptr = std::make_shared<TimsFrame>(timsId, scan_number,
nullptr, 0);