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

Barth Netterfield netterfield at astro.utoronto.ca
Wed Nov 5 23:10:24 CET 2008


SVN commit 880592 by netterfield:

port the dirfile datasource to use the external getdata library.
add field scalars to kst and have dirfilesource provide them
add field strings to kst and have dirfilesource provide them

field strings need more work
	-they need to show up in the string view dialog
	-they need to get coppied in replace dependant type functions

Still need to add a readme to tell you where to get said library.
Need to decide how to deal with data sources that use external libraries



 M  +1 -1      datasources/datasources.pro  
 D             datasources/dirfile (directory)  
 A             datasources/dirfilesource (directory)  
 A             datasources/dirfilesource/dirfilesource.cpp   [License: GPL (v2+)]
 A             datasources/dirfilesource/dirfilesource.h   [License: GPL (v2+)]
 A             datasources/dirfilesource/dirfilesource.pro  
 A             datasources/dirfilesource/kstdata_dirfilesource.desktop   [TRAILING SPACE]
 M  +7 -4      libkst/datasource.cpp  
 M  +14 -10    libkst/datasource.h  
 M  +1 -1      libkst/datastring.h  
 M  +87 -0     libkst/datavector.cpp  
 M  +8 -0      libkst/datavector.h  
 M  +5 -0      libkst/vector.cpp  
 M  +5 -1      libkst/vector.h  
 A             old_datasources/dirfile (directory)   datasources/dirfile#880583
 M  +1 -1      plugins/plugins.pro  


--- branches/work/kst/portto4/kst/src/datasources/datasources.pro #880591:880592
@@ -7,7 +7,7 @@
     sampledatasource
 
 
-!win32:SUBDIRS += dirfile
+!win32:SUBDIRS += dirfilesource
 
 #     cdf \
 #     fitsimage \
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #880591:880592
@@ -114,7 +114,7 @@
     //try a cast
     if (DataSourcePluginInterface *ds = dynamic_cast<DataSourcePluginInterface*>(plugin)) {
       tmpList.append(ds);
-    }
+    } 
   }
 
   QStringList pluginPaths;
@@ -130,6 +130,8 @@
           if (DataSourcePluginInterface *ds = dynamic_cast<DataSourcePluginInterface*>(plugin)) {
             tmpList.append(ds);
           }
+        } else {
+              Debug::self()->log(QString("instance failed for %1 (%2)").arg(fileName).arg(loader.errorString()));
         }
     }
   }
@@ -218,7 +220,6 @@
       return plugin;
     }
   }
-
   return 0L;
 }
 
@@ -730,9 +731,10 @@
   return QStringList();
 }
 
-int DataSource::readFieldScalars(double v[], const QString& field) {
+int DataSource::readFieldScalars(QList<double> &v, const QString& field, bool init) {
   Q_UNUSED(v)
   Q_UNUSED(field)
+  Q_UNUSED(init)
   return (0);
 }
 
@@ -743,9 +745,10 @@
 }
 
 
