Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

BinnedSpectrum.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Mathias Walzer $
00032 // $Authors: $
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     // docu in base class
00291     virtual void clearChildIds_()
00292     {
00293       //TODO Persistence
00294     }
00295 
00296   };
00297 
00298 }
00299 #endif //OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:37 using doxygen 1.7.1