Mercurial > hg > svcore
comparison data/fft/FFTFileCacheReader.cpp @ 555:8accc7969c1c
* Some steps to avoid backward seeks in MatrixFile in common use cases
author | Chris Cannam |
---|---|
date | Mon, 09 Feb 2009 11:38:08 +0000 |
parents | 60482f13e627 |
children | 06f13a3b9e9e |
comparison
equal
deleted
inserted
replaced
554:60482f13e627 | 555:8accc7969c1c |
---|---|
32 | 32 |
33 FFTFileCacheReader::FFTFileCacheReader(FFTFileCacheWriter *writer) : | 33 FFTFileCacheReader::FFTFileCacheReader(FFTFileCacheWriter *writer) : |
34 m_readbuf(0), | 34 m_readbuf(0), |
35 m_readbufCol(0), | 35 m_readbufCol(0), |
36 m_readbufWidth(0), | 36 m_readbufWidth(0), |
37 m_readbufGood(false), | |
37 m_storageType(writer->getStorageType()), | 38 m_storageType(writer->getStorageType()), |
38 m_factorSize(m_storageType == FFTCache::Compact ? 2 : 1), | 39 m_factorSize(m_storageType == FFTCache::Compact ? 2 : 1), |
39 m_mfc(new MatrixFile | 40 m_mfc(new MatrixFile |
40 (writer->getFileBase(), | 41 (writer->getFileBase(), |
41 MatrixFile::ReadOnly, | 42 MatrixFile::ReadOnly, |
154 } | 155 } |
155 | 156 |
156 void | 157 void |
157 FFTFileCacheReader::getValuesAt(size_t x, size_t y, float &real, float &imag) const | 158 FFTFileCacheReader::getValuesAt(size_t x, size_t y, float &real, float &imag) const |
158 { | 159 { |
160 // std::cerr << "FFTFileCacheReader::getValuesAt(" << x << "," << y << ")" << std::endl; | |
161 | |
159 switch (m_storageType) { | 162 switch (m_storageType) { |
160 | 163 |
161 case FFTCache::Rectangular: | 164 case FFTCache::Rectangular: |
162 real = getFromReadBufStandard(x, y * 2); | 165 real = getFromReadBufStandard(x, y * 2); |
163 imag = getFromReadBufStandard(x, y * 2 + 1); | 166 imag = getFromReadBufStandard(x, y * 2 + 1); |
209 } | 212 } |
210 | 213 |
211 bool | 214 bool |
212 FFTFileCacheReader::haveSetColumnAt(size_t x) const | 215 FFTFileCacheReader::haveSetColumnAt(size_t x) const |
213 { | 216 { |
217 if (m_readbuf && m_readbufGood && | |
218 (m_readbufCol == x || (m_readbufWidth > 1 && m_readbufCol+1 == x))) { | |
219 // std::cerr << "FFTFileCacheReader::haveSetColumnAt: short-circuiting; we know about this one" << std::endl; | |
220 return true; | |
221 } | |
214 return m_mfc->haveSetColumnAt(x); | 222 return m_mfc->haveSetColumnAt(x); |
215 } | 223 } |
216 | 224 |
217 size_t | 225 size_t |
218 FFTFileCacheReader::getCacheSize(size_t width, size_t height, | 226 FFTFileCacheReader::getCacheSize(size_t width, size_t height, |
226 void | 234 void |
227 FFTFileCacheReader::populateReadBuf(size_t x) const | 235 FFTFileCacheReader::populateReadBuf(size_t x) const |
228 { | 236 { |
229 Profiler profiler("FFTFileCacheReader::populateReadBuf", false); | 237 Profiler profiler("FFTFileCacheReader::populateReadBuf", false); |
230 | 238 |
231 std::cerr << "FFTFileCacheReader::populateReadBuf(" << x << ")" << std::endl; | 239 // std::cerr << "FFTFileCacheReader::populateReadBuf(" << x << ")" << std::endl; |
232 | 240 |
233 if (!m_readbuf) { | 241 if (!m_readbuf) { |
234 m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()]; | 242 m_readbuf = new char[m_mfc->getHeight() * 2 * m_mfc->getCellSize()]; |
235 } | 243 } |
236 | 244 |
245 m_readbufGood = false; | |
246 | |
237 try { | 247 try { |
238 m_mfc->getColumnAt(x, m_readbuf); | 248 bool good = false; |
249 if (m_mfc->haveSetColumnAt(x)) { | |
250 // If the column is not available, we have no obligation | |
251 // to do anything with the readbuf -- we can cheerfully | |
252 // return garbage. It's the responsibility of the caller | |
253 // to check haveSetColumnAt before trusting any retrieved | |
254 // data. However, we do record whether the data in the | |
255 // readbuf is good or not, because we can use that to | |
256 // return an immediate result for haveSetColumnAt if the | |
257 // column is right. | |
258 good = true; | |
259 m_mfc->getColumnAt(x, m_readbuf); | |
260 } | |
239 if (m_mfc->haveSetColumnAt(x + 1)) { | 261 if (m_mfc->haveSetColumnAt(x + 1)) { |
240 m_mfc->getColumnAt | 262 m_mfc->getColumnAt |
241 (x + 1, m_readbuf + m_mfc->getCellSize() * m_mfc->getHeight()); | 263 (x + 1, m_readbuf + m_mfc->getCellSize() * m_mfc->getHeight()); |
242 m_readbufWidth = 2; | 264 m_readbufWidth = 2; |
243 } else { | 265 } else { |
244 m_readbufWidth = 1; | 266 m_readbufWidth = 1; |
245 } | 267 } |
268 m_readbufGood = good; | |
246 } catch (FileReadFailed f) { | 269 } catch (FileReadFailed f) { |
247 std::cerr << "ERROR: FFTFileCacheReader::populateReadBuf: File read failed: " | 270 std::cerr << "ERROR: FFTFileCacheReader::populateReadBuf: File read failed: " |
248 << f.what() << std::endl; | 271 << f.what() << std::endl; |
249 memset(m_readbuf, 0, m_mfc->getHeight() * 2 * m_mfc->getCellSize()); | 272 memset(m_readbuf, 0, m_mfc->getHeight() * 2 * m_mfc->getCellSize()); |
250 } | 273 } |