-int DataSource::readFieldScalars(QStringList &v, const QString& field) {
+int DataSource::readFieldStrings(QStringList &v, const QString& field, bool init) {
   Q_UNUSED(v)
   Q_UNUSED(field)
+  Q_UNUSED(init)
   return (0);
 }
 
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #880591:880592
@@ -31,8 +31,8 @@
 #include "object.h"
 #include "dateparser.h"
 #include "objectlist.h"
-#include "scalar.h"
-#include "string_kst.h"
+//#include "scalar.h"
+//#include "string_kst.h"
 
 class QXmlStreamWriter;
 class QXmlStreamAttributes;
@@ -212,18 +212,19 @@
         These could be sample rate, calibrations, etc.  This list must be
         complete the very first time it is called and must never change its
         order or size, because readFieldScalars counts on its order and size. 
-        In order to remain fast, the data source can additionally assume that
-        readField() has already been called on the field, so the updating
-        of scalar values can be done there instead and cached for read by this
-        call.  */
+        */
     virtual QStringList fieldScalars(const QString& field);
 
     /** Read the values of the field scalars.  This is called for every field scalar
         every time the vector is updated, so it needs to be kept very cheap.
         Returns the number of scalars returned, and 0 on failure. V must
         be pre allocated to the right size as given by the length of the list
-        returned by fieldScalars() */ 
-    virtual int readFieldScalars(double v[], const QString& field);
+        returned by fieldScalars(). 
+        Most data sources will never change the the field scalars once they have 
+        been initialized.  In order to keep this case as fast as possible, the data 
+        source can chose to only update v[] if init is true.  
+        Note: datavector currently assumes these never change, and only gets them once! */ 
+    virtual int readFieldScalars(QList<double> &v, const QString& field, bool init);
 
     /** Returns a list of strings associated with a field by the data source.
         These could be units, notes, etc.  This list must be
@@ -237,8 +238,11 @@
 
     /** Read the values of the field strings.  This is called 
         every time the vector is updated, so it needs to be kept very cheap.
-        Returns the number of strings returned, and 0 on failure. */ 
-    virtual int readFieldScalars(QStringList &v, const QString& field);
+        Returns the number of strings returned, and 0 on failure. 
+        Most data sources will never change the the field strings once they have 
+        been initialized.  In order to keep this case as fast as possible, the data 
+        source can chose to only update v if init is true.  */ 
+    virtual int readFieldStrings(QStringList &v, const QString& field, bool init);
 
     /************************************************************/
     /* Methods for Matrixes                                     */
--- branches/work/kst/portto4/kst/src/libkst/datastring.h #880591:880592
@@ -18,7 +18,7 @@
 #ifndef DATASTRING_H
 #define DATASTRING_H
 
-#include "string.h"
+#include "string_kst.h"
 #include "datasource.h"
 #include "kst_export.h"
 
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #880591:880592
@@ -118,6 +118,7 @@
     _file->writeLock();
   }
   reset();
+  _resetFieldMetadata();
   if (_file) {
     _file->unlock();
   }
@@ -144,6 +145,7 @@
     _file->writeLock();
   }
   reset();
+  _resetFieldMetadata();
   if (_file) {
     _file->unlock();
   }
@@ -649,11 +651,96 @@
         reset();
       }
     }
+    _resetFieldMetadata();
     _file->unlock();
   }
 }
 
+void DataVector::_resetFieldMetadata() {
+  _resetFieldScalars();
+  _resetFieldStrings();
+}
 
