USGS

Isis 3.0 Developer's Reference (API)

Home

Isis::CubeIoHandler Class Reference

Handles converting buffers to and from disk. More...

#include <CubeIoHandler.h>

Inherited by Isis::CubeBsqHandler, and Isis::CubeTileHandler.

List of all members.

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)
 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 ()
 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)
 Children should probably implement this method.

Protected Member Functions

int getBandCount () 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 getLineCount () const
int getLineCountInChunk () const
PixelType getPixelType () const
int getSampleCount () 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.

Detailed Description

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.

Author:
2011-??-?? Jai Rideout and Steven Lambright

Constructor & Destructor Documentation

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.

Parameters:
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_, core(), Isis::PvlObject::FindGroup(), Isis::PvlObject::FindKeyword(), Isis::PvlContainer::FindKeyword(), Isis::PvlObject::FindObject(), Isis::iException::Message(), Isis::PixelTypeEnumeration(), Isis::iException::Programmer, setVirtualBands(), Isis::iString::UpCase(), and Isis::EndianSwapper::willSwap().

Isis::CubeIoHandler::~CubeIoHandler (  )  [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.

References ASSERT.


Member Function Documentation

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.

Parameters:
algorithm The caching algorithm to add to the Cube for I/O

Referenced by Isis::Cube::addCachingAlgorithm().

void Isis::CubeIoHandler::clearCache (  ) 

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.

References writeRaw().

Referenced by Isis::Cube::clearIoCache(), Isis::CubeBsqHandler::~CubeBsqHandler(), and Isis::CubeTileHandler::~CubeTileHandler().

int Isis::CubeIoHandler::getBandCount (  )  const [protected]
Returns:
the number of physical bands in the cube.
int Isis::CubeIoHandler::getBandCountInChunk (  )  const [protected]
Returns:
the number of bands per chunk for this cube.

Referenced by getChunkIndex().

BigInt Isis::CubeIoHandler::getBytesPerChunk (  )  const [protected]
Returns:
the byte size of each chunk in the cube. Currently they must be constant size, but this is planned to be changed at some point in time.
Number of bytes in a cube chunk

References Isis::SizeOf().

Referenced by getDataSize().

int Isis::CubeIoHandler::getChunkCountInBandDimension (  )  const [protected]
Returns:
the total number of chunks in the band (Z) dimension. This is always enough to contain every band in the cube.

Referenced by getDataSize().

int Isis::CubeIoHandler::getChunkCountInLineDimension (  )  const [protected]
Returns:
the total number of chunks in the line (Y) dimension. This is always enough to contain every line in the cube.

Referenced by getChunkIndex(), and getDataSize().

int Isis::CubeIoHandler::getChunkCountInSampleDimension (  )  const [protected]
Returns:
the total number of chunks in the sample (X) dimension. This is always enough to contain every sample in the cube.

Referenced by getChunkIndex(), and getDataSize().

int Isis::CubeIoHandler::getChunkIndex ( const RawCubeChunk chunk  )  const [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.

Returns:
The chunk's index into the file

References getBandCountInChunk(), getChunkCountInLineDimension(), getChunkCountInSampleDimension(), getLineCountInChunk(), getSampleCountInChunk(), Isis::RawCubeChunk::getStartBand(), Isis::RawCubeChunk::getStartLine(), and Isis::RawCubeChunk::getStartSample().

QFile * Isis::CubeIoHandler::getDataFile (  )  [protected]
Returns:
the QFile containing cube data. This is what should be read from and written to.
The data file for I/O

Referenced by Isis::CubeTileHandler::readRaw(), Isis::CubeBsqHandler::readRaw(), Isis::CubeTileHandler::writeRaw(), and Isis::CubeBsqHandler::writeRaw().

BigInt Isis::CubeIoHandler::getDataSize (  )  const
Returns:
the number of bytes that the cube DNs will take up. This includes padding caused by the cube chunks not aligning with the cube dimensions.

References getBytesPerChunk(), getChunkCountInBandDimension(), getChunkCountInLineDimension(), and getChunkCountInSampleDimension().

Referenced by setChunkSizes(), and Isis::Cube::write().

BigInt Isis::CubeIoHandler::getDataStartByte (  )  const [protected]
Returns:
the byte offset to the beginning of the cube data.

Referenced by setChunkSizes().

int Isis::CubeIoHandler::getLineCount (  )  const [protected]
Returns:
the number of lines in the cube. This does not include lines created by the chunk overflowing the line dimension.

Referenced by Isis::CubeBsqHandler::CubeBsqHandler(), and Isis::CubeTileHandler::CubeTileHandler().

int Isis::CubeIoHandler::getLineCountInChunk (  )  const [protected]
Returns:
the number of lines in each chunk of the cube.

Referenced by getChunkIndex(), and Isis::CubeTileHandler::updateLabels().

PixelType Isis::CubeIoHandler::getPixelType (  )  const [protected]
Returns:
the physical cube DN format.

Referenced by Isis::CubeTileHandler::CubeTileHandler().

int Isis::CubeIoHandler::getSampleCount (  )  const [protected]
Returns:
the number of samples in the cube. This does not include samples created by the chunk overflowing the sample dimension.

Referenced by Isis::CubeBsqHandler::CubeBsqHandler(), Isis::CubeTileHandler::CubeTileHandler(), and write().

int Isis::CubeIoHandler::getSampleCountInChunk (  )  const [protected]
Returns:
the number of samples in each chunk of the cube.

Referenced by getChunkIndex(), and Isis::CubeTileHandler::updateLabels().

void Isis::CubeIoHandler::read ( Buffer bufferToFill  ) 

Read cube data from disk into the buffer.

This is not const because it caches the read cube chunks from the disk.

Parameters:
bufferToFill The buffer to populate with cube data.

References Isis::Buffer::Band(), Isis::Buffer::BandDimension(), Isis::Buffer::Line(), Isis::Buffer::LineDimension(), Isis::Null, Isis::Buffer::Sample(), Isis::Buffer::SampleDimension(), and Isis::Buffer::size().

Referenced by Isis::Cube::read().

virtual void Isis::CubeIoHandler::readRaw ( RawCubeChunk chunkToFill  )  [protected, pure virtual]

This needs to populate the chunkToFill with unswapped raw bytes from the disk.

See also:
CubeTileHandler::readRaw()
Parameters:
chunkToFill The container that needs to be filled with cube data.

Implemented in Isis::CubeBsqHandler, and Isis::CubeTileHandler.

void Isis::CubeIoHandler::setChunkSizes ( int  numSamples,
int  numLines,
int  numBands 
) [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.

Parameters:
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(), Isis::iException::Message(), 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.

Parameters:
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().

void Isis::CubeIoHandler::updateLabels ( Pvl labels  )  [virtual]

Children should probably implement this method.

This is called to allow the IO Handling algorithm to change the labels to include things like TileSamples/TileLines for example.

Parameters:
labels The PVL cube label to be updated to reflect information that the child IO handlers need to properly re-read the cube.

Reimplemented in Isis::CubeBsqHandler, and Isis::CubeTileHandler.

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.

Parameters:
bufferToWrite The buffer to get cube data from.

References Isis::Buffer::Band(), Isis::Buffer::BandDimension(), getSampleCount(), Isis::Buffer::Line(), Isis::Buffer::LineDimension(), Isis::Buffer::Sample(), and Isis::Buffer::SampleDimension().

Referenced by Isis::Cube::write().

virtual void Isis::CubeIoHandler::writeRaw ( const RawCubeChunk chunkToWrite  )  [protected, pure virtual]

This needs to write the chunkToWrite directly to disk with no modifications to the data itself.

See also:
CubeTileHandler::writeRaw()
Parameters:
chunkToWrite The container that needs to be put on disk.

Implemented in Isis::CubeBsqHandler, and Isis::CubeTileHandler.

Referenced by clearCache().


The documentation for this class was generated from the following files: