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
20namespace Isis {
30 m_uniqueIOs = NULL;
31 m_uniqueIOs = new QQueue < QList <RawCubeChunk *> >;
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
53
54
66 QList <RawCubeChunk *> allocated, QList <RawCubeChunk *> justUsed,
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
Buffer for reading and writing cube data.
Definition Buffer.h:53
This stores the results of the caching algorithm.
Isis exception class.
Definition IException.h:91
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Adds specific functionality to C++ strings.
Definition IString.h:165
A section of raw data on the disk.
virtual CacheResult recommendChunksToFree(QList< RawCubeChunk * > allocated, QList< RawCubeChunk * > justUsed, const Buffer &justRequested)
Please see the class description for how this algorithm works.
UniqueIOCachingAlgorithm(int numUniqueIOs)
Construct a new UniqueIOCachingAlgorithm.
virtual ~UniqueIOCachingAlgorithm()
Frees the memory allocated by this caching algorithm.
QQueue< QList< RawCubeChunk * > > * m_uniqueIOs
This is the set of past unique IOs.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16