OpenMS
SpectrumRangeManager.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: Administrator $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 #include <map>
14 #include <set>
15 
16 namespace OpenMS
17 {
18  class MSSpectrum; // Forward declaration for MSSpectrum
43  class OPENMS_DLLAPI SpectrumRangeManager : public RangeManager<RangeMZ, RangeIntensity, RangeMobility, RangeRT>
44  {
45  public:
48 
50  SpectrumRangeManager() = default;
51 
53  SpectrumRangeManager(const SpectrumRangeManager& source) = default;
54 
57 
60 
63 
65  ~SpectrumRangeManager() = default;
66 
70  void clearRanges()
71  {
72  BaseType::clearRanges();
73  ms_level_ranges_.clear();
74  }
75 
82  void extend(const BaseType& other, UInt ms_level = 0)
83  {
84  ms_level == 0 ? BaseType::extend(other) : ms_level_ranges_[ms_level].extend(other);
85  }
86 
94  const BaseType& byMSLevel(UInt ms_level = 0) const
95  {
96  if (auto it = ms_level_ranges_.find(ms_level); it != ms_level_ranges_.end())
97  {
98  return it->second;
99  }
100  throw Exception::InvalidValue(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "No ranges for this MS level", String(ms_level));
101  }
102 
108  std::set<UInt> getMSLevels() const
109  {
110  std::set<UInt> ms_levels;
111  for (const auto& [level, _] : ms_level_ranges_)
112  {
113  ms_levels.insert(level);
114  }
115  return ms_levels;
116  }
117 
124  void extendRT(double rt, UInt ms_level = 0)
125  {
126  ms_level == 0 ? BaseType::extendRT(rt) : ms_level_ranges_[ms_level].extendRT(rt);
127  }
128 
135  void extendMZ(double mz, UInt ms_level = 0)
136  {
137  ms_level == 0 ? BaseType::extendMZ(mz) : ms_level_ranges_[ms_level].extendMZ(mz);
138  }
139 
146  void extendUnsafe(const MSSpectrum& spectrum, UInt ms_level = 0)
147  {
148  ms_level == 0 ? BaseType::extendUnsafe(spectrum.getRange()) : ms_level_ranges_[ms_level].extendUnsafe(spectrum.getRange());
149  }
150 
151  protected:
153  std::map<UInt, BaseType> ms_level_ranges_;
154  };
155 
156 } // namespace OpenMS
Invalid value exception.
Definition: Exception.h:305
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:901
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:568
Advanced range manager for MS spectra with separate ranges for each MS level.
Definition: SpectrumRangeManager.h:44
void extendMZ(double mz, UInt ms_level=0)
Extends the m/z range with an MS level parameter.
Definition: SpectrumRangeManager.h:135
void extend(const BaseType &other, UInt ms_level=0)
Extends the ranges with the ranges of another range manager.
Definition: SpectrumRangeManager.h:82
SpectrumRangeManager(const SpectrumRangeManager &source)=default
Copy constructor.
std::set< UInt > getMSLevels() const
Gets all MS levels for which specific ranges exist.
Definition: SpectrumRangeManager.h:108
SpectrumRangeManager & operator=(SpectrumRangeManager &&source)=default
Move assignment operator.
~SpectrumRangeManager()=default
Destructor.
void extendUnsafe(const MSSpectrum &spectrum, UInt ms_level=0)
Extends the ranges with the ranges of a spectrum using an MS level parameter.
Definition: SpectrumRangeManager.h:146
SpectrumRangeManager(SpectrumRangeManager &&source)=default
Move constructor.
SpectrumRangeManager()=default
Default constructor.
void clearRanges()
Clears all ranges (global and MS level-specific)
Definition: SpectrumRangeManager.h:70
std::map< UInt, BaseType > ms_level_ranges_
MS level-specific ranges.
Definition: SpectrumRangeManager.h:153
void extendRT(double rt, UInt ms_level=0)
Extends the RT range with an MS level parameter.
Definition: SpectrumRangeManager.h:124
SpectrumRangeManager & operator=(const SpectrumRangeManager &source)=default
Assignment operator.
const BaseType & byMSLevel(UInt ms_level=0) const
Gets the ranges for a specific MS level.
Definition: SpectrumRangeManager.h:94
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19