Isis 3 Programmer Reference
UniqueIOCachingAlgorithm.cpp
Go to the documentation of this file.
1 
22 
23 #include <algorithm>
24 #include <iostream>
25 
26 #include <QList>
27 #include <QQueue>
28 
29 #include "IException.h"
30 #include "IString.h"
31 #include "RawCubeChunk.h"
32 
33 namespace Isis {
43  m_uniqueIOs = NULL;
45 
46  if (numUniqueIOs <= 0) {
47  IString msg = "At least one unique IO must be used when using the unique "
48  "IO cube caching algorithm";
50  }
51 
52  while (m_uniqueIOs->size() < numUniqueIOs)
53  m_uniqueIOs->enqueue( QList<RawCubeChunk *>() );
54  }
55 
56 
61  if (m_uniqueIOs) {
62  delete m_uniqueIOs;
63  m_uniqueIOs = NULL;
64  }
65  }
66 
67 
80  const Buffer &justRequested) {
81  QList <RawCubeChunk *> chunksToToss;
82  CacheResult result(chunksToToss);
83 
84  // This read has different chunks than before...
85  if (justUsed.size()) {
86  // If any of our unique reads are not yet populated, then populate them
87  // with our current IO.
88  bool foundAHome = false;
89 
90  for (int uniqueIONum = 0;
91  !foundAHome && uniqueIONum < m_uniqueIOs->size();
92  uniqueIONum++) {
93  QList <RawCubeChunk *> &uniqueIO = (*m_uniqueIOs)[uniqueIONum];
94 
95  if (uniqueIO.empty()) {
96  foundAHome = true;
97  uniqueIO = justUsed;
98  }
99  else if (uniqueIO == justUsed) {
100  foundAHome = true;
101  m_uniqueIOs->enqueue(m_uniqueIOs->takeAt(uniqueIONum));
102  }
103  }
104 
105  if (!foundAHome) {
106  m_uniqueIOs->enqueue(justUsed);
107  m_uniqueIOs->dequeue();
108  }
109 
110  // We don't know if Cube tossed any of the chunks, so we really need to
111  // look in the allocated list for things to toss.
112  QListIterator <RawCubeChunk *> allocatedIterator(allocated);
113 
114  while (allocatedIterator.hasNext()) {
115  RawCubeChunk *chunk = allocatedIterator.next();
116 
117  bool found = false;
118 
119  foreach (QList <RawCubeChunk *> chunksForIo, *m_uniqueIOs) {
120  if (!found)
121  found = chunksForIo.indexOf(chunk) != -1;
122  }
123 
124  if (!found) {
125  chunksToToss.append(chunk);
126  }
127  }
128 
129  result = CacheResult(chunksToToss);
130  }
131 
132  return result;
133  }
134 }
135 
Buffer for reading and writing cube data.
Definition: Buffer.h:69
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
virtual CacheResult recommendChunksToFree(QList< RawCubeChunk *> allocated, QList< RawCubeChunk *> justUsed, const Buffer &justRequested)
Please see the class description for how this algorithm works.
virtual ~UniqueIOCachingAlgorithm()
Frees the memory allocated by this caching algorithm.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A section of raw data on the disk.
Definition: RawCubeChunk.h:42
UniqueIOCachingAlgorithm(int numUniqueIOs)
Construct a new UniqueIOCachingAlgorithm.
Isis exception class.
Definition: IException.h:107
Adds specific functionality to C++ strings.
Definition: IString.h:181
This stores the results of the caching algorithm.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
QQueue< QList< RawCubeChunk * > > * m_uniqueIOs
This is the set of past unique IOs.