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 
20 using std::max;
21 
22 namespace 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 
Isis::RawCubeChunk
A section of raw data on the disk.
Definition: RawCubeChunk.h:27
Isis::Buffer::SampleDimension
int SampleDimension() const
Returns the number of samples in the shape buffer.
Definition: Buffer.h:70
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::RegionalCachingAlgorithm::recommendChunksToFree
virtual CacheResult recommendChunksToFree(QList< RawCubeChunk * > allocated, QList< RawCubeChunk * > justUsed, const Buffer &justRequested)
Definition: RegionalCachingAlgorithm.cpp:24
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::Buffer::LineDimension
int LineDimension() const
Returns the number of lines in the shape buffer.
Definition: Buffer.h:79
Isis::Buffer::BandDimension
int BandDimension() const
Returns the number of bands in the shape buffer.
Definition: Buffer.h:88
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16