Isis 3.0 Programmer Reference
Back | Home
RegionalCachingAlgorithm.cpp
Go to the documentation of this file.
1 
22 
23 #include <algorithm>
24 #include <iostream>
25 
26 #include <QList>
27 
28 #include "Buffer.h"
29 #include "Distance.h"
30 #include "RawCubeChunk.h"
31 #include "Statistics.h"
32 
33 using std::max;
34 
35 namespace Isis {
36  CubeCachingAlgorithm::CacheResult
38  QList<RawCubeChunk *> allocated, QList<RawCubeChunk *> justUsed,
39  const Buffer &justRequested) {
40  CacheResult result;
41  if(allocated.size() && allocated[0] != NULL) {
42  double avgLargestDim = max( max(justRequested.SampleDimension(),
43  justRequested.LineDimension()),
44  justRequested.BandDimension());
45 
46  // They'll all be roughly the same size, so the first one is good enough
47  int largestChunkDim = max( max( allocated[0]->sampleCount(),
48  allocated[0]->lineCount()),
49  allocated[0]->bandCount());
50  // The average needed per request ought to be
51  // avgLargestDim / largestChunkDim. Let's keep an extra few around
52  // since it's cheap, and because we are uncertain of request patterns.
53  // 40X with a maximum should keep a reasonable number of results
54  // around.
55  int numToKeep = (int)ceil(avgLargestDim / largestChunkDim) * 1;
56 
57  // Limit to ~10MB
58  int approxBytesPerChunk = allocated[0]->getByteCount();
59 
60  int tenMB = 10 * 1024 * 1024; // 10MB in bytes
61  if(numToKeep * approxBytesPerChunk > tenMB) {
62  numToKeep = tenMB / approxBytesPerChunk;
63  }
64 
65  if(numToKeep < justUsed.size())
66  numToKeep = justUsed.size();
67 
68  int numToToss = allocated.size() - numToKeep;
69 
70  QList<RawCubeChunk *> chunksToToss;
71 
72  QListIterator<RawCubeChunk *> allocatedIterator(allocated);
73 
74  while(numToToss > 0 && allocatedIterator.hasNext()) {
75  RawCubeChunk *chunk = allocatedIterator.next();
76 
77  if(justUsed.indexOf(chunk) == -1) {
78  numToToss --;
79  chunksToToss.append(chunk);
80  }
81  }
82 
83  result = CacheResult(chunksToToss);
84  }
85 
86  return result;
87  }
88 }
89 
Buffer for reading and writing cube data.
Definition: Buffer.h:68
virtual CacheResult recommendChunksToFree(QList< RawCubeChunk * > allocated, QList< RawCubeChunk * > justUsed, const Buffer &justRequested)
int LineDimension() const
Returns the number of lines in the shape buffer.
Definition: Buffer.h:94
int BandDimension() const
Returns the number of bands in the shape buffer.
Definition: Buffer.h:103
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
A section of raw data on the disk.
Definition: RawCubeChunk.h:42
This stores the results of the caching algorithm.
int SampleDimension() const
Returns the number of samples in the shape buffer.
Definition: Buffer.h:85

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:28:13