Isis Developer Reference
CubeIoHandler.h
Go to the documentation of this file.
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#ifndef CubeIoHandler_h
9#define CubeIoHandler_h
10
11#include <QRunnable>
12#include <QThreadPool>
13
14#include "Constants.h"
15#include "Endian.h"
16#include "PixelType.h"
17
18class QFile;
19class QMutex;
20class QElapsedTimer;
21template <typename A> class QList;
22template <typename A, typename B> class QMap;
23template <typename A, typename B> struct QPair;
24
25namespace Isis {
26 class Buffer;
27 class CubeCachingAlgorithm;
28 class EndianSwapper;
29 class Pvl;
30 class RawCubeChunk;
31
110 public:
111 CubeIoHandler(QFile * dataFile, const QList<int> *virtualBandList,
112 const Pvl &label, bool alreadyOnDisk);
113 virtual ~CubeIoHandler();
114
115 void read(Buffer &bufferToFill) const;
116 void write(const Buffer &bufferToWrite);
117
119 void clearCache(bool blockForWriteCache = true) const;
120 BigInt getDataSize() const;
121 void setVirtualBands(const QList<int> *virtualBandList);
127 virtual void updateLabels(Pvl &labels) = 0;
128
129 QMutex *dataFileMutex();
130
131 protected:
132 int bandCount() const;
133 int getBandCountInChunk() const;
134 BigInt getBytesPerChunk() const;
138 int getChunkIndex(const RawCubeChunk &) const;
139 BigInt getDataStartByte() const;
140 QFile * getDataFile();
141 int lineCount() const;
142 int getLineCountInChunk() const;
143 PixelType pixelType() const;
144 int sampleCount() const;
145 int getSampleCountInChunk() const;
146
147 void setChunkSizes(int numSamples, int numLines, int numBands);
148
157 virtual void readRaw(RawCubeChunk &chunkToFill) = 0;
158
166 virtual void writeRaw(const RawCubeChunk &chunkToWrite) = 0;
167
168 private:
185 class BufferToChunkWriter : public QRunnable {
186 public:
187 BufferToChunkWriter(CubeIoHandler * ioHandler,
188 QList<Buffer *> buffersToWrite);
189 ~BufferToChunkWriter();
190
191 void run();
192
193 private:
198 BufferToChunkWriter(const BufferToChunkWriter & other);
204 BufferToChunkWriter & operator=(const BufferToChunkWriter & rhs);
205
206 private:
208 CubeIoHandler * m_ioHandler;
210 QList<Buffer * > * m_buffersToWrite;
212 QElapsedTimer *m_timer;
213 };
214
215
221 CubeIoHandler(const CubeIoHandler &other);
222
230 CubeIoHandler &operator=(const CubeIoHandler &other);
231
232 void blockUntilThreadPoolEmpty() const;
233
234 static bool bufferLessThan(Buffer * const &lhs, Buffer * const &rhs);
235
236 QPair< QList<RawCubeChunk *>, QList<int> > findCubeChunks(int startSample, int numSamples,
237 int startLine, int numLines,
238 int startBand, int numBands) const;
239
240 void findIntersection(const RawCubeChunk &cube1,
241 const Buffer &cube2, int &startX, int &startY, int &startZ,
242 int &endX, int &endY, int &endZ) const;
243
244 void flushWriteCache(bool force = false) const;
245
246 void freeChunk(RawCubeChunk *chunkToFree) const;
247
248 RawCubeChunk *getChunk(int chunkIndex, bool allocateIfNecessary) const;
249
250 int getChunkCount() const;
251
252 void getChunkPlacement(int chunkIndex,
253 int &startSample, int &startLine, int &startBand,
254 int &endSample, int &endLine, int &endBand) const;
255
256 RawCubeChunk *getNullChunk(int chunkIndex) const;
257
258 void minimizeCache(const QList<RawCubeChunk *> &justUsed,
259 const Buffer &justRequested) const;
260
261 void synchronousWrite(const Buffer &bufferToWrite);
262
263 void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const;
264
265 void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const;
266
267 void writeNullDataToDisk() const;
268
269 private:
271 QFile * m_dataFile;
272
278 BigInt m_startByte;
279
281 PixelType m_pixelType;
282
284 double m_base;
285
287 double m_multiplier;
288
290 ByteOrder m_byteOrder;
291
293 EndianSwapper * m_byteSwapper;
294
296 int m_numSamples;
297
299 int m_numLines;
300
302 int m_numBands;
303
305 QList<CubeCachingAlgorithm *> * m_cachingAlgorithms;
306
308 mutable QMap<int, RawCubeChunk *> * m_rawData;
309
311 mutable QMap<int, bool> * m_dataIsOnDiskMap;
312
314 QList<int> * m_virtualBands;
315
317 int m_samplesInChunk;
318
320 int m_linesInChunk;
321
323 int m_bandsInChunk;
324
329 mutable QList<RawCubeChunk *> *m_lastProcessByLineChunks;
330
332 mutable QByteArray *m_nullChunkData;
333
335 QPair< QMutex *, QList<Buffer *> > *m_writeCache;
336
342 mutable QThreadPool *m_ioThreadPool;
343
348 mutable bool m_lastOperationWasWrite;
353 bool m_useOptimizedCubeWrite;
354
356 QMutex *m_writeThreadMutex;
357
359 mutable volatile int m_idealFlushSize;
360
362 mutable int m_consecutiveOverflowCount;
363 };
364}
365
366#endif
Buffer for reading and writing cube data.
Definition Buffer.h:53
This is the parent of the caching algorithms.
Definition CubeCachingAlgorithm.h:31
Handles converting buffers to and from disk.
Definition CubeIoHandler.h:109
void clearCache(bool blockForWriteCache=true) const
Free all cube chunks (cached cube data) from memory and write them to disk.
Definition CubeIoHandler.cpp:379
int bandCount() const
Definition CubeIoHandler.cpp:462
virtual ~CubeIoHandler()
Cleans up all allocated memory.
Definition CubeIoHandler.cpp:155
void addCachingAlgorithm(CubeCachingAlgorithm *algorithm)
This will add the given caching algorithm to the list of attempted caching algorithms.
Definition CubeIoHandler.cpp:364
QMutex * dataFileMutex()
Get the mutex that this IO handler is using around I/Os on the given data file.
Definition CubeIoHandler.cpp:455
PixelType pixelType() const
Definition CubeIoHandler.cpp:580
QFile * getDataFile()
Definition CubeIoHandler.cpp:555
int getChunkCountInLineDimension() const
Definition CubeIoHandler.cpp:501
void setChunkSizes(int numSamples, int numLines, int numBands)
This should be called once from the child constructor.
Definition CubeIoHandler.cpp:614
int getLineCountInChunk() const
Definition CubeIoHandler.cpp:572
int getChunkCountInSampleDimension() const
Definition CubeIoHandler.cpp:510
virtual void readRaw(RawCubeChunk &chunkToFill)=0
This needs to populate the chunkToFill with unswapped raw bytes from the disk.
int getChunkCountInBandDimension() const
Definition CubeIoHandler.cpp:492
CubeIoHandler(QFile *dataFile, const QList< int > *virtualBandList, const Pvl &label, bool alreadyOnDisk)
Creates a new CubeIoHandler using a RegionalCachingAlgorithm.
Definition CubeIoHandler.cpp:61
BigInt getBytesPerChunk() const
Definition CubeIoHandler.cpp:482
BigInt getDataStartByte() const
Definition CubeIoHandler.cpp:544
virtual void writeRaw(const RawCubeChunk &chunkToWrite)=0
This needs to write the chunkToWrite directly to disk with no modifications to the data itself.
int sampleCount() const
Definition CubeIoHandler.cpp:589
int lineCount() const
Definition CubeIoHandler.cpp:564
void read(Buffer &bufferToFill) const
Read cube data from disk into the buffer.
Definition CubeIoHandler.cpp:226
void write(const Buffer &bufferToWrite)
Write buffer data into the cube data on disk.
Definition CubeIoHandler.cpp:334
void setVirtualBands(const QList< int > *virtualBandList)
This changes the virtual band list.
Definition CubeIoHandler.cpp:438
virtual void updateLabels(Pvl &labels)=0
Function to update the labels with a Pvl object.
int getSampleCountInChunk() const
Definition CubeIoHandler.cpp:597
BigInt getDataSize() const
Definition CubeIoHandler.cpp:421
int getBandCountInChunk() const
Definition CubeIoHandler.cpp:470
int getChunkIndex(const RawCubeChunk &) const
Given a chunk, what's its index in the file.
Definition CubeIoHandler.cpp:526
Byte swapper.
Definition EndianSwapper.h:38
Container for cube-like labels.
Definition Pvl.h:119
A section of raw data on the disk.
Definition RawCubeChunk.h:27
This is free and unencumbered software released into the public domain.
Definition BoxcarCachingAlgorithm.h:13
This is free and unencumbered software released into the public domain.
Definition CubeIoHandler.h:22
ByteOrder
Tests the current architecture for byte order.
Definition Endian.h:42
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
long long int BigInt
Big int.
Definition Constants.h:49
PixelType
Enumerations for Isis Pixel Types.
Definition PixelType.h:27
This is free and unencumbered software released into the public domain.
Definition CubeIoHandler.h:23