Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

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 "IEndian.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;
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 virtual void read(Buffer &bufferToFill) const;
116 virtual void write(const Buffer &bufferToWrite);
117
118 virtual void addCachingAlgorithm(CubeCachingAlgorithm *algorithm);
119 virtual void clearCache(bool blockForWriteCache = true) const;
120 virtual BigInt getDataSize() const;
126 virtual void updateLabels(Pvl &labels) = 0;
127
128 int bandCount() const;
129 int getBandCountInChunk() const;
130 BigInt getBytesPerChunk() const;
134 int getChunkIndex(const RawCubeChunk &) const;
135 BigInt getDataStartByte() const;
136 int lineCount() const;
137 int getLineCountInChunk() const;
138 PixelType pixelType() const;
139 int sampleCount() const;
140 int getSampleCountInChunk() const;
141
142 protected:
143 QFile * getDataFile();
144
145 void setChunkSizes(int numSamples, int numLines, int numBands);
146
155 virtual void readRaw(RawCubeChunk &chunkToFill) = 0;
156
164 virtual void writeRaw(const RawCubeChunk &chunkToWrite) = 0;
165
166 private:
183 class BufferToChunkWriter : public QRunnable {
184 public:
185 BufferToChunkWriter(CubeIoHandler * ioHandler,
186 QList<Buffer *> buffersToWrite);
187 ~BufferToChunkWriter();
188
189 void run();
190
191 private:
196 BufferToChunkWriter(const BufferToChunkWriter & other);
202 BufferToChunkWriter & operator=(const BufferToChunkWriter & rhs);
203
204 private:
206 CubeIoHandler * m_ioHandler;
208 QList<Buffer * > * m_buffersToWrite;
210 QElapsedTimer *m_timer;
211 };
212
213
219 CubeIoHandler(const CubeIoHandler &other);
220
228 CubeIoHandler &operator=(const CubeIoHandler &other);
229
230 void blockUntilThreadPoolEmpty() const;
231
232 static bool bufferLessThan(Buffer * const &lhs, Buffer * const &rhs);
233
234 QPair< QList<RawCubeChunk *>, QList<int> > findCubeChunks(int startSample, int numSamples,
235 int startLine, int numLines,
236 int startBand, int numBands) const;
237
238 void findIntersection(const RawCubeChunk &cube1,
239 const Buffer &cube2, int &startX, int &startY, int &startZ,
240 int &endX, int &endY, int &endZ) const;
241
242 void flushWriteCache(bool force = false) const;
243
244 void freeChunk(RawCubeChunk *chunkToFree) const;
245
246 RawCubeChunk *getChunk(int chunkIndex, bool allocateIfNecessary) const;
247
248 int getChunkCount() const;
249
250 void getChunkPlacement(int chunkIndex,
251 int &startSample, int &startLine, int &startBand,
252 int &endSample, int &endLine, int &endBand) const;
253
254 RawCubeChunk *getNullChunk(int chunkIndex) const;
255
256 void minimizeCache(const QList<RawCubeChunk *> &justUsed,
257 const Buffer &justRequested) const;
258
259 void synchronousWrite(const Buffer &bufferToWrite);
260
261 void writeIntoDouble(const RawCubeChunk &chunk, Buffer &output, int startIndex) const;
262
263 void writeIntoRaw(const Buffer &buffer, RawCubeChunk &output, int index) const;
264
265 void writeNullDataToDisk() const;
266
267 private:
269 QFile * m_dataFile;
270
276 BigInt m_startByte;
277
279 PixelType m_pixelType;
280
282 double m_base;
283
285 double m_multiplier;
286
288 ByteOrder m_byteOrder;
289
291 EndianSwapper * m_byteSwapper;
292
294 int m_numSamples;
295
297 int m_numLines;
298
300 int m_numBands;
301
303 QList<CubeCachingAlgorithm *> * m_cachingAlgorithms;
304
306 mutable QMap<int, RawCubeChunk *> * m_rawData;
307
309 mutable QMap<int, bool> * m_dataIsOnDiskMap;
310
311
313 int m_samplesInChunk;
314
316 int m_linesInChunk;
317
319 int m_bandsInChunk;
320
325 mutable QList<RawCubeChunk *> *m_lastProcessByLineChunks;
326
328 mutable QByteArray *m_nullChunkData;
329
331 QPair< QMutex *, QList<Buffer *> > *m_writeCache;
332
338 mutable QThreadPool *m_ioThreadPool;
339
344 mutable bool m_lastOperationWasWrite;
349 bool m_useOptimizedCubeWrite;
350
352 mutable volatile int m_idealFlushSize;
353
355 mutable int m_consecutiveOverflowCount;
356 };
357}
358
359#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
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
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
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16