OpenMS
Loading...
Searching...
No Matches
Weights.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Anton Pervukhin <Anton.Pervukhin@CeBiTec.Uni-Bielefeld.DE> $
7// --------------------------------------------------------------------------
8//
9
10#pragma once
11
12#include <vector>
13#include <iosfwd>
14
15#include <OpenMS/config.h>
16
17namespace OpenMS
18{
19 namespace ims
20 {
43 class OPENMS_DLLAPI Weights
44 {
45public:
47 typedef long unsigned int weight_type;
48
50 typedef double alphabet_mass_type;
51
53 typedef std::vector<weight_type> weights_type;
54
56 typedef std::vector<alphabet_mass_type> alphabet_masses_type;
57
59 typedef weights_type::size_type size_type;
60
68
81 Weights(const alphabet_masses_type & masses, alphabet_mass_type precision) :
82 alphabet_masses_(masses),
83 precision_(precision)
84 {
85 setPrecision(precision);
86 }
87
93 Weights(const Weights & other) :
94 alphabet_masses_(other.alphabet_masses_),
95 precision_(other.precision_),
96 weights_(other.weights_) {}
97
104 Weights & operator=(const Weights & other);
105
112 {
113 return weights_.size();
114 }
115
125 {
126 checkIndex_(i);
127 return weights_[i];
128 }
129
138
145 {
146 return precision_;
147 }
148
160 {
161 checkIndex_(i);
162 return weights_[i];
163 }
164
173 {
174 checkIndex_(0);
175 return weights_.back();
176 }
177
187 {
188 checkIndex_(i);
189 return alphabet_masses_[i];
190 }
191
203 alphabet_mass_type getParentMass(const std::vector<unsigned int> & decomposition) const;
204
217 void swap(size_type index1, size_type index2);
218
233
242
251private:
254 void checkIndex_(size_type i) const
255 {
256 if (i >= weights_.size())
257 {
258 throwIndexOverflow_(i);
259 }
260 }
261
262 [[noreturn]] void throwIndexOverflow_(size_type i) const;
263
268
273
278 };
279
287 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const Weights & weights);
288
289 } // namespace ims
290} // namespace OpenMS
291
Pairs an alphabet of double-valued masses with the scaled integer weights derived from them.
Definition Weights.h:44
void swap(size_type index1, size_type index2)
Exchange the alphabet mass and the integer weight at index1 with those at index2.
alphabet_mass_type getMinRoundingError() const
Largest negative relative rounding error introduced by the current precision.
weights_type weights_
Definition Weights.h:277
alphabet_masses_type alphabet_masses_
Definition Weights.h:267
alphabet_mass_type precision_
Definition Weights.h:272
void setPrecision(alphabet_mass_type precision)
Replace the precision and recompute the integer weights from the stored alphabet masses.
alphabet_mass_type getMaxRoundingError() const
Largest positive relative rounding error introduced by the current precision.
Weights(const Weights &other)
Definition Weights.h:93
size_type size() const
Definition Weights.h:111
Weights(const alphabet_masses_type &masses, alphabet_mass_type precision)
Construct from a set of masses and a precision.
Definition Weights.h:81
weight_type back() const
Definition Weights.h:172
alphabet_mass_type getParentMass(const std::vector< unsigned int > &decomposition) const
Reconstruct a parent mass from a decomposition expressed as multiplicities of the alphabet.
void throwIndexOverflow_(size_type i) const
weight_type operator[](size_type i) const
Definition Weights.h:159
Weights & operator=(const Weights &other)
double alphabet_mass_type
Type of double values to be used.
Definition Weights.h:50
bool divideByGCD()
Divide every integer weight by the greatest common divisor of all weights and scale the precision acc...
weight_type getWeight(size_type i) const
Definition Weights.h:124
std::vector< alphabet_mass_type > alphabet_masses_type
Type of container to store double values.
Definition Weights.h:56
long unsigned int weight_type
Type of integer values to be used.
Definition Weights.h:47
std::vector< weight_type > weights_type
Type of container to store integer values.
Definition Weights.h:53
Weights()
Default constructor.
Definition Weights.h:67
weights_type::size_type size_type
Type of container's size.
Definition Weights.h:59
alphabet_mass_type getPrecision() const
Definition Weights.h:144
alphabet_mass_type getAlphabetMass(size_type i) const
Definition Weights.h:186
void checkIndex_(size_type i) const
Definition Weights.h:254
std::ostream & operator<<(std::ostream &os, const IMSAlphabet &alphabet)
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19