Isis 3.0
Back | 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> struct QPair;
40 
41 namespace Isis {
42  class Buffer;
43  class CubeCachingAlgorithm;
44  class EndianSwapper;
45  class Pvl;
46  class RawCubeChunk;
47 
120  public:
121  CubeIoHandler(QFile * dataFile, const QList<int> *virtualBandList,
122  const Pvl &label, bool alreadyOnDisk);
123  virtual ~CubeIoHandler();
124 
125  void read(Buffer &bufferToFill) const;
126  void write(const Buffer &bufferToWrite);
127 
128  void addCachingAlgorithm(CubeCachingAlgorithm *algorithm);
129  void clearCache(bool blockForWriteCache = true) const;
130  BigInt getDataSize() const;
131  void setVirtualBands(const QList<int> *virtualBandList);
132  virtual void updateLabels(Pvl &labels) = 0;
133 
134  QMutex *dataFileMutex();
135 
136  protected:
137  int bandCount() const;
138  int getBandCountInChunk() const;
139  BigInt getBytesPerChunk() const;
140  int getChunkCountInBandDimension() const;
141  int getChunkCountInLineDimension() const;
142  int getChunkCountInSampleDimension() const;
143  int getChunkIndex(const RawCubeChunk &) const;
144  BigInt getDataStartByte() const;
145  QFile * getDataFile();
146  int lineCount() const;
147  int getLineCountInChunk() const;
148  PixelType pixelType() const;
149  int sampleCount() const;
150  int getSampleCountInChunk() const;
151 
152  void setChunkSizes(int numSamples, int numLines, int numBands);
153 
162  virtual void readRaw(RawCubeChunk &chunkToFill) = 0;
163 
171  virtual void writeRaw(const RawCubeChunk &chunkToWrite) = 0;
172 
173  private:
190  class BufferToChunkWriter : public QRunnable {
191  public:
192  BufferToChunkWriter(CubeIoHandler * ioHandler,
193  QList<Buffer *> buffersToWrite);
194  ~BufferToChunkWriter();
195 
196  void run();
197 
198  private:
203  BufferToChunkWriter(const BufferToChunkWriter & other);
209  BufferToChunkWriter & operator=(const BufferToChunkWriter & rhs);
210 
211  private:
213  CubeIoHandler * m_ioHandler;
215  QList<Buffer * > * m_buffersToWrite;
217  QTime *m_timer;
218  };
219 
220 
226  CubeIoHandler(const CubeIoHandler &other);
227 
235  CubeIoHandler &operator=(const CubeIoHandler &other);
236 
237  void blockUntilThreadPoolEmpty() const;
238 
239  static bool bufferLessThan(Buffer * const &lhs, Buffer * const &rhs);
240 
241  QPair< QList<RawCubeChunk *>, QList<int> > findCubeChunks(int startSample, int numSamples,
242  int startLine, int numLines,
243  int startBand, int numBands) const;
244 
245  void findIntersection(const RawCubeChunk &cube1,
246  const Buffer &cube2, int &startX, int &startY, int &startZ,
247  int &endX, int &endY, int &endZ) const;
248 
249  void flushWriteCache(bool force = false) const;
250 
251  void freeChunk(RawCubeChunk *chunkToFree) const;
252 
253  RawCubeChunk *getChunk(int chunkIndex, bool allocateIfNecessary) const;
254 
255  int getChunkCount() const;
256 
257  void getChunkPlacement(int chunkIndex,
258  int &startSample, int &startLine, int &startBand,
259  int &endSample, int &endLine, int &endBand) const;
260 
261  RawCubeChunk *getNullChunk(int chunkIndex) const;
262 
263  void minimizeCache(const QList<RawCubeChunk *> &justUsed,
264  const Buffer &justRequested) const;
265 
266  void synchronousWrite(const Buffer &bufferToWrite);
267 
268  void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const;
269 
270  void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const;
271 
272  void writeNullDataToDisk() const;
273 
274  private:
276  QFile * m_dataFile;
277 
283  BigInt m_startByte;
284 
286  PixelType m_pixelType;
287 
289  double m_base;
290 
292  double m_multiplier;
293 
295  ByteOrder m_byteOrder;
296 
298  EndianSwapper * m_byteSwapper;
299 
301  int m_numSamples;
302 
304  int m_numLines;
305 
307  int m_numBands;
308 
310  QList<CubeCachingAlgorithm *> * m_cachingAlgorithms;
311 
313  mutable QMap<int, RawCubeChunk *> * m_rawData;
314 
316  mutable QMap<int, bool> * m_dataIsOnDiskMap;
317 
319  QList<int> * m_virtualBands;
320 
322  int m_samplesInChunk;
323 
325  int m_linesInChunk;
326 
328  int m_bandsInChunk;
329 
334  mutable QList<RawCubeChunk *> *m_lastProcessByLineChunks;
335 
337  mutable QByteArray *m_nullChunkData;
338 
340  QPair< QMutex *, QList<Buffer *> > *m_writeCache;
341 
347  mutable QThreadPool *m_ioThreadPool;
348 
353  mutable bool m_lastOperationWasWrite;
358  bool m_useOptimizedCubeWrite;
359 
361  QMutex *m_writeThreadMutex;
362 
364  mutable volatile int m_idealFlushSize;
365 
367  mutable int m_consecutiveOverflowCount;
368  };
369 }
370 
371 #endif
Buffer for reading and writing cube data.
Definition: Buffer.h:68
long long int BigInt
Definition: Constants.h:63
void write(const Buffer &bufferToWrite)
Write buffer data into the cube data on disk.
Definition: CubeIoHandler.cpp:354
BigInt getDataStartByte() const
Definition: CubeIoHandler.cpp:567
void addCachingAlgorithm(CubeCachingAlgorithm *algorithm)
This will add the given caching algorithm to the list of attempted caching algorithms.
Definition: CubeIoHandler.cpp:384
void setChunkSizes(int numSamples, int numLines, int numBands)
This should be called once from the child constructor.
Definition: CubeIoHandler.cpp:637
BigInt getBytesPerChunk() const
Definition: CubeIoHandler.cpp:502
virtual void readRaw(RawCubeChunk &chunkToFill)=0
This needs to populate the chunkToFill with unswapped raw bytes from the disk.
int sampleCount() const
Definition: CubeIoHandler.cpp:612
QMutex * dataFileMutex()
Get the mutex that this IO handler is using around I/Os on the given data file.
Definition: CubeIoHandler.cpp:475
void read(Buffer &bufferToFill) const
Read cube data from disk into the buffer.
Definition: CubeIoHandler.cpp:246
virtual void writeRaw(const RawCubeChunk &chunkToWrite)=0
This needs to write the chunkToWrite directly to disk with no modifications to the data itself...
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:59
int bandCount() const
Definition: CubeIoHandler.cpp:482
virtual ~CubeIoHandler()
Cleans up all allocated memory.
Definition: CubeIoHandler.cpp:173
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:43
Handles converting buffers to and from disk.
Definition: CubeIoHandler.h:119
CubeIoHandler(QFile *dataFile, const QList< int > *virtualBandList, const Pvl &label, bool alreadyOnDisk)
Creates a new CubeIoHandler using a RegionalCachingAlgorithm.
Definition: CubeIoHandler.cpp:79
int getLineCountInChunk() const
Definition: CubeIoHandler.cpp:595
int getChunkIndex(const RawCubeChunk &) const
Given a chunk, what&#39;s its index in the file.
Definition: CubeIoHandler.cpp:546
int getChunkCountInBandDimension() const
Definition: CubeIoHandler.cpp:512
QFile * getDataFile()
Definition: CubeIoHandler.cpp:578
virtual void updateLabels(Pvl &labels)=0
BigInt getDataSize() const
Definition: CubeIoHandler.cpp:441
A section of raw data on the disk.
Definition: RawCubeChunk.h:42
Byte swapper.
Definition: EndianSwapper.h:54
void clearCache(bool blockForWriteCache=true) const
Free all cube chunks (cached cube data) from memory and write them to disk.
Definition: CubeIoHandler.cpp:399
void setVirtualBands(const QList< int > *virtualBandList)
This changes the virtual band list.
Definition: CubeIoHandler.cpp:458
Container for cube-like labels.
Definition: Pvl.h:135
int getChunkCountInSampleDimension() const
Definition: CubeIoHandler.cpp:530
int lineCount() const
Definition: CubeIoHandler.cpp:587
PixelType pixelType() const
Definition: CubeIoHandler.cpp:603
Definition: BoxcarCachingAlgorithm.h:29
int getChunkCountInLineDimension() const
Definition: CubeIoHandler.cpp:521
int getSampleCountInChunk() const
Definition: CubeIoHandler.cpp:620
int getBandCountInChunk() const
Definition: CubeIoHandler.cpp:490
Definition: CubeIoHandler.h:39
This is the parent of the caching algorithms.
Definition: CubeCachingAlgorithm.h:47
Definition: CubeIoHandler.h:38

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:17:13