OpenMS
Loading...
Searching...
No Matches
FeatureHandle.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: $
7// --------------------------------------------------------------------------
8
9#pragma once
10
15#include <OpenMS/OpenMSConfig.h>
16
17#include <functional>
18#include <iosfwd>
19#include <vector>
20
21namespace OpenMS
22{
23 class BaseFeature;
24
33 class OPENMS_DLLAPI FeatureHandle :
34 public Peak2D,
36 {
37
38public:
40
42
43
44 typedef Int ChargeType;
46 typedef float WidthType;
48
50
51
53
55 FeatureHandle(UInt64 map_index, const Peak2D& point, UInt64 element_index);
56
58 FeatureHandle(UInt64 map_index, const BaseFeature& feature);
59
62
65
67 ~FeatureHandle() override;
68
84 FeatureHandleMutable_& asMutable() const;
86
88
89
91
94
96 void setCharge(ChargeType charge);
97
100
102 void setWidth(WidthType width);
103
106
108
110 bool operator==(const FeatureHandle& i) const;
111
113 bool operator!=(const FeatureHandle& i) const;
114
117 {
118 bool operator()(FeatureHandle const& left, FeatureHandle const& right) const;
119 };
120
121protected:
122
128 float width_;
129 };
130
139 public FeatureHandle
140 {
141private:
142 using FeatureHandle::setUniqueId;
143 using FeatureHandle::setMapIndex;
146 };
147
149 {
150 // the const cast is to remove constness, but note that FeatureHandleMutable_ lacks some mutators
151 // TODO use const_cast
152 return static_cast<FeatureHandleMutable_&>(const_cast<FeatureHandle&>(*this));
153 }
154
155 inline bool FeatureHandle::IndexLess::operator()(FeatureHandle const& left, FeatureHandle const& right) const
156 {
157 // if map indices are equal, use unique ids
158 if (left.map_index_ == right.map_index_)
159 {
160 return left.getUniqueId() < right.getUniqueId();
161 }
162 //else use map indices
163 return left.map_index_ < right.map_index_;
164 }
165
167 OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const FeatureHandle& cons);
168} // namespace OpenMS
169
170// Hash function specialization for FeatureHandle
171namespace std
172{
173 template<>
174 struct hash<OpenMS::FeatureHandle>
175 {
176 std::size_t operator()(const OpenMS::FeatureHandle& fh) const noexcept
177 {
178 // Hash Peak2D base class components
179 std::size_t seed = OpenMS::hash_float(fh.getRT());
180 OpenMS::hash_combine(seed, OpenMS::hash_float(fh.getMZ()));
181 OpenMS::hash_combine(seed, OpenMS::hash_float(fh.getIntensity()));
182 // Hash UniqueIdInterface component
183 OpenMS::hash_combine(seed, OpenMS::hash_int(fh.getUniqueId()));
184 // Hash FeatureHandle-specific members
185 OpenMS::hash_combine(seed, OpenMS::hash_int(fh.getMapIndex()));
186 OpenMS::hash_combine(seed, OpenMS::hash_int(fh.getCharge()));
187 OpenMS::hash_combine(seed, OpenMS::hash_float(fh.getWidth()));
188 return seed;
189 }
190 };
191} // namespace std
192
A basic LC-MS feature.
Definition BaseFeature.h:34
Helper class returned by FeatureHandle::asMutable(), which see.
Definition FeatureHandle.h:140
FeatureHandleMutable_(const FeatureHandleMutable_ &)
Representation of a Peak2D, RichPeak2D or Feature .
Definition FeatureHandle.h:36
FeatureHandle(UInt64 map_index, const BaseFeature &feature)
Constructor from map index and basic feature.
bool operator!=(const FeatureHandle &i) const
Equality operator.
bool operator==(const FeatureHandle &i) const
Equality operator.
FeatureHandle()
Default constructor.
UInt64 map_index_
Index of the element's container.
Definition FeatureHandle.h:124
UInt64 getMapIndex() const
Returns the map index.
FeatureHandleMutable_ & asMutable() const
Override (most of all) constness.
Definition FeatureHandle.h:148
float WidthType
Feature width type.
Definition FeatureHandle.h:46
void setMapIndex(UInt64 i)
Set the map index.
void setWidth(WidthType width)
Sets the width (FWHM)
FeatureHandle(const FeatureHandle &rhs)
Copy constructor.
WidthType getWidth() const
Returns the width (FWHM)
Int ChargeType
Charge type.
Definition FeatureHandle.h:44
~FeatureHandle() override
Destructor.
ChargeType getCharge() const
Returns the charge.
FeatureHandle & operator=(const FeatureHandle &rhs)
Assignment operator.
float width_
Width of the feature (FWHM)
Definition FeatureHandle.h:128
FeatureHandle(UInt64 map_index, const Peak2D &point, UInt64 element_index)
Constructor with map index, element index and position.
void setCharge(ChargeType charge)
Sets the charge.
Int charge_
Charge of the feature.
Definition FeatureHandle.h:126
A 2-dimensional raw data point or peak.
Definition Peak2D.h:30
friend std::ostream & operator<<(std::ostream &os, const Peak2D &point)
Print the contents to a stream.
A base class defining a common interface for all classes having a unique id.
Definition UniqueIdInterface.h:25
UInt64 getUniqueId() const
Non-mutable access to unique id - returns the unique id.
Definition UniqueIdInterface.h:78
int Int
Signed integer type.
Definition Types.h:72
uint64_t UInt64
Unsigned integer type (64bit)
Definition Types.h:47
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
std::size_t hash_float(T value) noexcept
Hash for a floating point type (float or double).
Definition HashUtils.h:142
STL namespace.
Comparator by map and unique id.
Definition FeatureHandle.h:117
bool operator()(FeatureHandle const &left, FeatureHandle const &right) const
Definition FeatureHandle.h:155
std::size_t operator()(const OpenMS::FeatureHandle &fh) const noexcept
Definition FeatureHandle.h:176