USGS

Isis 3.0 Object Programmers' Reference

Home

FilterCachingAlgorithm.cpp
Go to the documentation of this file.
1 
21 #include "FilterCachingAlgorithm.h"
22 
23 #include <algorithm>
24 #include <iostream>
25 
26 #include <QList>
27 
28 #include "Buffer.h"
29 #include "Distance.h"
30 #include "RawCubeChunk.h"
31 #include "Statistics.h"
32 
33 using std::max;
34 
35 namespace Isis {
45  m_chunksToKeep = NULL;
47 
48  while(m_chunksToKeep->size() < numParallelIOs)
50 
51  m_currentIo = 0;
52  }
53 
54 
59  if(m_chunksToKeep) {
60  delete m_chunksToKeep;
61  m_chunksToKeep = NULL;
62  }
63  }
64 
65 
77  QList<RawCubeChunk *> allocated, QList<RawCubeChunk *> justUsed,
78  const Buffer &justRequested) {
79  QList<RawCubeChunk *> chunksToToss;
80  CacheResult result(chunksToToss);
81 
82  // This read has different chunks than before...
83  if(!justUsed.size() ||
84  !(*m_chunksToKeep)[m_currentIo].size() ||
85  ((*m_chunksToKeep)[m_currentIo][0] != justUsed[0] &&
86  (*m_chunksToKeep)[m_currentIo] != justUsed)) {
87  (*m_chunksToKeep)[m_currentIo] = justUsed;
88 
89  // We don't know if Cube tossed any of the chunks, so we really need to
90  // look in the allocated list for things to toss. Let's work this by
91  // getting a list of things to keep and then freeing everything
92  // that is not in that list.
93  QListIterator<RawCubeChunk *> allocatedIterator(allocated);
94 
95  while(allocatedIterator.hasNext()) {
96  RawCubeChunk *chunk = allocatedIterator.next();
97 
98  bool found = false;
99 
100  foreach(QList<RawCubeChunk *> chunksForIo, *m_chunksToKeep) {
101  if(!found)
102  found = chunksForIo.indexOf(chunk) != -1;
103  }
104 
105  if(!found) {
106  chunksToToss.append(chunk);
107  }
108  }
109 
110  result = CacheResult(chunksToToss);
111  }
112 
113  m_currentIo ++;
114 
115  if(m_currentIo >= m_chunksToKeep->size())
116  m_currentIo = 0;
117 
118  return result;
119  }
120 }
121