Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
BinnedSpectrum.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Mathias Walzer $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 //
35 #ifndef OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
36 #define OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
37 
42 
43 
44 #include <cmath>
45 
46 namespace OpenMS
47 {
48 
66  class OPENMS_DLLAPI BinnedSpectrum :
67  public MSSpectrum<>
68  {
69 
70 private:
71 
75 
76 public:
77 
82  class OPENMS_DLLAPI NoSpectrumIntegrated :
84  {
85 public:
86  NoSpectrumIntegrated(const char * file, int line, const char * function, const char * message = "BinnedSpectrum hasn't got a PeakSpectrum to base on yet") throw();
87 
88  virtual ~NoSpectrumIntegrated() throw();
89  };
90 
93 
96 
98  BinnedSpectrum(Real size, UInt spread, PeakSpectrum ps);
99 
101  BinnedSpectrum(const BinnedSpectrum & source);
102 
104  virtual ~BinnedSpectrum();
105 
108  {
109  if (&source != this)
110  {
111  setBinSize(source.getBinSize());
112  setBinSpread(source.getBinSpread());
113  bins_ = source.getBins();
114  MSSpectrum<>::operator=(source);
115  }
116  return *this;
117  }
118 
121  {
122  if (!MSSpectrum<>::operator==(source))
123  {
124  MSSpectrum<>::operator=(source);
125  setBinning();
126  }
127  return *this;
128  }
129 
131  bool operator==(const BinnedSpectrum & rhs) const
132  {
133  return MSSpectrum<>::operator==(rhs) &&
134  rhs.getBinSize() == this->bin_size_ &&
135  rhs.getBinSpread() == this->bin_spread_;
136  }
137 
139  bool operator!=(const BinnedSpectrum & rhs) const
140  {
141  return !(operator==(rhs));
142  }
143 
145  bool operator==(const PeakSpectrum & rhs) const
146  {
147  return MSSpectrum<>::operator==(rhs);
148  }
149 
151  bool operator!=(const PeakSpectrum & rhs) const
152  {
153  return !(operator==(rhs));
154  }
155 
157  inline double getBinSize() const
158  {
159  return this->bin_size_;
160  }
161 
163  inline UInt getBinSpread() const
164  {
165  return this->bin_spread_;
166  }
167 
169  inline UInt getBinNumber() const
170  {
171  return (UInt) this->bins_.size();
172  }
173 
175  inline UInt getFilledBinNumber() const
176  {
177  return (UInt) this->bins_.nonzero_size();
178  }
179 
184  inline const SparseVector<Real> & getBins() const
185  {
186  if (bins_.empty())
187  {
188  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
189  }
190  return bins_;
191  }
192 
198  {
199  if (bins_.empty())
200  {
201  try
202  {
203  this->setBinning();
204  }
205  catch (...)
206  {
207  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
208  }
209  }
210  return bins_;
211  }
212 
214  inline const_bin_iterator begin() const
215  {
216  return bins_.begin();
217  }
218 
220  inline const_bin_iterator end() const
221  {
222  return bins_.end();
223  }
224 
227  {
228  return bins_.begin();
229  }
230 
232  inline bin_iterator end()
233  {
234  return bins_.end();
235  }
236 
242  inline void setBinSize(double s)
243  {
244  if (this->bin_size_ != s)
245  {
246  this->bin_size_ = s;
247  try
248  {
249  this->setBinning();
250  }
251  catch (...)
252  {
253  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
254  }
255  }
256  }
257 
263  inline void setBinSpread(UInt s)
264  {
265  if (this->bin_spread_ != s)
266  {
267  this->bin_spread_ = s;
268  try
269  {
270  this->setBinning();
271  }
272  catch (...)
273  {
274  throw BinnedSpectrum::NoSpectrumIntegrated(__FILE__, __LINE__, __PRETTY_FUNCTION__);
275  }
276  }
277  }
278 
283  void setBinning();
284 
286  bool checkCompliance(const BinnedSpectrum & bs) const;
287 
288 
289 protected:
290  // docu in base class
291  virtual void clearChildIds_()
292  {
293  //TODO Persistence
294  }
295 
296  };
297 
298 }
299 #endif //OPENMS_COMPARISON_SPECTRA_BINNEDSPECTRUM_H
MSSpectrum & operator=(const MSSpectrum &source)
Assignment operator.
Definition: MSSpectrum.h:166
float Real
Real type.
Definition: Types.h:109
void setBinSize(double s)
Definition: BinnedSpectrum.h:242
bool operator==(const MSSpectrum &rhs) const
Equality operator.
Definition: MSSpectrum.h:186
double getBinSize() const
get the BinSize
Definition: BinnedSpectrum.h:157
SparseVector< Real > bins_
Definition: BinnedSpectrum.h:74
Real bin_size_
Definition: BinnedSpectrum.h:73
UInt bin_spread_
Definition: BinnedSpectrum.h:72
bin_iterator end()
returns the end iterator of the container
Definition: BinnedSpectrum.h:232
bool operator==(const BinnedSpectrum &rhs) const
equality operator
Definition: BinnedSpectrum.h:131
BinnedSpectrum & operator=(const PeakSpectrum &source)
assignment operator for PeakSpectra
Definition: BinnedSpectrum.h:120
SparseVector< Real > & getBins()
Definition: BinnedSpectrum.h:197
bool operator!=(const BinnedSpectrum &rhs) const
inequality operator
Definition: BinnedSpectrum.h:139
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
UInt getFilledBinNumber() const
get the FilledBinNumber, number of filled Bins
Definition: BinnedSpectrum.h:175
bin_iterator begin()
returns the begin iterator of the container
Definition: BinnedSpectrum.h:226
UInt getBinSpread() const
get the BinSpread
Definition: BinnedSpectrum.h:163
BinnedSpectrum & operator=(const BinnedSpectrum &source)
assignment operator
Definition: BinnedSpectrum.h:107
SparseVector< Real >::const_iterator const_bin_iterator
Definition: BinnedSpectrum.h:91
bool operator!=(const PeakSpectrum &rhs) const
inequality operator for PeakSpectra
Definition: BinnedSpectrum.h:151
SparseVector< Real >::iterator bin_iterator
Definition: BinnedSpectrum.h:92
const_bin_iterator end() const
returns the const end iterator of the container
Definition: BinnedSpectrum.h:220
Exception base class.
Definition: Exception.h:90
void setBinSpread(UInt s)
Definition: BinnedSpectrum.h:263
This is a binned representation of a PeakSpectrum.
Definition: BinnedSpectrum.h:66
virtual void clearChildIds_()
Clears the persistence id of all sub-objects.
Definition: BinnedSpectrum.h:291
bool operator==(const PeakSpectrum &rhs) const
equality operator for PeakSpectra
Definition: BinnedSpectrum.h:145
UInt getBinNumber() const
get the BinNumber, number of Bins
Definition: BinnedSpectrum.h:169
const SparseVector< Real > & getBins() const
Definition: BinnedSpectrum.h:184
Exception which is thrown if BinnedSpectrum bins are accessed and no PeakSpektrum has been integrated...
Definition: BinnedSpectrum.h:82
const_bin_iterator begin() const
returns the const begin iterator of the container
Definition: BinnedSpectrum.h:214

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:11 using doxygen 1.8.5