AnalysisPlugins 2.0(r200)
For the analysis of event energy and time

PacWaveformBase.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Matthias Nagl   *
00003  *   mnagl@uni-goettingen.de   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef PACWAVEFORMPLUGINBASE_H
00021 #define PACWAVEFORMPLUGINBASE_H
00022 
00033 #include <QObject>
00034 #include <QDataStream>
00035 #include <QByteArray>
00036 #include <QVector>
00037 #include <QGroupBox>
00038 #include <QVBoxLayout>
00039 #include <WaveformInterface.h>
00040 #include <TransmittableProperty.h>
00041 #include <PropertyBranch.h>
00042 #include <limits>
00043 
00044 class PacWaveformDataBase;
00045 class QwtPlotCurve;
00046 class QwtPlot;
00047 class QwtPlotGrid;
00048 class QwtPlotZoomer;
00049 class QwtPlotMarker;
00050 class QToolButton;
00051 
00056 class PacWaveformBase
00057     : public QObject,
00058       public WaveformProcessingInterface,
00059       public PropertyBranch,
00060       public WaveformPresentationInterface
00061 {
00062     Q_OBJECT
00063     Q_INTERFACES(WaveformProcessingInterface)
00064     Q_INTERFACES(WaveformPresentationInterface)
00065 
00066   public:
00067     PacWaveformBase(QObject *parent = 0, const QString &pluginname = "", const QString &pluginversion = "");
00068     virtual ~PacWaveformBase();
00069 
00070     virtual void setParentBranch(PropertyBranchInterface *p = 0);
00071     virtual QString name() const { return pluginname; }
00072     virtual QString version() const { return pluginversion; }
00073     //virtual void attachToPlot(QwtPlot *plot);
00074     virtual void setWaveformData(WaveformDataInterface *data);
00075     virtual WaveformDataInterface * tryDeserialization(const QByteArray &serialized) const;
00076     virtual void readUpdatedParameters();
00077     virtual QWidget * getWidget();
00078     virtual void setTitleString(const QString &);
00079     //virtual void deleteControlWidget();
00080 
00081   protected slots:
00082     void exportWaveform();
00083 
00084   protected:
00085     QWidget * createExportButton();
00086     const QString pluginname;
00087     const QString pluginversion;
00088     QString titlestring;
00089     virtual bool canDeserialize(const QByteArray &serialized) const;
00090     TransmittableProperty p_overflowlimit;
00091     qint32 overflowlimit;
00092     QVector<qreal> xvector, voltvector;
00093     QwtPlotCurve *waveform;
00094     QwtPlotMarker *waveformtrigger;
00095     QwtPlotGrid *waveformgrid;
00096     QPointer<QwtPlot> myplot;
00097     QPointer<QGroupBox> widget;
00098     QPointer<QWidget> controlwidget;
00099     QVBoxLayout *layout;
00100     QPointer<QwtPlotZoomer> wfzoomer;
00101     qreal xmin, xmax, ymin, ymax; 
00102     QPointer<QToolButton> exportbutton;
00103     const PacWaveformDataBase *currentwf;
00104     bool noupdates;
00105 };
00106 
00113 class PacWaveformDataBase
00114     : public WaveformDataInterface
00115 {
00116   public:
00117     PacWaveformDataBase(const PacWaveformBase *creator = 0);
00118     PacWaveformDataBase(const PacWaveformBase *creator, const QByteArray &serialized);
00119     PacWaveformDataBase(const PacWaveformDataBase &original);
00120     virtual void clone(const WaveformDataInterface *original);
00121     virtual ~PacWaveformDataBase();
00122 
00123     virtual void setData(
00124       quint32 numsamples,
00125       const qint8 * dataArray,
00126       qulonglong triggertimestamp,
00127       qreal hpos,
00128       qint32 samplesbeforetrigger,
00129       qreal sampleinterval,
00130       qreal vgain,
00131       qreal voffset,
00132       qint8 polarity,
00133       qreal triggerlevel
00134     );
00135 
00136     qint32 overflowSamples() const;
00137 
00138     virtual QByteArray serialize(const QByteArray &childrensdata = QByteArray()) const;
00139     virtual QByteArray deserialize(const QByteArray &serialized);
00140     virtual qreal getCoulomb() const { analyze(); return coulomb; }
00141     virtual qulonglong getSignalOnset() const { analyze(); return onsettime; }
00142     virtual bool badWaveform() const { analyze(); return badwaveform; }
00143     virtual void setNodeId(quint16 nodeid) { nid = nodeid; }
00144     virtual quint16 nodeId() const { return nid; }
00145     virtual QString toCSV() const;
00146     friend void PacWaveformBase::setWaveformData(WaveformDataInterface *data);
00147 
00148   protected:
00150     virtual void analyze() const = 0;
00152     inline qreal sampleInVolts(quint32 i) const { return qreal(dataArray[i])*vgain-voffset-autooffset; }
00156     inline qreal sampleTime(qint32 i) const { return qreal(i-(samplesbeforetrigger+1))*sampleinterval+hpos; }
00158     inline qreal digitizersUpperLimitInVolts() const { return qreal(std::numeric_limits<qint8>::max())*vgain-voffset; }
00160     inline qreal digitizersLowerLimitInVolts() const { return qreal(std::numeric_limits<qint8>::min())*vgain-voffset; }
00162     inline qreal timescaleLowerLimit() const { return -qreal(samplesbeforetrigger+1+1)*sampleinterval; }
00164     inline qreal timescaleUpperLimit() const { return qreal(numsamples-(samplesbeforetrigger+1))*sampleinterval; }
00165 
00166     quint32 numsamples;
00167     qint8 *dataArray;
00168     qulonglong triggertimestamp;
00169     mutable qreal autooffset;
00170     mutable qint32 numoverflowsamples;
00171     mutable qreal coulomb;        
00172     mutable qulonglong onsettime; 
00173     mutable bool badwaveform;     
00174     qint32 samplesbeforetrigger;
00175     qreal hpos, sampleinterval, vgain, voffset;
00176     qint8 polarity;         
00177     qreal triggerlevel;     
00178     quint16 nid;
00179     const PacWaveformBase *creator;
00180 };
00181 
00182 #endif
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends