libpappsomspp
Library for mass spectrometry
pappso::TimsBinDec Class Reference

#include <timsbindec.h>

Public Member Functions

 TimsBinDec (const QFileInfo &timsBinFile, int timsCompressionType)
 
 TimsBinDec (const TimsBinDec &other)
 
 ~TimsBinDec ()
 
TimsFrameSPtr getTimsFrameSPtrByOffset (std::size_t timsId, std::size_t timsOffset) const
 

Private Member Functions

void indexingFile ()
 

Private Attributes

QString m_timsBinFile
 

Detailed Description

Todo:
write docs

Definition at line 40 of file timsbindec.h.

Constructor & Destructor Documentation

◆ TimsBinDec() [1/2]

TimsBinDec::TimsBinDec ( const QFileInfo &  timsBinFile,
int  timsCompressionType 
)

Default constructor

Definition at line 35 of file timsbindec.cpp.

36  : m_timsBinFile(timsBinFile.absoluteFilePath())
37 {
38 
39  if(timsCompressionType != 2)
40  {
42  QObject::tr("compression type %1 not handled by this library")
43  .arg(timsCompressionType));
44  }
45  if(m_timsBinFile.isEmpty())
46  {
48  QObject::tr("No TIMS binary file name specified"));
49  }
50  QFile file(m_timsBinFile);
51  if(!file.open(QIODevice::ReadOnly))
52  {
53  throw PappsoException(
54  QObject::tr("ERROR opening TIMS binary file %1 for read")
55  .arg(timsBinFile.absoluteFilePath()));
56  }
57 }
QString m_timsBinFile
Definition: timsbindec.h:69

References m_timsBinFile.

◆ TimsBinDec() [2/2]

TimsBinDec::TimsBinDec ( const TimsBinDec other)

Copy constructor

Parameters
otherTODO

Definition at line 60 of file timsbindec.cpp.

62 {
63 }

◆ ~TimsBinDec()

TimsBinDec::~TimsBinDec ( )

Destructor

Definition at line 65 of file timsbindec.cpp.

66 {
67 }

Member Function Documentation

◆ getTimsFrameSPtrByOffset()

TimsFrameSPtr TimsBinDec::getTimsFrameSPtrByOffset ( std::size_t  timsId,
std::size_t  timsOffset 
) const

Definition at line 142 of file timsbindec.cpp.

144 {
145  qDebug() << "timsId:" << timsId << "timsOffset:" << timsOffset;
146 
147  // QMutexLocker locker(&m_mutex);
148  QFile file(m_timsBinFile);
149  if(!file.open(QIODevice::ReadOnly))
150  {
151  throw PappsoException(
152  QObject::tr("ERROR opening TIMS binary file %1 for read")
153  .arg(m_timsBinFile));
154  }
155 
156  bool seekpos_ok = file.seek(timsOffset);
157  if(!seekpos_ok)
158  {
159  throw PappsoException(
160  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
161  "m_timsBinFile.seek(%3) failed")
162  .arg(timsId)
163  .arg(m_timsBinFile)
164  .arg(timsOffset));
165  }
166 
167  quint32 frame_length;
168  file.read((char *)&frame_length, 4);
169  // frame_length = qToBigEndian(frame_length);
170 
171  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
172  // << " frame_length=" << frame_length;
173 
174  quint32 scan_number;
175  file.read((char *)&scan_number, 4);
176  // scan_number = qToBigEndian(scan_number);
177  frame_length -= 8;
178 
179  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
180  // << " pos=" << m_timsBinFile.pos();
181 
182  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
183  // << " scan_number=" << scan_number;
184  // m_timsBinFile.seek(m_indexArray.at(timsId) + 8);
185 
186 
187  qDebug();
188 
189  QByteArray frame_byte_array = file.read((qint64)frame_length + 2);
190 
191  file.close();
192 
193  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
194  // << " +frame_length-1="
195  // << (quint8) * (frame_byte_array.constData() + frame_length - 1);
196  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
197  // << " +frame_length="
198  // << (quint8) * (frame_byte_array.constData() + frame_length);
199  // m_timsBinFile.seek(m_indexArray.at(timsId) + 8);
200 
201  if(frame_byte_array.size() - 2 != (qint64)frame_length)
202  {
203  throw PappsoException(
204  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
205  "frame_byte_array.size()%3 != %4frame_length")
206  .arg(timsId)
207  .arg(m_timsBinFile)
208  .arg(frame_byte_array.size())
209  .arg(frame_length));
210  }
211  TimsFrameSPtr frame_sptr;
212  if(frame_length > 0)
213  {
214  auto decompressed_size2 =
215  ZSTD_getFrameContentSize(frame_byte_array.constData(), frame_length);
216 
217  if(decompressed_size2 == ZSTD_CONTENTSIZE_UNKNOWN)
218  {
219  throw PappsoException(
220  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
221  " decompressed_size2 == ZSTD_CONTENTSIZE_UNKNOWN, "
222  "frame_length=%3")
223  .arg(timsId)
224  .arg(m_timsBinFile)
225  .arg(frame_length));
226  }
227 
228  if(decompressed_size2 == ZSTD_CONTENTSIZE_ERROR)
229  {
230  throw PappsoException(
231  QObject::tr(
232  "ERROR reading TIMS frame %1 TIMS binary file %2: "
233  " decompressed_size2 == ZSTD_CONTENTSIZE_ERROR, frame_length=%3")
234  .arg(timsId)
235  .arg(m_timsBinFile)
236  .arg(frame_length));
237  }
238  qDebug() << " decompressed_size2=" << decompressed_size2;
239 
240  char *uncompress = new char[decompressed_size2 + 10];
241  std::size_t decompressed_size =
242  ZSTD_decompress(uncompress,
243  decompressed_size2 + 10,
244  frame_byte_array.constData(),
245  frame_length);
246  qDebug();
247 
248  if(decompressed_size != decompressed_size2)
249  {
250  throw PappsoException(
251  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
252  "decompressed_size != decompressed_size2")
253  .arg(timsId)
254  .arg(m_timsBinFile)
255  .arg(decompressed_size)
256  .arg(decompressed_size2));
257  }
258 
259  qDebug();
260 
261  frame_sptr = std::make_shared<TimsFrame>(
262  timsId, scan_number, uncompress, decompressed_size);
263 
264  delete[] uncompress;
265  }
266  else
267  {
268  frame_sptr = std::make_shared<TimsFrame>(timsId, scan_number, nullptr, 0);
269  }
270  return frame_sptr;
271 }
std::shared_ptr< TimsFrame > TimsFrameSPtr
Definition: timsframe.h:40

