Mercurial > hg > svcore
comparison data/fft/FFTDataServer.cpp @ 550:107d3f3705c9
* Auto-close write-mode matrix files when all columns written
author | Chris Cannam |
---|---|
date | Thu, 05 Feb 2009 14:17:11 +0000 |
parents | 388afa99d537 |
children | 53e5dc8439e7 |
comparison
equal
deleted
inserted
replaced
549:388afa99d537 | 550:107d3f3705c9 |
---|---|
898 Profiler profiler("FFTDataServer::getMagnitudeAt: filling"); | 898 Profiler profiler("FFTDataServer::getMagnitudeAt: filling"); |
899 #ifdef DEBUG_FFT_SERVER | 899 #ifdef DEBUG_FFT_SERVER |
900 std::cerr << "FFTDataServer::getMagnitudeAt: calling fillColumn(" | 900 std::cerr << "FFTDataServer::getMagnitudeAt: calling fillColumn(" |
901 << x << ")" << std::endl; | 901 << x << ")" << std::endl; |
902 #endif | 902 #endif |
903 fillColumn(x, cache); | 903 fillColumn(x); |
904 } | 904 } |
905 return cache->getMagnitudeAt(col, y); | 905 return cache->getMagnitudeAt(col, y); |
906 } | 906 } |
907 | 907 |
908 bool | 908 bool |
923 if (!cache) return false; | 923 if (!cache) return false; |
924 | 924 |
925 //!!! n.b. can throw | 925 //!!! n.b. can throw |
926 if (!cache->haveSetColumnAt(col)) { | 926 if (!cache->haveSetColumnAt(col)) { |
927 Profiler profiler("FFTDataServer::getMagnitudesAt: filling"); | 927 Profiler profiler("FFTDataServer::getMagnitudesAt: filling"); |
928 fillColumn(x, cache); | 928 fillColumn(x); |
929 } | 929 } |
930 | 930 |
931 cache->getMagnitudesAt(col, values, minbin, count, step); | 931 cache->getMagnitudesAt(col, values, minbin, count, step); |
932 | 932 |
933 return true; | 933 return true; |
945 if (!cache) return 0; | 945 if (!cache) return 0; |
946 | 946 |
947 //!!! n.b. can throw | 947 //!!! n.b. can throw |
948 if (!cache->haveSetColumnAt(col)) { | 948 if (!cache->haveSetColumnAt(col)) { |
949 Profiler profiler("FFTDataServer::getNormalizedMagnitudeAt: filling"); | 949 Profiler profiler("FFTDataServer::getNormalizedMagnitudeAt: filling"); |
950 fillColumn(x, cache); | 950 fillColumn(x); |
951 } | 951 } |
952 return cache->getNormalizedMagnitudeAt(col, y); | 952 return cache->getNormalizedMagnitudeAt(col, y); |
953 } | 953 } |
954 | 954 |
955 bool | 955 bool |
970 if (!cache) return false; | 970 if (!cache) return false; |
971 | 971 |
972 //!!! n.b. can throw | 972 //!!! n.b. can throw |
973 if (!cache->haveSetColumnAt(col)) { | 973 if (!cache->haveSetColumnAt(col)) { |
974 Profiler profiler("FFTDataServer::getNormalizedMagnitudesAt: filling"); | 974 Profiler profiler("FFTDataServer::getNormalizedMagnitudesAt: filling"); |
975 fillColumn(x, cache); | 975 fillColumn(x); |
976 } | 976 } |
977 | 977 |
978 for (size_t i = 0; i < count; ++i) { | 978 for (size_t i = 0; i < count; ++i) { |
979 values[i] = cache->getNormalizedMagnitudeAt(col, i * step + minbin); | 979 values[i] = cache->getNormalizedMagnitudeAt(col, i * step + minbin); |
980 } | 980 } |
994 if (!cache) return 0; | 994 if (!cache) return 0; |
995 | 995 |
996 //!!! n.b. can throw | 996 //!!! n.b. can throw |
997 if (!cache->haveSetColumnAt(col)) { | 997 if (!cache->haveSetColumnAt(col)) { |
998 Profiler profiler("FFTDataServer::getMaximumMagnitudeAt: filling"); | 998 Profiler profiler("FFTDataServer::getMaximumMagnitudeAt: filling"); |
999 fillColumn(x, cache); | 999 fillColumn(x); |
1000 } | 1000 } |
1001 return cache->getMaximumMagnitudeAt(col); | 1001 return cache->getMaximumMagnitudeAt(col); |
1002 } | 1002 } |
1003 | 1003 |
1004 float | 1004 float |
1013 if (!cache) return 0; | 1013 if (!cache) return 0; |
1014 | 1014 |
1015 //!!! n.b. can throw | 1015 //!!! n.b. can throw |
1016 if (!cache->haveSetColumnAt(col)) { | 1016 if (!cache->haveSetColumnAt(col)) { |
1017 Profiler profiler("FFTDataServer::getPhaseAt: filling"); | 1017 Profiler profiler("FFTDataServer::getPhaseAt: filling"); |
1018 fillColumn(x, cache); | 1018 fillColumn(x); |
1019 } | 1019 } |
1020 return cache->getPhaseAt(col, y); | 1020 return cache->getPhaseAt(col, y); |
1021 } | 1021 } |
1022 | 1022 |
1023 bool | 1023 bool |
1038 if (!cache) return false; | 1038 if (!cache) return false; |
1039 | 1039 |
1040 //!!! n.b. can throw | 1040 //!!! n.b. can throw |
1041 if (!cache->haveSetColumnAt(col)) { | 1041 if (!cache->haveSetColumnAt(col)) { |
1042 Profiler profiler("FFTDataServer::getPhasesAt: filling"); | 1042 Profiler profiler("FFTDataServer::getPhasesAt: filling"); |
1043 fillColumn(x, cache); | 1043 fillColumn(x); |
1044 } | 1044 } |
1045 | 1045 |
1046 for (size_t i = 0; i < count; ++i) { | 1046 for (size_t i = 0; i < count; ++i) { |
1047 values[i] = cache->getPhaseAt(col, i * step + minbin); | 1047 values[i] = cache->getPhaseAt(col, i * step + minbin); |
1048 } | 1048 } |
1074 if (!cache->haveSetColumnAt(col)) { | 1074 if (!cache->haveSetColumnAt(col)) { |
1075 Profiler profiler("FFTDataServer::getValuesAt: filling"); | 1075 Profiler profiler("FFTDataServer::getValuesAt: filling"); |
1076 #ifdef DEBUG_FFT_SERVER | 1076 #ifdef DEBUG_FFT_SERVER |
1077 std::cerr << "FFTDataServer::getValuesAt(" << x << ", " << y << "): filling" << std::endl; | 1077 std::cerr << "FFTDataServer::getValuesAt(" << x << ", " << y << "): filling" << std::endl; |
1078 #endif | 1078 #endif |
1079 fillColumn(x, cache); | 1079 fillColumn(x); |
1080 } | 1080 } |
1081 | 1081 |
1082 cache->getValuesAt(col, y, real, imaginary); | 1082 cache->getValuesAt(col, y, real, imaginary); |
1083 } | 1083 } |
1084 | 1084 |
1109 //!!! n.b. can throw | 1109 //!!! n.b. can throw |
1110 return cache->haveSetColumnAt(col); | 1110 return cache->haveSetColumnAt(col); |
1111 } | 1111 } |
1112 | 1112 |
1113 void | 1113 void |
1114 FFTDataServer::fillColumn(size_t x, FFTCacheReader *tester) | 1114 FFTDataServer::fillColumn(size_t x) |
1115 { | 1115 { |
1116 Profiler profiler("FFTDataServer::fillColumn", false); | 1116 Profiler profiler("FFTDataServer::fillColumn", false); |
1117 | 1117 |
1118 if (!m_model->isReady()) { | 1118 if (!m_model->isReady()) { |
1119 std::cerr << "WARNING: FFTDataServer::fillColumn(" | 1119 std::cerr << "WARNING: FFTDataServer::fillColumn(" |
1164 << " from channel " << m_channel << std::endl; | 1164 << " from channel " << m_channel << std::endl; |
1165 #endif | 1165 #endif |
1166 | 1166 |
1167 QMutexLocker locker(&m_fftBuffersLock); | 1167 QMutexLocker locker(&m_fftBuffersLock); |
1168 | 1168 |
1169 if (tester) { | 1169 // We may have been called from a function that wanted to obtain a |
1170 // We are being called from a function that wanted to obtain a | 1170 // column using an FFTCacheReader. Before calling us, it checked |
1171 // column using an FFTCacheReader. Before calling us, it | 1171 // whether the column was available already, and the reader |
1172 // checked whether the column was available already, and the | 1172 // reported that it wasn't. Now we test again, with the mutex |
1173 // reader reported that it wasn't. Now we test again with the | 1173 // held, to avoid a race condition in case another thread has |
1174 // mutex held, to avoid a race condition in case another | 1174 // called fillColumn at the same time. |
1175 // thread has called fillColumn at the same time. | 1175 if (cache->haveSetColumnAt(x & m_cacheWidthMask)) { |
1176 if (tester->haveSetColumnAt(x & m_cacheWidthMask)) { | 1176 return; |
1177 return; | |
1178 } | |
1179 } | 1177 } |
1180 | 1178 |
1181 if (!m_fftInput) { | 1179 if (!m_fftInput) { |
1182 std::cerr << "WARNING: FFTDataServer::fillColumn(" << x << "): " | 1180 std::cerr << "WARNING: FFTDataServer::fillColumn(" << x << "): " |
1183 << "input has already been completed and discarded?" | 1181 << "input has already been completed and discarded?" |