File failed to load: https://isis.astrogeology.usgs.gov/3.9.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Developer Reference
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 
126  public:
127  CubeIoHandler(QFile * dataFile, const QList<int> *virtualBandList,
128  const Pvl &label, bool alreadyOnDisk);
129  virtual ~CubeIoHandler();
130 
131  void read(Buffer &bufferToFill) const;
132  void write(const Buffer &bufferToWrite);
133 
134  void addCachingAlgorithm(CubeCachingAlgorithm *algorithm);
135  void clearCache(bool blockForWriteCache = true) const;
136  BigInt getDataSize() const;
137  void setVirtualBands(const QList<int> *virtualBandList);
143  virtual void updateLabels(Pvl &labels) = 0;
144 
145  QMutex *dataFileMutex();
146 
147  protected:
148  int bandCount() const;
149  int getBandCountInChunk() const;
150  BigInt getBytesPerChunk() const;
151  int getChunkCountInBandDimension() const;
152  int getChunkCountInLineDimension() const;
153  int getChunkCountInSampleDimension() const;
154  int getChunkIndex(const RawCubeChunk &) const;
155  BigInt getDataStartByte() const;
156  QFile * getDataFile();
157  int lineCount() const;
158  int getLineCountInChunk() const;
159  PixelType pixelType() const;
160  int sampleCount() const;
161  int getSampleCountInChunk() const;
162 
163  void setChunkSizes(int numSamples, int numLines, int numBands);
164 
173  virtual void readRaw(RawCubeChunk &chunkToFill) = 0;
174 
182  virtual void writeRaw(const RawCubeChunk &chunkToWrite) = 0;
183 
184  private:
201  class BufferToChunkWriter : public QRunnable {
202  public:
203  BufferToChunkWriter(CubeIoHandler * ioHandler,
204  QList<Buffer *> buffersToWrite);
205  ~BufferToChunkWriter();
206 
207  void run();
208 
209  private:
214  BufferToChunkWriter(const BufferToChunkWriter & other);
220  BufferToChunkWriter & operator=(const BufferToChunkWriter & rhs);
221 
222  private:
224  CubeIoHandler * m_ioHandler;
226  QList<Buffer * > * m_buffersToWrite;
228  QTime *m_timer;
229  };
230 
231 
237  CubeIoHandler(const CubeIoHandler &other);
238 
246  CubeIoHandler &operator=(const CubeIoHandler &other);
247 
248  void blockUntilThreadPoolEmpty() const;
249 
250  static bool bufferLessThan(Buffer * const &lhs, Buffer * const &rhs);
251 
252  QPair< QList<RawCubeChunk *>, QList<int> > findCubeChunks(int startSample, int numSamples,
253  int startLine, int numLines,
254  int startBand, int numBands) const;
255 
256  void findIntersection(const RawCubeChunk &cube1,
257  const Buffer &cube2, int &startX, int &startY, int &startZ,
258  int &endX, int &endY, int &endZ) const;
259 
260  void flushWriteCache(bool force = false) const;
261 
262  void freeChunk(RawCubeChunk *chunkToFree) const;
263 
264  RawCubeChunk *getChunk(int chunkIndex, bool allocateIfNecessary) const;
265 
266  int getChunkCount() const;
267 
268  void getChunkPlacement(int chunkIndex,
269  int &startSample, int &startLine, int &startBand,
270  int &endSample, int &endLine, int &endBand) const;
271 
272  RawCubeChunk *getNullChunk(int chunkIndex) const;
273 
274  void minimizeCache(const QList<RawCubeChunk *> &justUsed,
275  const Buffer &justRequested) const;
276 
277  void synchronousWrite(const Buffer &bufferToWrite);
278 
279  void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const;
280 
281  void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const;
282 
283  void writeNullDataToDisk() const;
284 
285  private:
287  QFile * m_dataFile;
288 
294  BigInt m_startByte;
295 
297  PixelType m_pixelType;
298 
300  double m_base;
301 
303  double m_multiplier;
304 
306  ByteOrder m_byteOrder;
307 
309  EndianSwapper * m_byteSwapper;
310 
312  int m_numSamples;
313 
315  int m_numLines;
316 
318  int m_numBands;
319 
321  QList<CubeCachingAlgorithm *> * m_cachingAlgorithms;
322 
324  mutable QMap<int, RawCubeChunk *> * m_rawData;
325 
327  mutable QMap<int, bool> * m_dataIsOnDiskMap;
328 
330  QList<int> * m_virtualBands;
331 
333  int m_samplesInChunk;
334 
336  int m_linesInChunk;
337 
339  int m_bandsInChunk;
340 
345  mutable QList<RawCubeChunk *> *m_lastProcessByLineChunks;
346 
348  mutable QByteArray *m_nullChunkData;
349 
351  QPair< QMutex *, QList<Buffer *> > *m_writeCache;
352 
358  mutable QThreadPool *m_ioThreadPool;
359 
364  mutable bool m_lastOperationWasWrite;
369  bool m_useOptimizedCubeWrite;
370 
372  QMutex *m_writeThreadMutex;
373 
375  mutable volatile int m_idealFlushSize;
376 
378  mutable int m_consecutiveOverflowCount;
379  };
380 }
381 
382 #endif
Buffer for reading and writing cube data.
Definition: Buffer.h:69
long long int BigInt
Big int.
Definition: Constants.h:65
void clearCache(bool blockForWriteCache=true) const
Free all cube chunks (cached cube data) from memory and write them to disk.
Definition: CubeIoHandler.cpp:399
int getChunkIndex(const RawCubeChunk &) const
Given a chunk, what&#39;s its index in the file.
Definition: CubeIoHandler.cpp:546
void write(const Buffer &bufferToWrite)
Write buffer data into the cube data on disk.
Definition: CubeIoHandler.cpp:354
int getChunkCountInLineDimension() const
Definition: CubeIoHandler.cpp:521
int bandCount() const
Definition: CubeIoHandler.cpp:482
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
int getSampleCountInChunk() const
Definition: CubeIoHandler.cpp:620
virtual void readRaw(RawCubeChunk &chunkToFill)=0
This needs to populate the chunkToFill with unswapped raw bytes from the disk.
int getBandCountInChunk() const
Definition: CubeIoHandler.cpp:490
QMutex * dataFileMutex()
Get the mutex that this IO handler is using around I/Os on the given data file.
Definition: CubeIoHandler.cpp:475
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
BigInt getDataStartByte() const
Definition: CubeIoHandler.cpp:567
int sampleCount() const
Definition: CubeIoHandler.cpp:612
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:125
CubeIoHandler(QFile *dataFile, const QList< int > *virtualBandList, const Pvl &label, bool alreadyOnDisk)
Creates a new CubeIoHandler using a RegionalCachingAlgorithm.
Definition: CubeIoHandler.cpp:79
int lineCount() const
Definition: CubeIoHandler.cpp:587
int getChunkCountInBandDimension() const
Definition: CubeIoHandler.cpp:512
QFile * getDataFile()
Definition: CubeIoHandler.cpp:578
virtual void updateLabels(Pvl &labels)=0
Function to update the labels with a Pvl object.
BigInt getDataSize() const
Definition: CubeIoHandler.cpp:441
A section of raw data on the disk.
Definition: RawCubeChunk.h:42
Byte swapper.
Definition: EndianSwapper.h:55
BigInt getBytesPerChunk() const
Definition: CubeIoHandler.cpp:502
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
Definition: BoxcarCachingAlgorithm.h:29
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void read(Buffer &bufferToFill) const
Read cube data from disk into the buffer.
Definition: CubeIoHandler.cpp:246
Definition: CubeIoHandler.h:39
int getLineCountInChunk() const
Definition: CubeIoHandler.cpp:595
This is the parent of the caching algorithms
Definition: CubeCachingAlgorithm.h:47
Definition: CubeIoHandler.h:38
PixelType pixelType() const
Definition: CubeIoHandler.cpp:603

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 USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/12/2023 23:17:32