File failed to load: https://isis.astrogeology.usgs.gov/dev/Object/assets/jax/output/NativeMML/config.js
Isis Developer Reference
CubeIoHandler.h
Go to the documentation of this file.
1
5
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 "ImageIoHandler.h"
17#include "PixelType.h"
18
19class QFile;
20class QMutex;
21class QElapsedTimer;
22template <typename A> class QList;
23template <typename A, typename B> class QMap;
24template <typename A, typename B> struct QPair;
25
26namespace Isis {
27 class Buffer;
28 class CubeCachingAlgorithm;
29 class EndianSwapper;
30 class Pvl;
31 class RawCubeChunk;
32
111 public:
112 CubeIoHandler(QFile * dataFile, const QList<int> *virtualBandList,
113 const Pvl &label, bool alreadyOnDisk);
114 virtual ~CubeIoHandler();
115
116 virtual void read(Buffer &bufferToFill) const;
117 virtual void write(const Buffer &bufferToWrite);
118
119 virtual void addCachingAlgorithm(CubeCachingAlgorithm *algorithm);
120 virtual void clearCache(bool blockForWriteCache = true) const;
121 virtual BigInt getDataSize() const;
127 virtual void updateLabels(Pvl &labels) = 0;
128
129 int bandCount() const;
130 int getBandCountInChunk() const;
131 BigInt getBytesPerChunk() const;
135 int getChunkIndex(const RawCubeChunk &) const;
136 BigInt getDataStartByte() const;
137 int lineCount() const;
138 int getLineCountInChunk() const;
139 PixelType pixelType() const;
140 int sampleCount() const;
141 int getSampleCountInChunk() const;
142
143 protected:
144 QFile * getDataFile();
145
146 void setChunkSizes(int numSamples, int numLines, int numBands);
147
156 virtual void readRaw(RawCubeChunk &chunkToFill) = 0;
157
165 virtual void writeRaw(const RawCubeChunk &chunkToWrite) = 0;
166
167 private:
184 class BufferToChunkWriter : public QRunnable {
185 public:
186 BufferToChunkWriter(CubeIoHandler * ioHandler,
187 QList<Buffer *> buffersToWrite);
188 ~BufferToChunkWriter();
189
190 void run();
191
192 private:
197 BufferToChunkWriter(const BufferToChunkWriter & other);
203 BufferToChunkWriter & operator=(const BufferToChunkWriter & rhs);
204
205 private:
207 CubeIoHandler * m_ioHandler;
209 QList<Buffer * > * m_buffersToWrite;
211 QElapsedTimer *m_timer;
212 };
213
214
220 CubeIoHandler(const CubeIoHandler &other);
221
229 CubeIoHandler &operator=(const CubeIoHandler &other);
230
231 void blockUntilThreadPoolEmpty() const;
232
233 static bool bufferLessThan(Buffer * const &lhs, Buffer * const &rhs);
234
235 QPair< QList<RawCubeChunk *>, QList<int> > findCubeChunks(int startSample, int numSamples,
236 int startLine, int numLines,
237 int startBand, int numBands) const;
238
239 void findIntersection(const RawCubeChunk &cube1,
240 const Buffer &cube2, int &startX, int &startY, int &startZ,
241 int &endX, int &endY, int &endZ) const;
242
243 void flushWriteCache(bool force = false) const;
244
245 void freeChunk(RawCubeChunk *chunkToFree) const;
246
247 RawCubeChunk *getChunk(int chunkIndex, bool allocateIfNecessary) const;
248
249 int getChunkCount() const;
250
251 void getChunkPlacement(int chunkIndex,
252 int &startSample, int &startLine, int &startBand,
253 int &endSample, int &endLine, int &endBand) const;
254
255 RawCubeChunk *getNullChunk(int chunkIndex) const;
256
257 void minimizeCache(const QList<RawCubeChunk *> &justUsed,
258 const Buffer &justRequested) const;
259
260 void synchronousWrite(const Buffer &bufferToWrite);
261
262 void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const;
263
264 void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const;
265
266 void writeNullDataToDisk() const;
267
268 private:
270 QFile * m_dataFile;
271
277 BigInt m_startByte;
278
280 PixelType m_pixelType;
281
283 double m_base;
284
286 double m_multiplier;
287
289 ByteOrder m_byteOrder;
290
292 EndianSwapper * m_byteSwapper;
293
295 int m_numSamples;
296
298 int m_numLines;
299
301 int m_numBands;
302
304 QList<CubeCachingAlgorithm *> * m_cachingAlgorithms;
305
307 mutable QMap<int, RawCubeChunk *> * m_rawData;
308
310 mutable QMap<int, bool> * m_dataIsOnDiskMap;
311
312
314 int m_samplesInChunk;
315
317 int m_linesInChunk;
318
320 int m_bandsInChunk;
321
326 mutable QList<RawCubeChunk *> *m_lastProcessByLineChunks;
327
329 mutable QByteArray *m_nullChunkData;
330
332 QPair< QMutex *, QList<Buffer *> > *m_writeCache;
333
339 mutable QThreadPool *m_ioThreadPool;
340
345 mutable bool m_lastOperationWasWrite;
350 bool m_useOptimizedCubeWrite;
351
353 mutable volatile int m_idealFlushSize;
354
356 mutable int m_consecutiveOverflowCount;
357 };
358}
359
360#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:110
virtual void clearCache(bool blockForWriteCache=true) const
Free all cube chunks (cached cube data) from memory and write them to disk.
Definition CubeIoHandler.cpp:370
int bandCount() const
Definition CubeIoHandler.cpp:422
virtual ~CubeIoHandler()
Cleans up all allocated memory.
Definition CubeIoHandler.cpp:152
virtual void addCachingAlgorithm(CubeCachingAlgorithm *algorithm)
This will add the given caching algorithm to the list of attempted caching algorithms.
Definition CubeIoHandler.cpp:355
PixelType pixelType() const
Definition CubeIoHandler.cpp:540
QFile * getDataFile()
Definition CubeIoHandler.cpp:515
int getChunkCountInLineDimension() const
Definition CubeIoHandler.cpp:461
void setChunkSizes(int numSamples, int numLines, int numBands)
This should be called once from the child constructor.
Definition CubeIoHandler.cpp:574
int getLineCountInChunk() const
Definition CubeIoHandler.cpp:532
int getChunkCountInSampleDimension() const
Definition CubeIoHandler.cpp:470
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:452
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:442
BigInt getDataStartByte() const
Definition CubeIoHandler.cpp:504
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:549
int lineCount() const
Definition CubeIoHandler.cpp:524
virtual void read(Buffer &bufferToFill) const
Read cube data from disk into the buffer.
Definition CubeIoHandler.cpp:217
virtual void write(const Buffer &bufferToWrite)
Write buffer data into the cube data on disk.
Definition CubeIoHandler.cpp:325
virtual void updateLabels(Pvl &labels)=0
Function to update the labels with a Pvl object.
int getSampleCountInChunk() const
Definition CubeIoHandler.cpp:557
virtual BigInt getDataSize() const
Definition CubeIoHandler.cpp:412
int getBandCountInChunk() const
Definition CubeIoHandler.cpp:430
int getChunkIndex(const RawCubeChunk &) const
Given a chunk, what's its index in the file.
Definition CubeIoHandler.cpp:486
Byte swapper.
Definition EndianSwapper.h:38
ImageIoHandler(const QList< int > *virtualBandList)
Definition ImageIoHandler.cpp:12
Container for cube-like labels.
Definition Pvl.h:122
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:23
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:29
This is free and unencumbered software released into the public domain.
Definition CubeIoHandler.h:24