Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
00036 #define OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
00037
00038 #include <OpenMS/KERNEL/StandardTypes.h>
00039 #include <OpenMS/KERNEL/MSSpectrum.h>
00040 #include <OpenMS/DATASTRUCTURES/SparseVector.h>
00041 #include <OpenMS/CONCEPT/Exception.h>
00042
00043
00044 #include <cmath>
00045
00046 namespace OpenMS
00047 {
00048
00066 class OPENMS_DLLAPI BinnedSpectrum :
00067 public MSSpectrum<>
00068 {
00069
00070 private:
00071
00072 UInt bin_spread_;
00073 Real bin_size_;
00074 SparseVector<Real> bins_;
00075
00076 public:
00077
00082 class OPENMS_DLLAPI NoSpectrumIntegrated :
00083 public Exception::BaseException
00084 {
00085 public:
00086 NoSpectrumIntegrated(const char * file, int line, const char * function, const char * message = "BinnedSpectrum hasn't got a PeakSpectrum to base on yet") throw();
00087
00088 virtual ~NoSpectrumIntegrated() throw();
00089 };
00090
00091 typedef SparseVector<Real>::const_iterator const_bin_iterator;
00092 typedef SparseVector<Real>::iterator bin_iterator;
00093
00095 BinnedSpectrum();
00096
00098 BinnedSpectrum(Real size, UInt spread, PeakSpectrum ps);
00099
00101 BinnedSpectrum(const BinnedSpectrum & source);
00102
00104 virtual ~BinnedSpectrum();
00105
00107 BinnedSpectrum & operator=(const BinnedSpectrum & source)
00108 {
00109 if (&source != this)
00110 {
00111 setBinSize(source.getBinSize());
00112 setBinSpread(source.getBinSpread());
00113 bins_ = source.getBins();
00114 MSSpectrum<>::operator=(source);
00115 }
00116 return *this;
00117 }
00118
00120 BinnedSpectrum & operator=(const PeakSpectrum & source)
00121 {
00122 if (!MSSpectrum<>::operator==(source))
00123 {
00124 MSSpectrum<>::operator=(source);
00125 setBinning();
00126 }
00127 return *this;
00128 }
00129
00131 bool operator==(const BinnedSpectrum & rhs) const
00132 {
00133 return MSSpectrum<>::operator==(rhs) &&
00134 rhs.getBinSize() == this->bin_size_ &&
00135 rhs.getBinSpread() == this->bin_spread_;
00136 }
00137
00139 bool operator!=(const BinnedSpectrum & rhs) const
00140 {
00141 return !(operator==(rhs));
00142 }
00143
00145 bool operator==(const PeakSpectrum & rhs) const
00146 {
00147 return MSSpectrum<>::operator==(rhs);
00148 }
00149
00151 bool operator!=(const PeakSpectrum & rhs) const
00152 {
00153 return !(operator==(rhs));
00154 }
00155
00157 inline double getBinSize() const
00158 {
00159 return this->bin_size_;
00160 }
00161
00163 inline UInt getBinSpread() const
00164 {
00165 return this->bin_spread_;
00166 }
00167
00169 inline UInt getBinNumber() const
00170 {
00171 return (UInt) this->bins_.size();
00172 }
00173
00175 inline UInt getFilledBinNumber() const
00176 {
00177 return (UInt) this->bins_.nonzero_size();
00178 }
00179
00184 inline const SparseVector<Real> & getBins() const
00185 {
00186 if (bins_.empty())
00187 {
00188 throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00189 }
00190 return bins_;
00191 }
00192
00197 inline SparseVector<Real> & getBins()
00198 {
00199 if (bins_.empty())
00200 {
00201 try
00202 {
00203 this->setBinning();
00204 }
00205 catch (...)
00206 {
00207 throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00208 }
00209 }
00210 return bins_;
00211 }
00212
00214 inline const_bin_iterator begin() const
00215 {
00216 return bins_.begin();
00217 }
00218
00220 inline const_bin_iterator end() const
00221 {
00222 return bins_.end();
00223 }
00224
00226 inline bin_iterator begin()
00227 {
00228 return bins_.begin();
00229 }
00230
00232 inline bin_iterator end()
00233 {
00234 return bins_.end();
00235 }
00236
00242 inline void setBinSize(double s)
00243 {
00244 if (this->bin_size_ != s)
00245 {
00246 this->bin_size_ = s;
00247 try
00248 {
00249 this->setBinning();
00250 }
00251 catch (...)
00252 {
00253 throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00254 }
00255 }
00256 }
00257
00263 inline void setBinSpread(UInt s)
00264 {
00265 if (this->bin_spread_ != s)
00266 {
00267 this->bin_spread_ = s;
00268 try
00269 {
00270 this->setBinning();
00271 }
00272 catch (...)
00273 {
00274 throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
00275 }
00276 }
00277 }
00278
00283 void setBinning();
00284
00286 bool checkCompliance(const BinnedSpectrum & bs) const;
00287
00288
00289 protected:
00290
00291 virtual void clearChildIds_()
00292 {
00293
00294 }
00295
00296 };
00297
00298 }
00299 #endif //OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H