Isis 3 Programmer Reference
RegionalCachingAlgorithm.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#include "RegionalCachingAlgorithm.h"
9
10#include <algorithm>
11#include <iostream>
12
13#include <QList>
14
15#include "Buffer.h"
16#include "Distance.h"
17#include "RawCubeChunk.h"
18#include "Statistics.h"
19
20using std::max;
21
22namespace Isis {
23 CubeCachingAlgorithm::CacheResult
25 QList<RawCubeChunk *> allocated, QList<RawCubeChunk *> justUsed,
26 const Buffer &justRequested) {
27 CacheResult result;
28 if(allocated.size() && allocated[0] != NULL) {
29 double avgLargestDim = max( max(justRequested.SampleDimension(),
30 justRequested.LineDimension()),
31 justRequested.BandDimension());
32
33 // They'll all be roughly the same size, so the first one is good enough
34 int largestChunkDim = max( max( allocated[0]->sampleCount(),
35 allocated[0]->lineCount()),
36 allocated[0]->bandCount());
37 // The average needed per request ought to be
38 // avgLargestDim / largestChunkDim. Let's keep an extra few around
39 // since it's cheap, and because we are uncertain of request patterns.
40 // 40X with a maximum should keep a reasonable number of results
41 // around.
42 int numToKeep = (int)ceil(avgLargestDim / largestChunkDim) * 1;
43
44 // Limit to ~10MB
45 int approxBytesPerChunk = allocated[0]->getByteCount();
46
47 int tenMB = 10 * 1024 * 1024; // 10MB in bytes
48 if(numToKeep * approxBytesPerChunk > tenMB) {
49 numToKeep = tenMB / approxBytesPerChunk;
50 }
51
52 if(numToKeep < justUsed.size())
53 numToKeep = justUsed.size();
54
55 int numToToss = allocated.size() - numToKeep;
56
57 QList<RawCubeChunk *> chunksToToss;
58
59 QListIterator<RawCubeChunk *> allocatedIterator(allocated);
60
61 while(numToToss > 0 && allocatedIterator.hasNext()) {
62 RawCubeChunk *chunk = allocatedIterator.next();
63
64 if(justUsed.indexOf(chunk) == -1) {
65 numToToss --;
66 chunksToToss.append(chunk);
67 }
68 }
69
70 result = CacheResult(chunksToToss);
71 }
72
73 return result;
74 }
75}
76
Buffer for reading and writing cube data.
Definition Buffer.h:53
This stores the results of the caching algorithm.
A section of raw data on the disk.
virtual CacheResult recommendChunksToFree(QList< RawCubeChunk * > allocated, QList< RawCubeChunk * > justUsed, const Buffer &justRequested)
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16