Isis Developer Reference
|
Handles converting buffers to and from disk. More...
#include <CubeIoHandler.h>
Public Member Functions | |
CubeIoHandler (QFile *dataFile, const QList< int > *virtualBandList, const Pvl &label, bool alreadyOnDisk) | |
Creates a new CubeIoHandler using a RegionalCachingAlgorithm. | |
virtual | ~CubeIoHandler () |
Cleans up all allocated memory. | |
void | read (Buffer &bufferToFill) const |
Read cube data from disk into the buffer. | |
void | write (const Buffer &bufferToWrite) |
Write buffer data into the cube data on disk. | |
void | addCachingAlgorithm (CubeCachingAlgorithm *algorithm) |
This will add the given caching algorithm to the list of attempted caching algorithms. | |
void | clearCache (bool blockForWriteCache=true) const |
Free all cube chunks (cached cube data) from memory and write them to disk. | |
BigInt | getDataSize () const |
void | setVirtualBands (const QList< int > *virtualBandList) |
This changes the virtual band list. | |
virtual void | updateLabels (Pvl &labels)=0 |
Function to update the labels with a Pvl object. | |
QMutex * | dataFileMutex () |
Get the mutex that this IO handler is using around I/Os on the given data file. | |
Protected Member Functions | |
int | bandCount () const |
int | getBandCountInChunk () const |
BigInt | getBytesPerChunk () const |
int | getChunkCountInBandDimension () const |
int | getChunkCountInLineDimension () const |
int | getChunkCountInSampleDimension () const |
int | getChunkIndex (const RawCubeChunk &) const |
Given a chunk, what's its index in the file. | |
BigInt | getDataStartByte () const |
QFile * | getDataFile () |
int | lineCount () const |
int | getLineCountInChunk () const |
PixelType | pixelType () const |
int | sampleCount () const |
int | getSampleCountInChunk () const |
void | setChunkSizes (int numSamples, int numLines, int numBands) |
This should be called once from the child constructor. | |
virtual void | readRaw (RawCubeChunk &chunkToFill)=0 |
This needs to populate the chunkToFill with unswapped raw bytes from the disk. | |
virtual void | writeRaw (const RawCubeChunk &chunkToWrite)=0 |
This needs to write the chunkToWrite directly to disk with no modifications to the data itself. | |
Handles converting buffers to and from disk.
This class handles converting buffers to and from disk. This class holds the cube chunks in memory and is capable of reading and writing them. It asks the caching algorithms to recommend cube chunks to not keep in memory. Children need to call setChunkSizes() in their constructor.
This class handles all of the virtual band conversions. This class also guarantees that unwritten cube data ends up read and written as NULLs. The default caching algorithm is a RegionalCachingAlgorithm.
Isis::CubeIoHandler::CubeIoHandler | ( | QFile * | dataFile, |
const QList< int > * | virtualBandList, | ||
const Pvl & | label, | ||
bool | alreadyOnDisk ) |
Creates a new CubeIoHandler using a RegionalCachingAlgorithm.
The chunk sizes must be set by a child in its constructor.
dataFile | The file that contains cube data. This should be a valid, opened QFile and may not be NULL. The file should have at least read permissions. |
virtualBandList | A list where the indices are the vbands and the values are the physical bands. The values are 1-based. This can be specified as NULL, in which case the vbands are the physical bands. The virtual band list is copied (the pointer provided isn't remembered). |
label | The label which contains the "Pixels" and "Core" groups. |
alreadyOnDisk | True if the cube exists; false ensures all NULLs are initialized into the file before this object is destructed. |
References _FILEINFO_, Isis::PvlContainer::findKeyword(), Isis::PvlObject::findObject(), Isis::PixelTypeEnumeration(), Isis::Preference::Preferences(), Isis::IException::Programmer, setVirtualBands(), and Isis::EndianSwapper::willSwap().
|
virtual |
Cleans up all allocated memory.
Child destructors must call clearCache() because we can no longer do IO by the time this destructor is called.
void Isis::CubeIoHandler::addCachingAlgorithm | ( | CubeCachingAlgorithm * | algorithm | ) |
This will add the given caching algorithm to the list of attempted caching algorithms.
The algorithms are tried in the opposite order that they were added - the first algorithm added is the last algorithm tried.
This method takes ownership of algorithm.
algorithm | The caching algorithm to add to the Cube for I/O |
Referenced by Isis::Cube::addCachingAlgorithm().
|
protected |
void Isis::CubeIoHandler::clearCache | ( | bool | blockForWriteCache = true | ) | const |
Free all cube chunks (cached cube data) from memory and write them to disk.
Child destructors need to call this method.
This method should only be called otherwise when lots of cubes are in memory and the many caches cause problems with system RAM limitations.
blockForWriteCache | This should be true unless this method is called from the write thread. |
Referenced by Isis::Cube::clearIoCache(), Isis::Cube::copy(), Isis::CubeBsqHandler::~CubeBsqHandler(), and Isis::CubeTileHandler::~CubeTileHandler().
QMutex * Isis::CubeIoHandler::dataFileMutex | ( | ) |
Get the mutex that this IO handler is using around I/Os on the given data file.
A lock should be acquired before doing any reads/writes on the data file externally.
Referenced by Isis::Cube::read(), and Isis::Cube::write().
|
protected |
Referenced by getChunkIndex(), and read().
|
protected |
References Isis::SizeOf().
Referenced by getDataSize().
|
protected |
Referenced by getDataSize().
|
protected |
Referenced by getChunkIndex(), getDataSize(), and read().
|
protected |
Referenced by getChunkIndex(), getDataSize(), and read().
|
protected |
Given a chunk, what's its index in the file.
Chunks are ordered from left to right, then top to bottom, then front to back (BSQ). The first chunk is at the top left of band 1 and is index 0, for example. In other words, this is going from the value of m_rawData to the key.
Chunks which sit outside of the cube entirely must not be passed into this method; the results will be wrong.
References getBandCountInChunk(), getChunkCountInLineDimension(), getChunkCountInSampleDimension(), getLineCountInChunk(), and getSampleCountInChunk().
|
protected |
Referenced by Isis::CubeBsqHandler::readRaw(), Isis::CubeTileHandler::readRaw(), Isis::CubeBsqHandler::writeRaw(), and Isis::CubeTileHandler::writeRaw().
BigInt Isis::CubeIoHandler::getDataSize | ( | ) | const |
References getBytesPerChunk(), getChunkCountInBandDimension(), getChunkCountInLineDimension(), and getChunkCountInSampleDimension().
Referenced by setChunkSizes(), and Isis::Cube::write().
|
protected |
Referenced by setChunkSizes().
|
protected |
Referenced by getChunkIndex(), read(), and Isis::CubeTileHandler::updateLabels().
|
protected |
Referenced by getChunkIndex(), read(), and Isis::CubeTileHandler::updateLabels().
|
protected |
Referenced by Isis::CubeBsqHandler::CubeBsqHandler(), and Isis::CubeTileHandler::CubeTileHandler().
|
protected |
Referenced by Isis::CubeBsqHandler::CubeBsqHandler(), and Isis::CubeTileHandler::CubeTileHandler().
void Isis::CubeIoHandler::read | ( | Buffer & | bufferToFill | ) | const |
Read cube data from disk into the buffer.
This is not const because it caches the read cube chunks from the disk.
bufferToFill | The buffer to populate with cube data. |
References getBandCountInChunk(), getChunkCountInLineDimension(), getChunkCountInSampleDimension(), getLineCountInChunk(), getSampleCountInChunk(), and Isis::Null.
Referenced by Isis::Cube::read().
|
protectedpure virtual |
This needs to populate the chunkToFill with unswapped raw bytes from the disk.
chunkToFill | The container that needs to be filled with cube data. |
Implemented in Isis::CubeBsqHandler, and Isis::CubeTileHandler.
|
protected |
Referenced by Isis::CubeBsqHandler::CubeBsqHandler(), and Isis::CubeTileHandler::CubeTileHandler().
|
protected |
This should be called once from the child constructor.
This determines the chunk sizes used for the cube and often should remain constant for a particular cube (BSQ, for example, doesn't need it to be constant but Tile does). These being large can cause excessive use of disk space that stores no cube data. These being large can also drastically increase the amount of RAM consumed.
numSamples | The chunk size in the sample dimension |
numLines | The chunk size in the line dimension |
numBands | The chunk size in the band dimension |
References _FILEINFO_, getDataSize(), getDataStartByte(), and Isis::IException::Programmer.
Referenced by Isis::CubeBsqHandler::CubeBsqHandler(), and Isis::CubeTileHandler::CubeTileHandler().
void Isis::CubeIoHandler::setVirtualBands | ( | const QList< int > * | virtualBandList | ) |
This changes the virtual band list.
virtualBandList | A list where the indices are the vbands and the values are the physical bands. The values are 1-based. This can be specified as NULL, in which case the vbands are the physical bands. The virtual band list is copied (the pointer provided isn't remembered). |
Referenced by CubeIoHandler(), and Isis::Cube::setVirtualBands().
|
pure virtual |
Function to update the labels with a Pvl object.
labels | Pvl object to update with |
Implemented in Isis::CubeTileHandler, and Isis::CubeBsqHandler.
Referenced by Isis::Cube::create().
void Isis::CubeIoHandler::write | ( | const Buffer & | bufferToWrite | ) |
Write buffer data into the cube data on disk.
This could do no IO if the cube chunks required are already in memory and our caching algorithms say to not free any of the cube chunks afterwards.
bufferToWrite | The buffer to get cube data from. |
Referenced by Isis::Cube::write().
|
protectedpure virtual |
This needs to write the chunkToWrite directly to disk with no modifications to the data itself.
chunkToWrite | The container that needs to be put on disk. |
Implemented in Isis::CubeBsqHandler, and Isis::CubeTileHandler.