USGS

Isis 3.0 Developer's Reference (API)

Home

CubeIoHandler.h
Go to the documentation of this file.
1 
24 #ifndef CubeIoHandler_h
25 #define CubeIoHandler_h
26 
27 #include <QRunnable>
28 #include <QThreadPool>
29 
30 #include "Constants.h"
31 #include "Endian.h"
32 #include "PixelType.h"
33 
34 class QFile;
35 class QMutex;
36 class QTime;
37 template <typename A> class QList;
38 template <typename A, typename B> class QMap;
39 template <typename A, typename B> class QPair;
40 
41 namespace Isis {
42  class Buffer;
43  class CubeCachingAlgorithm;
44  class EndianSwapper;
45  class Pvl;
46  class RawCubeChunk;
47 
116  public:
117  CubeIoHandler(QFile * dataFile, const QList<int> *virtualBandList,
118  const Pvl &label, bool alreadyOnDisk);
119  virtual ~CubeIoHandler();
120 
121  void read(Buffer &bufferToFill) const;
122  void write(const Buffer &bufferToWrite);
123 
124  void addCachingAlgorithm(CubeCachingAlgorithm *algorithm);
125  void clearCache(bool blockForWriteCache = true) const;
126  BigInt getDataSize() const;
127  void setVirtualBands(const QList<int> *virtualBandList);
128  virtual void updateLabels(Pvl &labels);
129 
130  QMutex *dataFileMutex();
131 
132  protected:
133  int bandCount() const;
134  int getBandCountInChunk() const;
135  BigInt getBytesPerChunk() const;
136  int getChunkCountInBandDimension() const;
137  int getChunkCountInLineDimension() const;
138  int getChunkCountInSampleDimension() const;
139  int getChunkIndex(const RawCubeChunk &) const;
140  BigInt getDataStartByte() const;
141  QFile * getDataFile();
142  int lineCount() const;
143  int getLineCountInChunk() const;
144  PixelType pixelType() const;
145  int sampleCount() const;
146  int getSampleCountInChunk() const;
147 
148  void setChunkSizes(int numSamples, int numLines, int numBands);
149 
158  virtual void readRaw(RawCubeChunk &chunkToFill) = 0;
159 
167  virtual void writeRaw(const RawCubeChunk &chunkToWrite) = 0;
168 
169  private:
186  class BufferToChunkWriter : public QRunnable {
187  public:
188  BufferToChunkWriter(CubeIoHandler * ioHandler,
189  QList<Buffer *> buffersToWrite);
190  ~BufferToChunkWriter();
191 
192  void run();
193 
194  private:
199  BufferToChunkWriter(const BufferToChunkWriter & other);
205  BufferToChunkWriter & operator=(const BufferToChunkWriter & rhs);
206 
207  private:
209  CubeIoHandler * m_ioHandler;
211  QList<Buffer * > * m_buffersToWrite;
213  QTime *m_timer;
214  };
215 
216 
222  CubeIoHandler(const CubeIoHandler &other);
223 
231  CubeIoHandler &operator=(const CubeIoHandler &other);
232 
233  void blockUntilThreadPoolEmpty() const;
234 
235  static bool bufferLessThan(Buffer * const &lhs, Buffer * const &rhs);
236 
237  QPair< QList<RawCubeChunk *>, QList<int> > findCubeChunks(int startSample, int numSamples,
238  int startLine, int numLines,
239  int startBand, int numBands) const;
240 
241  void findIntersection(const RawCubeChunk &cube1,
242  const Buffer &cube2, int &startX, int &startY, int &startZ,
243  int &endX, int &endY, int &endZ) const;
244 
245  void flushWriteCache(bool force = false) const;
246 
247  void freeChunk(RawCubeChunk *chunkToFree) const;
248 
249  RawCubeChunk *getChunk(int chunkIndex, bool allocateIfNecessary) const;
250 
251  int getChunkCount() const;
252 
253  void getChunkPlacement(int chunkIndex,
254  int &startSample, int &startLine, int &startBand,
255  int &endSample, int &endLine, int &endBand) const;
256 
257  RawCubeChunk *getNullChunk(int chunkIndex) const;
258 
259  void minimizeCache(const QList<RawCubeChunk *> &justUsed,
260  const Buffer &justRequested) const;
261 
262  void synchronousWrite(const Buffer &bufferToWrite);
263 
264  void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const;
265 
266  void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const;
267 
268  void writeNullDataToDisk() const;
269 
270  private:
272  QFile * m_dataFile;
273 
279  BigInt m_startByte;
280 
282  PixelType m_pixelType;
283 
285  double m_base;
286 
288  double m_multiplier;
289 
291  ByteOrder m_byteOrder;
292 
294  EndianSwapper * m_byteSwapper;
295 
297  int m_numSamples;
298 
300  int m_numLines;
301 
303  int m_numBands;
304 
306  QList<CubeCachingAlgorithm *> * m_cachingAlgorithms;
307 
309  mutable QMap<int, RawCubeChunk *> * m_rawData;
310 
312  mutable QMap<int, bool> * m_dataIsOnDiskMap;
313 
315  QList<int> * m_virtualBands;
316 
318  int m_samplesInChunk;
319 
321  int m_linesInChunk;
322 
324  int m_bandsInChunk;
325 
330  mutable QList<RawCubeChunk *> *m_lastProcessByLineChunks;
331 
333  mutable QByteArray *m_nullChunkData;
334 
336  QPair< QMutex *, QList<Buffer *> > *m_writeCache;
337 
343  mutable QThreadPool *m_ioThreadPool;
344 
349  mutable bool m_lastOperationWasWrite;
354  bool m_useOptimizedCubeWrite;
355 
357  QMutex *m_writeThreadMutex;
358 
360  mutable volatile int m_idealFlushSize;
361 
363  mutable int m_consecutiveOverflowCount;
364  };
365 }
366 
367 #endif
368