File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
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 
18 class QFile;
19 class QMutex;
20 class QTime;
21 template <typename A> class QList;
22 template <typename A, typename B> class QMap;
23 template <typename A, typename B> struct QPair;
24 
25 namespace 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 
118  void addCachingAlgorithm(CubeCachingAlgorithm *algorithm);
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;
135  int getChunkCountInBandDimension() const;
136  int getChunkCountInLineDimension() const;
137  int getChunkCountInSampleDimension() 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  QTime *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
Isis::SizeOf
int SizeOf(Isis::PixelType pixelType)
Returns the number of bytes of the specified PixelType.
Definition: PixelType.h:46
Isis::RawCubeChunk
A section of raw data on the disk.
Definition: RawCubeChunk.h:27
Isis::RawCubeChunk::getStartBand
int getStartBand() const
Definition: RawCubeChunk.h:67
Displacement.h
Isis::LOW_INSTR_SAT2
const short LOW_INSTR_SAT2
Definition: SpecialPixel.h:156
Isis::CubeIoHandler::addCachingAlgorithm
void addCachingAlgorithm(CubeCachingAlgorithm *algorithm)
This will add the given caching algorithm to the list of attempted caching algorithms.
Definition: CubeIoHandler.cpp:368
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::Buffer::SampleDimension
int SampleDimension() const
Returns the number of samples in the shape buffer.
Definition: Buffer.h:70
Isis::VALID_MAX4
const float VALID_MAX4
Definition: SpecialPixel.h:149
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::IString::DownCase
IString DownCase()
Converts all upper case letters in the object IString into lower case characters.
Definition: IString.cpp:644
Isis::RawCubeChunk::getStartLine
int getStartLine() const
Definition: RawCubeChunk.h:60
QList< int >
Isis::LOW_INSTR_SATU2
const unsigned short LOW_INSTR_SATU2
Definition: SpecialPixel.h:165
Isis::CubeIoHandler::sampleCount
int sampleCount() const
Definition: CubeIoHandler.cpp:596
Isis::CubeIoHandler::getBandCountInChunk
int getBandCountInChunk() const
Definition: CubeIoHandler.cpp:474
Isis::HIGH_REPR_SATU2
const unsigned short HIGH_REPR_SATU2
Definition: SpecialPixel.h:167
Isis::LOW_REPR_SAT4
const float LOW_REPR_SAT4
Definition: SpecialPixel.h:137
Isis::CubeIoHandler::updateLabels
virtual void updateLabels(Pvl &labels)=0
Function to update the labels with a Pvl object.
Isis::CubeIoHandler::pixelType
PixelType pixelType() const
Definition: CubeIoHandler.cpp:587
SpecialPixel.h
Isis::LOW_INSTR_SAT4
const float LOW_INSTR_SAT4
Definition: SpecialPixel.h:140
Isis::HIGH_REPR_SATUI4
const unsigned int HIGH_REPR_SATUI4
Definition: SpecialPixel.h:176
PvlGroup.h
Isis::CubeIoHandler::getBytesPerChunk
BigInt getBytesPerChunk() const
Definition: CubeIoHandler.cpp:486
Isis::VALID_MIN1
const unsigned char VALID_MIN1
Definition: SpecialPixel.h:181
Isis::CubeIoHandler::setVirtualBands
void setVirtualBands(const QList< int > *virtualBandList)
This changes the virtual band list.
Definition: CubeIoHandler.cpp:442
Isis::UnsignedWord
@ UnsignedWord
Definition: PixelType.h:31
Isis::RegionalCachingAlgorithm
This algorithm recommends chunks to be freed that are not within the last IO.
Definition: RegionalCachingAlgorithm.h:26
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::NULL1
const unsigned char NULL1
Definition: SpecialPixel.h:182
Isis::CubeIoHandler::getDataFile
QFile * getDataFile()
Definition: CubeIoHandler.cpp:562
RawCubeChunk.h
Isis::SignedWord
@ SignedWord
Definition: PixelType.h:32
Isis::LOW_INSTR_SAT1
const unsigned char LOW_INSTR_SAT1
Definition: SpecialPixel.h:184
Isis::LOW_REPR_SATU2
const unsigned short LOW_REPR_SATU2
Definition: SpecialPixel.h:164
Isis::HIGH_REPR_SAT8
const double HIGH_REPR_SAT8
Definition: SpecialPixel.h:116
Isis::CubeIoHandler::getSampleCountInChunk
int getSampleCountInChunk() const
Definition: CubeIoHandler.cpp:604
Preference.h
IString.h
Isis::ByteOrder
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:42
Isis::Buffer
Buffer for reading and writing cube data.
Definition: Buffer.h:53
Isis::CubeIoHandler::CubeIoHandler
CubeIoHandler(QFile *dataFile, const QList< int > *virtualBandList, const Pvl &label, bool alreadyOnDisk)
Creates a new CubeIoHandler using a RegionalCachingAlgorithm.
Definition: CubeIoHandler.cpp:63
Endian.h
Isis::VALID_MAX2
const short VALID_MAX2
Definition: SpecialPixel.h:159
Isis::LOW_REPR_SAT1
const unsigned char LOW_REPR_SAT1
Definition: SpecialPixel.h:183
Isis::CubeIoHandler::lineCount
int lineCount() const
Definition: CubeIoHandler.cpp:571
Isis::VALID_MIN2
const short VALID_MIN2
Definition: SpecialPixel.h:153
PixelType.h
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Pvl.h
Isis::CubeIoHandler::getDataStartByte
BigInt getDataStartByte() const
Definition: CubeIoHandler.cpp:551
_FILEINFO_
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:24
Isis::CubeIoHandler::~CubeIoHandler
virtual ~CubeIoHandler()
Cleans up all allocated memory.
Definition: CubeIoHandler.cpp:157
Isis::HIGH_REPR_SAT4
const float HIGH_REPR_SAT4
Definition: SpecialPixel.h:146
Isis::CubeIoHandler::getChunkCountInBandDimension
int getChunkCountInBandDimension() const
Definition: CubeIoHandler.cpp:496
Isis::VALID_MIN8
const double VALID_MIN8
Definition: SpecialPixel.h:86
EndianSwapper.h
Isis::HIGH_INSTR_SAT1
const unsigned char HIGH_INSTR_SAT1
Definition: SpecialPixel.h:185
Isis::CubeIoHandler::dataFileMutex
QMutex * dataFileMutex()
Get the mutex that this IO handler is using around I/Os on the given data file.
Definition: CubeIoHandler.cpp:459
Isis::CubeCachingAlgorithm
This is the parent of the caching algorithms.
Definition: CubeCachingAlgorithm.h:31
Isis::HIGH_REPR_SAT2
const short HIGH_REPR_SAT2
Definition: SpecialPixel.h:158
Isis::Buffer::LineDimension
int LineDimension() const
Returns the number of lines in the shape buffer.
Definition: Buffer.h:79
Isis::CubeIoHandler
Handles converting buffers to and from disk.
Definition: CubeIoHandler.h:109
Isis::NULL8
const double NULL8
Definition: SpecialPixel.h:94
Isis::BigInt
long long int BigInt
Big int.
Definition: Constants.h:49
Isis::PvlObject::findObject
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:274
CubeCachingAlgorithm.h
Isis::HIGH_INSTR_SAT2
const short HIGH_INSTR_SAT2
Definition: SpecialPixel.h:157
Isis::HIGH_INSTR_SAT8
const double HIGH_INSTR_SAT8
Definition: SpecialPixel.h:110
Area3D.h
Isis::CubeIoHandler::getChunkIndex
int getChunkIndex(const RawCubeChunk &) const
Given a chunk, what's its index in the file.
Definition: CubeIoHandler.cpp:530
Isis::HIGH_INSTR_SAT4
const float HIGH_INSTR_SAT4
Definition: SpecialPixel.h:143
Isis::CubeIoHandler::writeRaw
virtual void writeRaw(const RawCubeChunk &chunkToWrite)=0
This needs to write the chunkToWrite directly to disk with no modifications to the data itself.
Isis::NULL2
const short NULL2
Definition: SpecialPixel.h:154
Isis::IException
Isis exception class.
Definition: IException.h:91
ASSERT
#define ASSERT(x)
Definition: IsisDebug.h:134
Isis::RawCubeChunk::getStartSample
int getStartSample() const
Definition: RawCubeChunk.h:53
Isis::NULLU2
const unsigned short NULLU2
Definition: SpecialPixel.h:163
RegionalCachingAlgorithm.h
Isis::VALID_MINUI4
const unsigned int VALID_MINUI4
Definition: SpecialPixel.h:171
round
#define round(x)
This is free and unencumbered software released into the public domain.
Definition: ViewportBuffer.cpp:29
Isis::Null
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:95
Isis::VALID_MAXU2
const unsigned short VALID_MAXU2
Definition: SpecialPixel.h:168
Isis::CubeIoHandler::bandCount
int bandCount() const
Definition: CubeIoHandler.cpp:466
Isis::CubeIoHandler::getChunkCountInSampleDimension
int getChunkCountInSampleDimension() const
Definition: CubeIoHandler.cpp:514
Isis::VALID_MAXUI4
const unsigned int VALID_MAXUI4
Definition: SpecialPixel.h:177
Isis::HIGH_INSTR_SATUI4
const unsigned int HIGH_INSTR_SATUI4
Definition: SpecialPixel.h:175
Isis::Buffer::Band
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
Definition: Buffer.cpp:162
Brick.h
Isis::PixelType
PixelType
Enumerations for Isis Pixel Types.
Definition: PixelType.h:27
Isis::LOW_INSTR_SATUI4
const unsigned int LOW_INSTR_SATUI4
Definition: SpecialPixel.h:174
Isis::CubeIoHandler::read
void read(Buffer &bufferToFill) const
Read cube data from disk into the buffer.
Definition: CubeIoHandler.cpp:230
Statistics.h
Isis::UnsignedInteger
@ UnsignedInteger
Definition: PixelType.h:33
IException.h
std
Namespace for the standard library.
Isis::LOW_REPR_SATUI4
const unsigned int LOW_REPR_SATUI4
Definition: SpecialPixel.h:173
Isis::NULL4
const float NULL4
Definition: SpecialPixel.h:134
QPair
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:23
Isis::VALID_MIN4
const float VALID_MIN4
Definition: SpecialPixel.h:130
QRunnable
Isis::EndianSwapper
Byte swapper.
Definition: EndianSwapper.h:38
Isis::HIGH_INSTR_SATU2
const unsigned short HIGH_INSTR_SATU2
Definition: SpecialPixel.h:166
Isis::CubeIoHandler::clearCache
void clearCache(bool blockForWriteCache=true) const
Free all cube chunks (cached cube data) from memory and write them to disk.
Definition: CubeIoHandler.cpp:383
Isis::VALID_MINU2
const unsigned short VALID_MINU2
Definition: SpecialPixel.h:162
Isis::PixelTypeEnumeration
Isis::PixelType PixelTypeEnumeration(const QString &type)
Returns PixelType enumeration given a string.
Definition: PixelType.h:89
PvlObject.h
Isis::CubeIoHandler::write
void write(const Buffer &bufferToWrite)
Write buffer data into the cube data on disk.
Definition: CubeIoHandler.cpp:338
QMap
This is free and unencumbered software released into the public domain.
Definition: CubeIoHandler.h:22
Isis::VALID_MAX1
const unsigned char VALID_MAX1
Definition: SpecialPixel.h:187
Isis::Buffer::size
int size() const
Returns the total number of pixels in the shape buffer.
Definition: Buffer.h:97
Isis::CubeIoHandler::getChunkCountInLineDimension
int getChunkCountInLineDimension() const
Definition: CubeIoHandler.cpp:505
Isis::PvlObject::findKeyword
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
Definition: PvlObject.cpp:177
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis::PvlContainer::findKeyword
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Definition: PvlContainer.cpp:62
Constants.h
Isis::LOW_REPR_SAT8
const double LOW_REPR_SAT8
Definition: SpecialPixel.h:98
Distance.h
Isis::CubeIoHandler::setChunkSizes
void setChunkSizes(int numSamples, int numLines, int numBands)
This should be called once from the child constructor.
Definition: CubeIoHandler.cpp:621
Isis::HIGH_REPR_SAT1
const unsigned char HIGH_REPR_SAT1
Definition: SpecialPixel.h:186
CubeIoHandler.h
Isis::Buffer::Sample
int Sample(const int index=0) const
Returns the sample position associated with a shape buffer index.
Definition: Buffer.cpp:127
IsisDebug.h
Isis::LOW_INSTR_SAT8
const double LOW_INSTR_SAT8
Definition: SpecialPixel.h:104
Isis::UnsignedByte
@ UnsignedByte
Definition: PixelType.h:29
Isis::CubeIoHandler::readRaw
virtual void readRaw(RawCubeChunk &chunkToFill)=0
This needs to populate the chunkToFill with unswapped raw bytes from the disk.
Isis::NULLUI4
const unsigned int NULLUI4
Definition: SpecialPixel.h:172
Isis::LOW_REPR_SAT2
const short LOW_REPR_SAT2
Definition: SpecialPixel.h:155
Isis::Buffer::Line
int Line(const int index=0) const
Returns the line position associated with a shape buffer index.
Definition: Buffer.cpp:145
Isis::CubeIoHandler::getLineCountInChunk
int getLineCountInChunk() const
Definition: CubeIoHandler.cpp:579
Isis::Buffer::BandDimension
int BandDimension() const
Returns the number of bands in the shape buffer.
Definition: Buffer.h:88
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::CubeIoHandler::getDataSize
BigInt getDataSize() const
Definition: CubeIoHandler.cpp:425
Isis::Real
@ Real
Definition: PixelType.h:35

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/13/2023 15:10:55