Isis 3.0 Programmer Reference
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:
191  public:
193  QList<Buffer *> buffersToWrite);
195 
196  void run();
197 
198  private:
210 
211  private:
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 
287 
289  double m_base;
290 
292  double m_multiplier;
293 
296 
299 
302 
305 
308 
311 
314 
317 
320 
323 
326 
329 
335 
337  mutable QByteArray *m_nullChunkData;
338 
341 
347  mutable QThreadPool *m_ioThreadPool;
348 
359 
362 
364  mutable volatile int m_idealFlushSize;
365 
368  };
369 }
370 
371 #endif
Buffer for reading and writing cube data.
Definition: Buffer.h:68
BufferToChunkWriter & operator=(const BufferToChunkWriter &rhs)
This is disabled.
ByteOrder m_byteOrder
The byte order (endianness) of the data on disk.
void write(const Buffer &bufferToWrite)
Write buffer data into the cube data on disk.
int m_linesInChunk
The number of lines in a cube chunk.
void freeChunk(RawCubeChunk *chunkToFree) const
If the chunk is dirty, then we write it to disk.
BigInt getDataStartByte() const
void getChunkPlacement(int chunkIndex, int &startSample, int &startLine, int &startBand, int &endSample, int &endLine, int &endBand) const
Get the X/Y/Z (Sample,Line,Band) range of the chunk at the given index.
void addCachingAlgorithm(CubeCachingAlgorithm *algorithm)
This will add the given caching algorithm to the list of attempted caching algorithms.
void setChunkSizes(int numSamples, int numLines, int numBands)
This should be called once from the child constructor.
CubeIoHandler & operator=(const CubeIoHandler &other)
Disallow assignments of this object.
QList< Buffer * > * m_buffersToWrite
The buffers that need pushed into the IO handler; we own these.
bool m_lastOperationWasWrite
If the last operation was a write then we need to flush the cache when reading.
BigInt getBytesPerChunk() const
void findIntersection(const RawCubeChunk &cube1, const Buffer &cube2, int &startX, int &startY, int &startZ, int &endX, int &endY, int &endZ) const
Find the intersection between the buffer area and the cube chunk.
virtual void readRaw(RawCubeChunk &chunkToFill)=0
This needs to populate the chunkToFill with unswapped raw bytes from the disk.
int sampleCount() const
QMap< int, RawCubeChunk * > * m_rawData
The map from chunk index to chunk for cached data.
void minimizeCache(const QList< RawCubeChunk * > &justUsed, const Buffer &justRequested) const
Apply the caching algorithms and get rid of excess cube data in memory.
QMutex * dataFileMutex()
Get the mutex that this IO handler is using around I/Os on the given data file.
QPair< QMutex *, QList< Buffer * > > * m_writeCache
These are the buffers we need to write to raw cube chunks.
void read(Buffer &bufferToFill) const
Read cube data from disk into the buffer.
QPair< QList< RawCubeChunk * >, QList< int > > findCubeChunks(int startSample, int numSamples, int startLine, int numLines, int startBand, int numBands) const
Get the cube chunks that correspond to the given cube area.
virtual void writeRaw(const RawCubeChunk &chunkToWrite)=0
This needs to write the chunkToWrite directly to disk with no modifications to the data itself...
volatile int m_idealFlushSize
Ideal write cache flush size.
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:59
int bandCount() const
int m_numSamples
The number of samples in the cube.
void run()
This is the asynchronous computation.
int m_bandsInChunk
The number of physical bands in a cube chunk.
int m_numBands
The number of physical bands in the cube.
QList< int > * m_virtualBands
Converts from virtual band to physical band.
virtual ~CubeIoHandler()
Cleans up all allocated memory.
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:43
Handles converting buffers to and from disk.
void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const
Write the intersecting area of the chunk into the buffer.
void flushWriteCache(bool force=false) const
This attempts to write the so-far-unwritten buffers from m_writeCache into the cube&#39;s RawCubeChunk ca...
CubeIoHandler(QFile *dataFile, const QList< int > *virtualBandList, const Pvl &label, bool alreadyOnDisk)
Creates a new CubeIoHandler using a RegionalCachingAlgorithm.
QMap< int, bool > * m_dataIsOnDiskMap
The map from chunk index to on-disk status, all true if not allocated.
int getLineCountInChunk() const
PixelType m_pixelType
The format of each DN in the cube.
int m_numLines
The number of lines in the cube.
int getChunkIndex(const RawCubeChunk &) const
Given a chunk, what&#39;s its index in the file.
int getChunkCount() const
CubeIoHandler * m_ioHandler
The IO Handler instance to put the buffers into.
QMutex * m_writeThreadMutex
This enables us to block while the write thread is working.
RawCubeChunk * getChunk(int chunkIndex, bool allocateIfNecessary) const
Retrieve the cached chunk at the given chunk index, if there is one.
int getChunkCountInBandDimension() const
bool m_useOptimizedCubeWrite
This is true if the Isis preference for the cube write thread is optimized.
QByteArray * m_nullChunkData
A raw cube chunk&#39;s data when it was all NULL&#39;s. Used for speed.
BigInt getDataSize() const
static bool bufferLessThan(Buffer *const &lhs, Buffer *const &rhs)
This is used for sorting buffers into the most efficient write order.
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.
void setVirtualBands(const QList< int > *virtualBandList)
This changes the virtual band list.
Container for cube-like labels.
Definition: Pvl.h:135
void blockUntilThreadPoolEmpty() const
This blocks (doesn&#39;t return) until the number of active runnables in the thread pool goes to 0...
double m_base
The additive offset of the data on disk.
BigInt m_startByte
The start byte of the cube data.
EndianSwapper * m_byteSwapper
A helper that swaps byte order to and from file order.
int getChunkCountInSampleDimension() const
BufferToChunkWriter(CubeIoHandler *ioHandler, QList< Buffer * > buffersToWrite)
Create a BufferToChunkWriter which is designed to asynchronously move the given buffers into the cube...
double m_multiplier
The multiplicative factor of the data on disk.
int lineCount() const
QThreadPool * m_ioThreadPool
This contains threads for doing cube writes (and later maybe cube reads).
PixelType pixelType() const
int getChunkCountInLineDimension() const
void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const
Write the intersecting area of the buffer into the chunk.
int m_samplesInChunk
The number of samples in a cube chunk.
int getSampleCountInChunk() const
QFile * m_dataFile
The file containing cube data.
int getBandCountInChunk() const
~BufferToChunkWriter()
We&#39;re done writing our buffers into the cube, clean up.
This class is designed to handle write() asynchronously.
RawCubeChunk * getNullChunk(int chunkIndex) const
This creates a chunk filled with NULLs whose placement is at chunkIndex&#39;s position.
void synchronousWrite(const Buffer &bufferToWrite)
This method takes the given buffer and synchronously puts it into the Cube&#39;s cache.
int m_consecutiveOverflowCount
How many times the write cache has overflown in a row.
This is the parent of the caching algorithms.
QList< RawCubeChunk * > * m_lastProcessByLineChunks
This is an optimization for process by line.
QTime * m_timer
Used to calculate the lifetime of an instance of this class.
void writeNullDataToDisk() const
Write all NULL cube chunks that have not yet been accessed to disk.
QList< CubeCachingAlgorithm * > * m_cachingAlgorithms
The caching algorithms to use, in order of priority.

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:11