File indexing completed on 2024-12-22 04:17:19

0001 /***************************************************************************
0002                           datavector.h  -  description
0003                              -------------------
0004     begin                : Fri Sep 22 2000
0005     copyright            : (C) 2000 by cbn
0006     email                : netterfield@astro.utoronto.ca
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #ifndef DATAVECTOR_H
0019 #define DATAVECTOR_H
0020 
0021 #include "kst_export.h"
0022 #include "dataprimitive.h"
0023 #include "vector.h"
0024 
0025 
0026 
0027 namespace Kst {
0028 
0029 /**A class for handling data vectors for kst.
0030  *@author cbn
0031  */
0032 
0033 class KSTCORE_EXPORT DataVector : public Vector, public DataPrimitive
0034 {
0035     Q_OBJECT
0036 
0037   public:
0038 
0039     /** Parameters for reading vectors a field from a file.  Data is returned in the data;
0040       data points to allocated array which should be filled
0041       startingFrame is the starting frame
0042       numberOfFrames is the number of frames to read
0043         if numberOfFrames is -1, it means to read 1 -sample- from startingFrame.
0044       skipFrame: currently ignored by all data sources
0045       lastFrameRead: currently ignored
0046      */
0047     struct KSTCORE_EXPORT ReadInfo {
0048       double*  data;
0049       int startingFrame;
0050       int numberOfFrames;
0051       int skipFrame;
0052     };
0053 
0054 
0055     struct KSTCORE_EXPORT DataInfo
0056     {
0057       DataInfo();
0058       DataInfo(int frameCount, int samplesPerFrame);
0059 
0060       int frameCount;
0061       int samplesPerFrame;
0062     };
0063 
0064 
0065 
0066     virtual const QString& typeString() const;
0067     static const QString staticTypeString;
0068     static const QString staticTypeTag;
0069 
0070     virtual void reset(); // must be called with a lock
0071 
0072     /** change the properties of a DataVector */
0073     void change(DataSourcePtr file, const QString &field,
0074                 int f0, int n, int skip,
0075                 bool in_doSkip, bool in_doAve);
0076 
0077     void changeFile(DataSourcePtr file);
0078 
0079     void changeFrames(int f0, int n, int skip,
0080                       bool in_doSkip, bool in_doAve);           //si
0081 
0082     /** Return frames held in Vector */
0083     int numFrames() const;                                      //si
0084 
0085     /** Return the requested number of frames in the vector */
0086     int reqNumFrames() const;
0087 
0088     /** Return Starting Frame of Vector */
0089     int startFrame() const;                                     //si
0090 
0091     /** Return the requested starting frame of the Vector */
0092     int reqStartFrame() const;
0093 
0094     /** Return frames to skip per read */
0095     bool doSkip() const;                                        //si^3
0096     bool doAve() const;
0097     int skip() const;
0098 
0099     /** Reload the contents of the vector */
0100     void reload();                                              //si
0101 
0102     /** Returns intrinsic samples per frame */
0103     int samplesPerFrame() const;                                //si
0104 
0105     /** Save vector information */
0106     virtual void save(QXmlStreamWriter &s);
0107 
0108     /** return a sensible label for this vector */
0109     virtual LabelInfo labelInfo() const;
0110 
0111     /** return the length of the file */
0112     int fileLength() const;                                     //si
0113 
0114     /** return whether the vector is suppose to read to end of file */
0115     bool readToEOF() const;                                     //si
0116 
0117     /** read whether the vector is suppose to count back from end of file */
0118     bool countFromEOF() const;                                  //si
0119 
0120     /** Read from end */
0121     void setFromEnd();
0122 
0123     virtual QString descriptionTip() const;                     //si
0124 
0125     virtual QString propertyString() const;
0126 
0127     bool isValid() const;                                       //si
0128     virtual void internalUpdate();
0129 
0130     //implemented in Vector too but must not be virtual.
0131     QByteArray scriptInterface(QList<QByteArray> &command);
0132 
0133     /** does the vector represent time? */
0134     virtual bool isTime() const;
0135 
0136     virtual ScriptInterface* createScriptInterface();
0137 
0138   protected:
0139     DataVector(ObjectStore *store);
0140     virtual ~DataVector();
0141 
0142     friend class ObjectStore;
0143 
0144     virtual QString _automaticDescriptiveName() const;
0145 
0146     virtual void _resetFieldMetadata();
0147 
0148     virtual qint64 minInputSerial() const;
0149     virtual qint64 maxInputSerialOfLastChange() const;
0150 
0151   private:
0152     virtual void _resetFieldScalars();
0153     virtual void _resetFieldStrings();
0154 
0155     bool _dirty; // different from the Object dirty flag
0156 
0157     /** Samples Per Frame */
0158     int SPF;
0159 
0160     /** current number of frames */
0161     int NF;
0162 
0163     /** current starting frame */
0164     int F0;
0165 
0166     /** frames to skip per read */
0167     bool DoSkip;
0168     bool DoAve;
0169     int Skip;
0170 
0171     /** max number of frames */
0172     int ReqNF;
0173 
0174     int _invalidCount;
0175 
0176     /** Requested Starting Frame */
0177     int ReqF0;
0178 
0179     /** Number of Samples allocated to the vector */
0180     int _numSamples;
0181 
0182     int N_AveReadBuf;
0183     double *AveReadBuf;
0184 
0185     bool checkIntegrity(); // must be called with a lock
0186 
0187     // wrappers around DataSource interface functions
0188     int readField(double *v, const QString& field, int s, int n, int skip = -1);
0189     const DataInfo dataInfo(const QString& field) const;
0190 
0191     QHash<QString, ScalarPtr> _fieldScalars;
0192     QHash<QString, StringPtr> _fieldStrings;
0193 
0194     /** make a copy of the DataVector */
0195     virtual PrimitivePtr makeDuplicate() const;
0196     virtual bool checkValidity(const DataSourcePtr& ds) const;
0197 
0198     friend class TestDataSource;
0199     friend class TestHistogram;
0200     friend class TestCSD;
0201     friend class TestPSD;
0202     friend class TestScalar;
0203 };
0204 
0205 typedef SharedPtr<DataVector> DataVectorPtr;
0206 typedef ObjectList<DataVector> DataVectorList;
0207 
0208 }
0209 #endif
0210 // vim: ts=2 sw=2 et