nmrspectrumbase.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef nmrspectrumbaseH
15 #define nmrspectrumbaseH
16 //---------------------------------------------------------------------------
17 #include <secondarydriver.h>
18 #include <xnodeconnector.h>
19 #include <complex>
20 #include "nmrspectrumsolver.h"
21 
22 class XNMRPulseAnalyzer;
23 class XWaveNGraph;
24 class XXYPlot;
25 
26 template <class FRM>
28 public:
29  XNMRSpectrumBase(const char *name, bool runtime,
30  Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
31  //! ususally nothing to do
32  virtual ~XNMRSpectrumBase();
33 
34  //! Shows all forms belonging to driver
35  virtual void showForms() override;
36 protected:
37  //! This function is called when a connected driver emit a signal
38  virtual void analyze(Transaction &tr, const Snapshot &shot_emitter, const Snapshot &shot_others,
39  XDriver *emitter) throw (XRecordError&) override;
40  //! This function is called after committing XPrimaryDriver::analyzeRaw() or XSecondaryDriver::analyze().
41  //! This might be called even if the record is invalid (time() == false).
42  virtual void visualize(const Snapshot &shot) override;
43  //! Checks if the connected drivers have valid time stamps.
44  //! \return true if dependency is resolved.
45  //! This function must be reentrant unlike analyze().
46  virtual bool checkDependency(const Snapshot &shot_this,
47  const Snapshot &shot_emitter, const Snapshot &shot_others,
48  XDriver *emitter) const override;
49 public:
50  //! driver specific part below
52  const std::vector<std::complex<double> > &wave() const {return m_wave;}
53  //! Averaged weights.
54  const std::vector<double> &weights() const {return m_weights;}
55  //! Power spectrum density of dark. [V].
56  const std::vector<double> &darkPSD() const {return m_darkPSD;}
57  //! Resolution [Hz].
58  double res() const {return m_res;}
59  //! Value of the first point [Hz].
60  double min() const {return m_min;}
61  private:
62  template <class>
63  friend class XNMRSpectrumBase;
64 
65  double m_res, m_min;
66 
67  std::vector<double> m_weights;
68  std::vector<double> m_darkPSD;
69  std::vector<std::complex<double> > m_wave;
70 
71  enum {ACCUM_BANKS = 3};
72  std::deque<std::complex<double> > m_accum[ACCUM_BANKS];
73  std::deque<double> m_accum_weights[ACCUM_BANKS];
74  std::deque<double> m_accum_dark[ACCUM_BANKS]; //[V^2/Hz].
75 
76  std::deque<std::pair<double, double> > m_peaks;
77 
78  shared_ptr<FFT> m_ift, m_preFFT;
79 
80  XTime m_timeClearRequested;
81  };
82 
83  const shared_ptr<XItemNode<XDriverList, XNMRPulseAnalyzer> > &pulse() const {return m_pulse;}
84 
85  const shared_ptr<XDoubleNode> &bandWidth() const {return m_bandWidth;}
86  //! Tune bandwidth to 50%/100%/200%.
87  const shared_ptr<XComboNode> &bwList() const {return m_bwList;}
88  //! Deduce phase from data
89  const shared_ptr<XBoolNode> &autoPhase() const {return m_autoPhase;}
90  //! (Deduced) phase of echoes [deg.]
91  const shared_ptr<XDoubleNode> &phase() const {return m_phase;}
92  //! Spectrum solvers.
93  const shared_ptr<XComboNode> &solverList() const {return m_solverList;}
94  ///! FFT Window Function
95  const shared_ptr<XComboNode> &windowFunc() const {return m_windowFunc;}
96  //! Changing width of time-domain image [%]
97  const shared_ptr<XDoubleNode> &windowWidth() const {return m_windowWidth;}
98  //! Clears stored points.
99  const shared_ptr<XTouchableNode> &clear() const {return m_clear;}
100 protected:
101  shared_ptr<XListener> m_lsnOnClear, m_lsnOnCondChanged;
102 
103  //! \return true to be cleared.
104  virtual bool onCondChangedImpl(const Snapshot &shot, XValueNodeBase *) const = 0;
105  //! [Hz]
106  virtual double getFreqResHint(const Snapshot &shot_this) const = 0;
107  //! [Hz]
108  virtual double getMinFreq(const Snapshot &shot_this) const = 0;
109  //! [Hz]
110  virtual double getMaxFreq(const Snapshot &shot_this) const = 0;
111  //! [Hz]
112  virtual double getCurrentCenterFreq(const Snapshot &shot_this, const Snapshot &shot_others) const = 0;
113  virtual void rearrangeInstrum(const Snapshot &) {}
114  virtual void getValues(const Snapshot &shot_this, std::vector<double> &values) const = 0;
115  virtual bool checkDependencyImpl(const Snapshot &shot_this,
116  const Snapshot &shot_emitter, const Snapshot &shot_others,
117  XDriver *emitter) const = 0;
118 private:
119  //! Fourier Step Summation.
120  void fssum(Transaction &tr, const Snapshot &shot_pulse, const Snapshot &shot_others);
121  void analyzeIFT(Transaction &tr, const Snapshot &shot_pulse);
122 
123  const shared_ptr<XItemNode<XDriverList, XNMRPulseAnalyzer> > m_pulse;
124 
125  const shared_ptr<XDoubleNode> m_bandWidth;
126  const shared_ptr<XComboNode> m_bwList;
127  const shared_ptr<XBoolNode> m_autoPhase;
128  const shared_ptr<XDoubleNode> m_phase;
129  const shared_ptr<XTouchableNode> m_clear;
130  const shared_ptr<XComboNode> m_solverList;
131  const shared_ptr<XComboNode> m_windowFunc;
132  const shared_ptr<XDoubleNode> m_windowWidth;
133 
134  std::deque<xqcon_ptr> m_conBaseUIs;
135 
136  shared_ptr<SpectrumSolverWrapper> m_solver;
137  shared_ptr<XXYPlot> m_peakPlot;
138 
139  void onCondChanged(const Snapshot &shot, XValueNodeBase *);
140 
141  atomic<int> m_isInstrumControlRequested;
142 protected:
143  const qshared_ptr<FRM> m_form;
144  const shared_ptr<XStatusPrinter> m_statusPrinter;
145  const shared_ptr<XWaveNGraph> m_spectrum;
146  void onClear(const Snapshot &shot, XTouchableNode *);
147 };
148 
149 #endif

Generated for KAME4 by  doxygen 1.8.3