Isis 3 Programmer Reference
UniqueIOCachingAlgorithm.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #include "UniqueIOCachingAlgorithm.h"
9 
10 #include <algorithm>
11 #include <iostream>
12 
13 #include <QList>
14 #include <QQueue>
15 
16 #include "IException.h"
17 #include "IString.h"
18 #include "RawCubeChunk.h"
19 
20 namespace Isis {
30  m_uniqueIOs = NULL;
32 
33  if (numUniqueIOs <= 0) {
34  IString msg = "At least one unique IO must be used when using the unique "
35  "IO cube caching algorithm";
36  throw IException(IException::Programmer, msg, _FILEINFO_);
37  }
38 
39  while (m_uniqueIOs->size() < numUniqueIOs)
40  m_uniqueIOs->enqueue( QList<RawCubeChunk *>() );
41  }
42 
43 
48  if (m_uniqueIOs) {
49  delete m_uniqueIOs;
50  m_uniqueIOs = NULL;
51  }
52  }
53 
54 
67  const Buffer &justRequested) {
68  QList <RawCubeChunk *> chunksToToss;
69  CacheResult result(chunksToToss);
70 
71  // This read has different chunks than before...
72  if (justUsed.size()) {
73  // If any of our unique reads are not yet populated, then populate them
74  // with our current IO.
75  bool foundAHome = false;
76 
77  for (int uniqueIONum = 0;
78  !foundAHome && uniqueIONum < m_uniqueIOs->size();
79  uniqueIONum++) {
80  QList <RawCubeChunk *> &uniqueIO = (*m_uniqueIOs)[uniqueIONum];
81 
82  if (uniqueIO.empty()) {
83  foundAHome = true;
84  uniqueIO = justUsed;
85  }
86  else if (uniqueIO == justUsed) {
87  foundAHome = true;
88  m_uniqueIOs->enqueue(m_uniqueIOs->takeAt(uniqueIONum));
89  }
90  }
91 
92  if (!foundAHome) {
93  m_uniqueIOs->enqueue(justUsed);
94  m_uniqueIOs->dequeue();
95  }
96 
97  // We don't know if Cube tossed any of the chunks, so we really need to
98  // look in the allocated list for things to toss.
99  QListIterator <RawCubeChunk *> allocatedIterator(allocated);
100 
101  while (allocatedIterator.hasNext()) {
102  RawCubeChunk *chunk = allocatedIterator.next();
103 
104  bool found = false;
105 
106  foreach (QList <RawCubeChunk *> chunksForIo, *m_uniqueIOs) {
107  if (!found)
108  found = chunksForIo.indexOf(chunk) != -1;
109  }
110 
111  if (!found) {
112  chunksToToss.append(chunk);
113  }
114  }
115 
116  result = CacheResult(chunksToToss);
117  }
118 
119  return result;
120  }
121 }
122 
Isis::RawCubeChunk
A section of raw data on the disk.
Definition: RawCubeChunk.h:27
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::UniqueIOCachingAlgorithm::~UniqueIOCachingAlgorithm
virtual ~UniqueIOCachingAlgorithm()
Frees the memory allocated by this caching algorithm.
Definition: UniqueIOCachingAlgorithm.cpp:47
Isis::CubeCachingAlgorithm::CacheResult
This stores the results of the caching algorithm.
Definition: CubeCachingAlgorithm.h:45
Isis::Buffer
Buffer for reading and writing cube data.
Definition: Buffer.h:53
Isis::UniqueIOCachingAlgorithm::m_uniqueIOs
QQueue< QList< RawCubeChunk * > > * m_uniqueIOs
This is the set of past unique IOs.
Definition: UniqueIOCachingAlgorithm.h:44
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::UniqueIOCachingAlgorithm::UniqueIOCachingAlgorithm
UniqueIOCachingAlgorithm(int numUniqueIOs)
Construct a new UniqueIOCachingAlgorithm.
Definition: UniqueIOCachingAlgorithm.cpp:29
Isis::IException::Programmer
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:146
QQueue
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:14
Isis::UniqueIOCachingAlgorithm::recommendChunksToFree
virtual CacheResult recommendChunksToFree(QList< RawCubeChunk * > allocated, QList< RawCubeChunk * > justUsed, const Buffer &justRequested)
Please see the class description for how this algorithm works.
Definition: UniqueIOCachingAlgorithm.cpp:65
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16