References m_timsBinFile.

Referenced by pappso::TimsData::getTimsFrameCstSPtr().

◆ indexingFile()

void TimsBinDec::indexingFile ( )
private

Definition at line 71 of file timsbindec.cpp.

72 {
73 
74  qDebug();
75  QFile file(m_timsBinFile);
76  QDataStream bin_in(&file);
77  bin_in.setByteOrder(QDataStream::ByteOrder::LittleEndian);
78  // m_indexArray.push_back(0);
79 
80  // QChar first_char;
81  // txt_in >> first_char;
82  quint32 number_in;
83  qint64 position(0);
84  qint8 trash;
85  while(!bin_in.atEnd())
86  {
87  while((!bin_in.atEnd()) && (position % 4 != 0))
88  {
89  bin_in >> trash;
90  position += 1;
91  if(trash != 0)
92  { /*
93  throw PappsoException(
94  QObject::tr("ERROR reading TIMS frame %1 TIMS binary file %2: "
95  "trash%3 != 0")
96  .arg(m_indexArray.size())
97  .arg(m_timsBinFile.fileName())
98  .arg(trash));*/
99  }
100  }
101  quint32 frame_len(0);
102  while((!bin_in.atEnd()) && (frame_len == 0))
103  {
104  bin_in >> frame_len;
105  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
106  // << " i=" << i;
107  position += 4;
108  }
109 
110  // m_indexArray.push_back(position - 4);
111  /*
112  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
113  << " frame_len=" << frame_len
114  << " frameid=" << m_indexArray.size() - 1
115  << " back=" << m_indexArray.back() << " position=" <<
116  position;
117 
118 
119  quint64 next_frame = m_indexArray.back() + frame_len;
120  */
121 
122  bin_in >> number_in;
123  position += 4;
124  qDebug() << " number_in(nb scans)=" << number_in
125  << " position=" << position;
126  ;
127  /*
128 
129  while((!bin_in.atEnd()) && (position < next_frame))
130  {
131  bin_in >> trash;
132  // qDebug() << __FILE__ << " " << __FUNCTION__ << " " <<
133  __LINE__
134  // << " i=" << i;
135  position += 1;
136  }*/
137  }
138  qDebug();
139 }

References m_timsBinFile.

Member Data Documentation

◆ m_timsBinFile

QString pappso::TimsBinDec::m_timsBinFile
private

Definition at line 69 of file timsbindec.h.

Referenced by TimsBinDec(), getTimsFrameSPtrByOffset(), and indexingFile().


The documentation for this class was generated from the following files: