Mercurial > hg > svcore
comparison data/fileio/MatrixFile.cpp @ 689:573d45e9487b
Merge from debug-output branch
author | Chris Cannam |
---|---|
date | Tue, 14 Jun 2011 14:47:59 +0100 |
parents | 06f13a3b9e9e |
children | 1424aa29ae95 |
comparison
equal
deleted
inserted
replaced
688:be43b2fe68e8 | 689:573d45e9487b |
---|---|
66 m_readyToReadColumn(-1) | 66 m_readyToReadColumn(-1) |
67 { | 67 { |
68 Profiler profiler("MatrixFile::MatrixFile", true); | 68 Profiler profiler("MatrixFile::MatrixFile", true); |
69 | 69 |
70 #ifdef DEBUG_MATRIX_FILE | 70 #ifdef DEBUG_MATRIX_FILE |
71 std::cerr << "MatrixFile::MatrixFile(" << fileBase.toStdString() << ", " << int(mode) << ", " << cellSize << ", " << width << ", " << height << ")" << std::endl; | 71 DEBUG << "MatrixFile::MatrixFile(" << fileBase << ", " << int(mode) << ", " << cellSize << ", " << width << ", " << height << ")" << endl; |
72 #endif | 72 #endif |
73 | 73 |
74 m_createMutex.lock(); | 74 m_createMutex.lock(); |
75 | 75 |
76 QDir tempDir(TempDirectory::getInstance()->getPath()); | 76 QDir tempDir(TempDirectory::getInstance()->getPath()); |
101 #ifdef _WIN32 | 101 #ifdef _WIN32 |
102 m_flags |= O_BINARY; | 102 m_flags |= O_BINARY; |
103 #endif | 103 #endif |
104 | 104 |
105 #ifdef DEBUG_MATRIX_FILE | 105 #ifdef DEBUG_MATRIX_FILE |
106 std::cerr << "MatrixFile(" << this << ")::MatrixFile: opening " << fileName.toStdString() << "..." << std::endl; | 106 std::cerr << "MatrixFile(" << this << ")::MatrixFile: opening " << fileName << "..." << std::endl; |
107 #endif | 107 #endif |
108 | 108 |
109 if ((m_fd = ::open(fileName.toLocal8Bit(), m_flags, m_fmode)) < 0) { | 109 if ((m_fd = ::open(fileName.toLocal8Bit(), m_flags, m_fmode)) < 0) { |
110 ::perror("Open failed"); | 110 ::perror("Open failed"); |
111 std::cerr << "ERROR: MatrixFile::MatrixFile: " | 111 std::cerr << "ERROR: MatrixFile::MatrixFile: " |
112 << "Failed to open cache file \"" | 112 << "Failed to open cache file \"" |
113 << fileName.toStdString() << "\""; | 113 << fileName << "\""; |
114 if (m_mode == WriteOnly) std::cerr << " for writing"; | 114 if (m_mode == WriteOnly) std::cerr << " for writing"; |
115 std::cerr << std::endl; | 115 std::cerr << std::endl; |
116 throw FailedToOpenFile(fileName); | 116 throw FailedToOpenFile(fileName); |
117 } | 117 } |
118 | 118 |
128 size_t header[2]; | 128 size_t header[2]; |
129 if (::read(m_fd, header, 2 * sizeof(size_t)) < 0) { | 129 if (::read(m_fd, header, 2 * sizeof(size_t)) < 0) { |
130 ::perror("MatrixFile::MatrixFile: read failed"); | 130 ::perror("MatrixFile::MatrixFile: read failed"); |
131 std::cerr << "ERROR: MatrixFile::MatrixFile: " | 131 std::cerr << "ERROR: MatrixFile::MatrixFile: " |
132 << "Failed to read header (fd " << m_fd << ", file \"" | 132 << "Failed to read header (fd " << m_fd << ", file \"" |
133 << fileName.toStdString() << "\")" << std::endl; | 133 << fileName << "\")" << std::endl; |
134 throw FileReadFailed(fileName); | 134 throw FileReadFailed(fileName); |
135 } | 135 } |
136 if (header[0] != m_width || header[1] != m_height) { | 136 if (header[0] != m_width || header[1] != m_height) { |
137 std::cerr << "ERROR: MatrixFile::MatrixFile: " | 137 std::cerr << "ERROR: MatrixFile::MatrixFile: " |
138 << "Dimensions in file header (" << header[0] << "x" | 138 << "Dimensions in file header (" << header[0] << "x" |
144 | 144 |
145 m_fileName = fileName; | 145 m_fileName = fileName; |
146 ++m_refcount[fileName]; | 146 ++m_refcount[fileName]; |
147 | 147 |
148 #ifdef DEBUG_MATRIX_FILE | 148 #ifdef DEBUG_MATRIX_FILE |
149 std::cerr << "MatrixFile[" << m_fd << "]::MatrixFile: File " << fileName.toStdString() << ", ref " << m_refcount[fileName] << std::endl; | 149 std::cerr << "MatrixFile[" << m_fd << "]::MatrixFile: File " << fileName << ", ref " << m_refcount[fileName] << std::endl; |
150 | 150 |
151 std::cerr << "MatrixFile[" << m_fd << "]::MatrixFile: Done, size is " << "(" << m_width << ", " << m_height << ")" << std::endl; | 151 std::cerr << "MatrixFile[" << m_fd << "]::MatrixFile: Done, size is " << "(" << m_width << ", " << m_height << ")" << std::endl; |
152 #endif | 152 #endif |
153 | 153 |
154 ++totalCount; | 154 ++totalCount; |
171 if (m_fileName != "") { | 171 if (m_fileName != "") { |
172 | 172 |
173 if (--m_refcount[m_fileName] == 0) { | 173 if (--m_refcount[m_fileName] == 0) { |
174 | 174 |
175 if (::unlink(m_fileName.toLocal8Bit())) { | 175 if (::unlink(m_fileName.toLocal8Bit())) { |
176 std::cerr << "WARNING: MatrixFile::~MatrixFile: reference count reached 0, but failed to unlink file \"" << m_fileName.toStdString() << "\"" << std::endl; | 176 std::cerr << "WARNING: MatrixFile::~MatrixFile: reference count reached 0, but failed to unlink file \"" << m_fileName << "\"" << std::endl; |
177 } else { | 177 } else { |
178 std::cerr << "deleted " << m_fileName.toStdString() << std::endl; | 178 std::cerr << "deleted " << m_fileName << std::endl; |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 if (m_mode == WriteOnly) { | 183 if (m_mode == WriteOnly) { |
246 | 246 |
247 void | 247 void |
248 MatrixFile::close() | 248 MatrixFile::close() |
249 { | 249 { |
250 #ifdef DEBUG_MATRIX_FILE | 250 #ifdef DEBUG_MATRIX_FILE |
251 std::cerr << "MatrixFile::close()" << std::endl; | 251 DEBUG << "MatrixFile::close()" << endl; |
252 #endif | 252 #endif |
253 if (m_fd >= 0) { | 253 if (m_fd >= 0) { |
254 if (::close(m_fd) < 0) { | 254 if (::close(m_fd) < 0) { |
255 ::perror("MatrixFile::close: close failed"); | 255 ::perror("MatrixFile::close: close failed"); |
256 } | 256 } |