|
Isis 3.0 Object Programmers' Reference |
Home |
00001 00021 #include "FilterCachingAlgorithm.h" 00022 00023 #include <algorithm> 00024 #include <iostream> 00025 00026 #include <QList> 00027 00028 #include "Buffer.h" 00029 #include "Distance.h" 00030 #include "RawCubeChunk.h" 00031 #include "Statistics.h" 00032 00033 using std::max; 00034 00035 namespace Isis { 00044 FilterCachingAlgorithm::FilterCachingAlgorithm(int numParallelIOs) { 00045 m_chunksToKeep = NULL; 00046 m_chunksToKeep = new QList< QList< RawCubeChunk * > >; 00047 00048 while(m_chunksToKeep->size() < numParallelIOs) 00049 m_chunksToKeep->append( QList<RawCubeChunk *>() ); 00050 00051 m_currentIo = 0; 00052 } 00053 00054 00058 FilterCachingAlgorithm::~FilterCachingAlgorithm() { 00059 if(m_chunksToKeep) { 00060 delete m_chunksToKeep; 00061 m_chunksToKeep = NULL; 00062 } 00063 } 00064 00065 00075 CubeCachingAlgorithm::CacheResult 00076 FilterCachingAlgorithm::recommendChunksToFree( 00077 QList<RawCubeChunk *> allocated, QList<RawCubeChunk *> justUsed, 00078 const Buffer &justRequested) { 00079 QList<RawCubeChunk *> chunksToToss; 00080 CacheResult result(chunksToToss); 00081 00082 // This read has different chunks than before... 00083 if(!justUsed.size() || 00084 !(*m_chunksToKeep)[m_currentIo].size() || 00085 ((*m_chunksToKeep)[m_currentIo][0] != justUsed[0] && 00086 (*m_chunksToKeep)[m_currentIo] != justUsed)) { 00087 (*m_chunksToKeep)[m_currentIo] = justUsed; 00088 00089 // We don't know if Cube tossed any of the chunks, so we really need to 00090 // look in the allocated list for things to toss. Let's work this by 00091 // getting a list of things to keep and then freeing everything 00092 // that is not in that list. 00093 QListIterator<RawCubeChunk *> allocatedIterator(allocated); 00094 00095 while(allocatedIterator.hasNext()) { 00096 RawCubeChunk *chunk = allocatedIterator.next(); 00097 00098 bool found = false; 00099 00100 foreach(QList<RawCubeChunk *> chunksForIo, *m_chunksToKeep) { 00101 if(!found) 00102 found = chunksForIo.indexOf(chunk) != -1; 00103 } 00104 00105 if(!found) { 00106 chunksToToss.append(chunk); 00107 } 00108 } 00109 00110 result = CacheResult(chunksToToss); 00111 } 00112 00113 m_currentIo ++; 00114 00115 if(m_currentIo >= m_chunksToKeep->size()) 00116 m_currentIo = 0; 00117 00118 return result; 00119 } 00120 } 00121