+void DataVector::_resetFieldStrings() {
+  // Note: this does not necessarily preseve order if the 
+  // datasource or field have been changed.  If dynamic
+  // fieldScalars are ever wanted, this should be fixed.
+  QStringList string_names = dataSource()->fieldStrings(field());
+  QStringList string_values;
+  dataSource()->readFieldStrings(string_values, field(), true);
+  StringPtr sp;
+  QString key;
+
+  QStringList fieldStringKeys = _fieldStrings.keys();
+  // remove field strings that no longer need to exist
+  readLock();
+  for (int i=0; i<fieldStringKeys.count(); i++) {
+    key = fieldStringKeys.at(i);
+    if (!string_names.contains(key)) {
+      StringPtr sp = _fieldStrings[key];
+      _strings.remove(key);
+      _fieldStrings.remove(key);
+      sp = 0L;
+    }
+  }
+  // find or insert strings, to set their value
+  for (int i=0; i<string_names.count(); i++) {
+    key = string_names.at(i);
+    if (!_fieldStrings.contains(key)) { // insert a new one
+      _strings.insert(key, sp = store()->createObject<String>());
+      _fieldStrings.insert(key, sp);
+      sp->setProvider(this);
+      sp->setSlaveName(string_names.at(i));
+      sp->_KShared_ref();
+    } else {  // find it
+      sp = _fieldStrings[key];
+    }
+    sp->setValue(string_values[i]);
+  }
+  unlock();
+}
+
+
+void DataVector::_resetFieldScalars() {
+  // Note: this does not necessarily preseve order if the 
+  // datasource or field have been changed.  If dynamic
+  // fieldScalars are ever wanted, this should be fixed.
+  QStringList scalar_names = dataSource()->fieldScalars(field());
+  QList<double> scalar_values;
+  dataSource()->readFieldScalars(scalar_values, field(), true);
+
+  ScalarPtr sp;
+  QString key;
+
+  QStringList fieldScalarKeys = _fieldScalars.keys();
+  // remove field scalars that no longer need to exist
+  readLock();
+  for (int i=0; i<fieldScalarKeys.count(); i++) {
+    key = fieldScalarKeys.at(i);
+    if (!scalar_names.contains(key)) {
+      ScalarPtr sp = _fieldScalars[key];
+      _scalars.remove(key);
+      _fieldScalars.remove(key);
+      sp = 0L;
+    }
+  }
+  // find or insert scalars, to set their value
+  for (int i=0; i<scalar_names.count(); i++) {
+    key = scalar_names.at(i);
+    if (!_fieldScalars.contains(key)) { // insert a new one
+      _scalars.insert(key, sp = store()->createObject<Scalar>());
+      _fieldScalars.insert(key, sp);
+      sp->setProvider(this);
+      sp->setSlaveName(scalar_names.at(i));
+      sp->_KShared_ref();
+    } else {  // find it
+      sp = _fieldScalars[key];
+    }
+    sp->setValue(scalar_values[i]);
+  }
+  unlock();
+}
+
 DataSourcePtr DataVector::dataSource() const {
   return _file;
 }
--- branches/work/kst/portto4/kst/src/libkst/datavector.h #880591:880592
@@ -121,7 +121,11 @@
 
     virtual QString _automaticDescriptiveName() const;
 
+    virtual void _resetFieldMetadata();
   private:
+    virtual void _resetFieldScalars();
+    virtual void _resetFieldStrings();
+
     Object::UpdateType doUpdate(bool force = false);
 
     bool _dirty; // different from the Object dirty flag
@@ -163,6 +167,10 @@
     void checkIntegrity(); // must be called with a lock
 
     bool _dontUseSkipAccel;
+
+    QHash<QString, Scalar*> _fieldScalars;
+    QHash<QString, String*> _fieldStrings;
+
 };
 
 typedef SharedPtr<DataVector> DataVectorPtr;
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #880591:880592
@@ -315,6 +315,11 @@
 }
 
 
+const QHash<QString, String*>& Vector::strings() const {
+  return _strings;
+}
+
+
 double* Vector::realloced(double *memptr, int newSize) {
   double *old = _v;
   _v = memptr;
--- branches/work/kst/portto4/kst/src/libkst/vector.h #880591:880592
@@ -25,6 +25,7 @@
 
 #include "primitive.h"
 #include "scalar.h"
+#include "string_kst.h"
 #include "kst_export.h"
 
 class QXmlStreamWriter;
@@ -135,6 +136,7 @@
     bool isScalarList() const { return _isScalarList; }
 
     const QHash<QString, Scalar*>& scalars() const;
+    const QHash<QString, String*>& strings() const; // used by datavector
 
     void setLabel(const QString& label_in);
 
@@ -172,6 +174,9 @@
     /** Statistics Scalars */
     QHash<QString, Scalar*> _scalars;
 
+    /** Dependent Strings: used by datavector */
+    QHash<QString, String*> _strings;
+
     /** is the vector monotonically rising */
     bool _is_rising : 1;
 
@@ -193,7 +198,6 @@
 
     /** Scalar Maintenance methods */
     void CreateScalars(ObjectStore *store);
-    void RenameScalars();
 
     virtual void deleteDependents();
 
--- branches/work/kst/portto4/kst/src/plugins/plugins.pro #880591:880592
@@ -2,7 +2,7 @@
 CONFIG += ordered
 
 SUBDIRS += \
-    #sampleplugin \
+    sampleplugin \
     filters \
     fits \
     dataobject


More information about the Kst mailing list