[Kst] branches/work/kst/portto4/kst/src/datasources/ascii

Peter Kümmel syntheticpp at gmx.net
Wed Oct 17 07:55:01 UTC 2012


SVN commit 1320844 by kuemmel:

try to improve readability

 M  +9 -8      asciifilebuffer.cpp  
 M  +6 -7      asciifilebuffer.h  
 M  +14 -12    asciisource.cpp  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.cpp #1320843:1320844
@@ -54,12 +54,13 @@
 void AsciiFileBuffer::clear()
 {
   _fileData.clear();
+  _slidingFileData.clear();
   _begin = -1;
   _bytesRead = 0;
 }
 
 //-------------------------------------------------------------------------------------------
-const QVector<AsciiFileData>& AsciiFileBuffer::data() const
+const QVector<AsciiFileData>& AsciiFileBuffer::fileData() const
 {
   return _fileData;
 }
@@ -114,9 +115,8 @@
   return chunks;
 }
 
-
 //-------------------------------------------------------------------------------------------
-void AsciiFileBuffer::readWholeFile(const RowIndex& rowIndex, int start, int bytesToRead, int numChunks, int maximalBytes)
+void AsciiFileBuffer::readComplete(const RowIndex& rowIndex, int start, int bytesToRead, int numChunks, int maximalBytes)
 {
   clear();
   if (!_file)
@@ -162,10 +162,11 @@
 }
 
 //-------------------------------------------------------------------------------------------
-void AsciiFileBuffer::readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize, int numSubChunks)
+void AsciiFileBuffer::readSliding(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize, int numSubChunks)
 {
-  _slidingWindow.clear();
-  _bytesRead = 0;
+  clear();
+  if (!_file)
+    return;
 
   int subChunkSize = chunkSize / numSubChunks;
 
@@ -194,14 +195,14 @@
         break;
     }
     //qDebug() << "Sub chunks:"; AsciiFileData::logData(subChunks);
-    _slidingWindow.push_back(subChunks);
+    _slidingFileData.push_back(subChunks);
   }
   _begin = start;
   _bytesRead = bytesToRead;
 }
 
 //-------------------------------------------------------------------------------------------
-void AsciiFileBuffer::readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize)
+void AsciiFileBuffer::readLazy(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize)
 {
   clear();
   if (!_file)
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.h #1320843:1320844
@@ -32,20 +32,19 @@
   void clear();
 
   void setFile(QFile* file);
-  void readWholeFile(const RowIndex& rowIndex, int start, int bytesToRead, int numChunks, int maximalBytes = -1);
-  const QVector<AsciiFileData>& data() const; // -> wholeFile();
+  void readComplete(const RowIndex& rowIndex, int start, int bytesToRead, int numChunks, int maximalBytes = -1);
+  void readLazy(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize);
+  void readSliding(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize, int numSubChunks);
   
-  void readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize);
-  void readFileSlidingWindow(const RowIndex& rowIndex, int start, int bytesToRead, int chunkSize, int numSubChunks);
+  const QVector<AsciiFileData>& fileData() const;
+  const QVector<QVector<AsciiFileData> >& slidingFileData() const { return _slidingFileData; }
 
-  const QVector<QVector<AsciiFileData> >& slidingWindow() const { return _slidingWindow; }
-
   static bool openFile(QFile &file);
 
 private:
   QFile* _file;
   QVector<AsciiFileData> _fileData;
-  QVector<QVector<AsciiFileData> > _slidingWindow;
+  QVector<QVector<AsciiFileData> > _slidingFileData;
 
   int _begin;
   int _bytesRead;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320843:1320844
@@ -268,6 +268,8 @@
       return 0;
     }
 
+    _fileBuffer.setFile(file);
+
     int numThreads;
     if (!_config._useThreads) {
       numThreads = 1;
@@ -276,16 +278,16 @@
       numThreads = (numThreads > 0) ? numThreads : 1;
     }
 
-    _fileBuffer.setFile(file);
     if (useSlidingWindow(bytesToRead)) {
       if (_config._useThreads) {
-        _fileBuffer.readFileSlidingWindow(_reader.rowIndex(), begin, bytesToRead, _config._limitFileBufferSize, numThreads);
+        _fileBuffer.readSliding(_reader.rowIndex(), begin, bytesToRead, _config._limitFileBufferSize, numThreads);
       } else {
-        _fileBuffer.readFileSlidingWindow(_reader.rowIndex(), begin, bytesToRead, _config._limitFileBufferSize);
+        _fileBuffer.readLazy(_reader.rowIndex(), begin, bytesToRead, _config._limitFileBufferSize);
       }
     } else {
-      _fileBuffer.readWholeFile(_reader.rowIndex(), begin, bytesToRead, numThreads);
+      _fileBuffer.readComplete(_reader.rowIndex(), begin, bytesToRead, numThreads);
     }
+
     if (_fileBuffer.bytesRead() == 0) {
       success = false;
       return 0;
@@ -294,11 +296,8 @@
   }
   
   if (_config._useThreads) {
-    if (!useSlidingWindow(bytesToRead)) {
-      //Q_ASSERT(n == readFieldSingleThreaded(_fileBuffer.data(), col, v, field));
-      return readFieldMultiThreaded(_fileBuffer.data(), col, v, field);
-    } else {
-      const QVector<QVector<AsciiFileData> >& slidingWindow = _fileBuffer.slidingWindow();
+    if (useSlidingWindow(bytesToRead)) {
+      const QVector<QVector<AsciiFileData> >& slidingWindow = _fileBuffer.slidingFileData();
       int sRead = 0;
       //int sRead_check = 0;
       foreach (const QVector<AsciiFileData>& window, slidingWindow) {
@@ -311,12 +310,15 @@
         sRead += readFieldMultiThreaded(window, col, v, field);
       }
       return sRead;
-    }
   } else  {
-    return readFieldSingleThreaded(_fileBuffer.data(), col, v, field);
+      //Q_ASSERT(n == readFieldSingleThreaded(_fileBuffer.data(), col, v, field));
+      return readFieldMultiThreaded(_fileBuffer.fileData(), col, v, field);
   }
 }
 
+  return readFieldSingleThreaded(_fileBuffer.fileData(), col, v, field);
+}
+
 //-------------------------------------------------------------------------------------------
 int AsciiSource::readFieldSingleThreaded(const QVector<AsciiFileData>& fileData, int col, double* v, const QString& field, int sRead)
 {
@@ -333,7 +335,7 @@
 int AsciiSource::readFieldMultiThreaded(const QVector<AsciiFileData>& fileData, int col, double* v, const QString& field)
 {
   QFutureSynchronizer<int> readFutures;
-  const QVector<AsciiFileData>& data = _fileBuffer.data();
+  const QVector<AsciiFileData>& data = _fileBuffer.fileData();
   foreach (const AsciiFileData& chunk, fileData) {
     QFuture<int> future = QtConcurrent::run(&_reader, &AsciiDataReader::readFieldChunk, chunk, col, v, field);
     readFutures.addFuture(future);


More information about the Kst mailing list