2 #include "CubeDataThread.h" 4 #include <QApplication> 9 #include <QReadWriteLock> 66 while (!isFinished()) {
67 QThread::yieldCurrentThread();
73 delete (*p_managedData)[i].first;
74 delete (*p_managedData)[i].second;
120 bool mustOpenReadWrite) {
127 if (!mustOpenReadWrite) {
141 newEntry.first =
true;
142 newEntry.second = newCube;
169 newEntry.first =
false;
170 newEntry.second = cube;
194 QString msg =
"CubeDataThread::RemoveCube failed because cube ID [";
195 msg += QString::number(cubeId);
196 msg +=
"] not found";
202 QString msg =
"CubeDataThread::RemoveCube failed cube ID [";
203 msg += QString::number(cubeId);
204 msg +=
"] has requested Bricks";
210 delete i.value().second;
211 i.value().second = NULL;
253 int band,
void *caller,
bool sharedLock) {
255 Brick *requestedBrick = NULL;
259 - ss + 1, el - sl + 1, 1);
266 bool exactMatch =
false;
267 int index =
OverlapIndex(requestedBrick, cubeId, instance, exactMatch);
270 while (index != -1) {
277 (*p_managedData)[index].first->unlock();
283 (*p_managedData)[index].first->unlock();
298 index =
OverlapIndex(requestedBrick, cubeId, instance, exactMatch);
303 if (exactIndex == -1) {
310 managedDataEntry.first =
new QReadWriteLock();
314 managedDataEntry.second = requestedBrick;
324 if (el - sl + 1 != (*
p_managedData)[exactIndex].second->LineDimension())
347 while (i.hasNext()) {
349 if (i.value().second == cubeToFind)
353 "Cube does not exist in this CubeDataThread",
_FILEINFO_);
372 while (!lockObject->tryLockForRead()) {
377 QThread::yieldCurrentThread();
380 qApp->sendPostedEvents(
this, 0);
387 while (!lockObject->tryLockForWrite()) {
392 QThread::yieldCurrentThread();
395 qApp->sendPostedEvents(
this, 0);
422 int endSample,
int endLine,
int band,
428 msg +=
"] is not a valid cube ID";
432 GetCubeData(cubeId, startSample, startLine, endSample, endLine, band,
457 int startLine,
int endSample,
int endLine,
458 int band,
void *caller) {
462 msg +=
"] is not a valid cube ID";
466 GetCubeData(cubeId, startSample, startLine, endSample, endLine, band,
484 int instanceNum,
bool &exact) {
488 int startSample = overlapping->
Sample(0);
489 int endSample = overlapping->
Sample(overlapping->
size() - 1);
490 int startLine = overlapping->
Line(0);
491 int endLine = overlapping->
Line(overlapping->
size() - 1);
492 int startBand = overlapping->
Band(0);
493 int endBand = overlapping->
Band(overlapping->
size() - 1);
497 for (
int knownBrick = 0; knownBrick <
p_managedData->size(); knownBrick++) {
498 int sourceCube = (*p_managedDataSources)[knownBrick];
501 if (sourceCube != cubeId)
505 (*p_managedData)[knownBrick];
507 Brick &brick = *managedBrick.second;
511 int compareSampStart = brick.
Sample(0);
512 int compareSampEnd = brick.
Sample(brick.
size() - 1);
513 int compareLineStart = brick.
Line(0);
514 int compareLineEnd = brick.
Line(brick.
size() - 1);
515 int compareBandStart = brick.
Band(0);
516 int compareBandEnd = brick.
Band(brick.
size() - 1);
518 bool overlap =
false;
521 if (compareSampStart >= startSample && compareSampStart <= endSample) {
526 if (compareSampEnd >= startSample && compareSampEnd <= endSample) {
531 if (compareLineStart >= startLine && compareLineStart <= endLine) {
536 if (compareLineEnd >= startLine && compareLineEnd <= endLine) {
541 if (compareBandStart >= startBand && compareBandStart <= endBand) {
546 if (compareBandEnd >= startBand && compareBandEnd <= endBand) {
551 if (compareSampStart == startSample && compareSampEnd == endSample
552 && compareLineStart == startLine && compareLineEnd == endLine
553 && compareBandStart == startBand && compareBandEnd == endBand) {
562 if (instanceNum < 0) {
582 ASSERT(brickDone != NULL);
584 bool exactMatch =
false;
585 bool writeLock =
false;
587 int index =
OverlapIndex(brickDone, cubeId, instance, exactMatch);
589 while (index != -1) {
593 index =
OverlapIndex(brickDone, cubeId, instance, exactMatch);
601 IString msg =
"Overlapping data had write locks";
610 IString msg =
"Overlapping data had write locks";
615 (*p_managedData)[index].first->unlock();
622 Brick cpy(*brickDone);
627 (*p_managedData)[index].first->unlock();
654 (*p_managedData)[index].first->unlock();
657 (*p_managedData)[index].first->unlock();
665 index =
OverlapIndex(brickDone, cubeId, instance, exactMatch);
682 if (!(*
p_managedData)[brickIndex].first->tryLockForWrite()) {
684 "CubeDataThread::FreeBrick called on a locked brick",
688 (*p_managedData)[brickIndex].first->unlock();
695 delete (*p_managedData)[brickIndex].first;
696 delete (*p_managedData)[brickIndex].second;
704 delete (*p_managedData)[i].first;
705 delete (*p_managedData)[i].second;
733 return numBricksInMemory;
747 "Invalid Cube ID [" +
IString(cubeId) +
"]",
764 "Invalid Cube ID [" +
IString(cubeId) +
"]",
QMutex * p_threadSafeMutex
This locks the member variable p_managedCubes and p_managedData itself.
void GetCubeData(int cubeId, int ss, int sl, int es, int el, int band, void *caller, bool sharedLock)
This helper method reads in cube data and handles the locking of similar bricks appropriately.
void RemoveCube(int cubeId)
Removes a cube from this lock manager.
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
int FindCubeId(const Cube *) const
Given a Cube pointer, return the cube ID associated with it.
File name manipulation and expansion.
void DoneWithData(int, const Isis::Brick *)
When done processing with a brick (reading or writing) this slot needs to be signalled to free locks ...
int p_numChangeListeners
This is the number of shaded locks to put on a brick when changes made.
unsigned int p_currentId
This is the unique id counter for cubes.
Buffer for containing a three dimensional section of an image.
void SetBasePosition(const int start_sample, const int start_line, const int start_band)
This method is used to set the base position of the shape buffer.
QList< QPair< QReadWriteLock *, Brick * > > * p_managedData
This is a list of bricks in memory and their locks.
QList< int > * p_managedDataSources
This is the associated cube ID with each brick.
This error is for when a programmer made an API call that was illegal.
int size() const
Returns the total number of pixels in the shape buffer.
void ReadReady(void *requester, int cubeId, const Isis::Brick *data)
This signal will be emitted when ReadCube has finished processing.
void AcquireLock(QReadWriteLock *lockObject, bool readLock)
This method is exclusively used to acquire locks.
int Sample(const int index=0) const
Returns the sample position associated with a shape buffer index.
unsigned int p_currentLocksWaiting
Number of locks being attempted that re-entered the event loop.
virtual ~CubeDataThread()
This class is a self-contained thread, so normally it would be bad to simply delete it...
#define _FILEINFO_
Macro for the filename and line number.
int AddCube(const FileName &fileName, bool mustOpenReadWrite=false)
This method is designed to be callable from any thread before data is requested, though no known side...
int Line(const int index=0) const
Returns the line position associated with a shape buffer index.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
void open(const QString &cfile, QString access="r")
This method will open an isis cube for reading or reading/writing.
UniversalGroundMap * GetUniversalGroundMap(int cubeId) const
This returns a new Universal Ground Map given a Cube ID.
void AddChangeListener()
You must call this method after connecting to the BrickChanged signal, otherwise you are not guarante...
void ReadWriteReady(void *requester, int cubeId, Isis::Brick *data)
This signal will be emitted when ReadWriteCube has finished processing.
QMap< int, QPair< bool, Cube *> > * p_managedCubes
This is a list of the opened cubes.
void ReadCube(int cubeId, int startSample, int startLine, int endSample, int endLine, int band, void *caller)
This slot should be connected to and upon receiving a signal it will begin the necessary cube I/O to ...
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
void RemoveChangeListener()
You must call this method after disconnecting from the BrickChanged signal, otherwise bricks cannot b...
void BrickChanged(int cubeId, const Isis::Brick *data)
DO NOT CONNECT TO THIS SIGNAL WITHOUT CALLING AddChangeListener().
void ReadWriteCube(int cubeId, int startSample, int startLine, int endSample, int endLine, int band, void *caller)
This slot should be connected to and upon receiving a signal it will begin the necessary cube I/O to ...
int OverlapIndex(const Brick *initial, int cubeId, int instanceNum, bool &exact)
This is a searching method used to identify overlapping data already in memory.
int BricksInMemory()
This is a helper method for both testing/debugging and general information that provides the current ...
bool p_stopping
This is set to help the shutdown process when deleted.
CubeDataThread()
This constructs a CubeDataThread().
const Cube * GetCube(int cubeId) const
This returns a constant pointer to a Cube at the given Cube ID.
IO Handler for Isis Cubes.
bool FreeBrick(int brickIndex)
This is used internally to delete bricks when possible.