OpenMS
Loading...
Searching...
No Matches
SpectrumSettings.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: Marc Sturm, Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
22
23#include <functional>
24#include <map>
25#include <vector>
26
27namespace OpenMS
28{
41 class OPENMS_DLLAPI SpectrumSettings :
43 {
44
45public:
46
48 enum class SpectrumType
49 {
50 UNKNOWN,
51 CENTROID,
52 PROFILE,
53 SIZE_OF_SPECTRUMTYPE
54 };
56 static const std::string NamesOfSpectrumType[static_cast<size_t>(SpectrumType::SIZE_OF_SPECTRUMTYPE)];
57
60
63 static const std::string& spectrumTypeToString(SpectrumType type);
64
67 static SpectrumType toSpectrumType(const std::string& name);
68
70 SpectrumSettings() = default;
74 SpectrumSettings(SpectrumSettings&&) noexcept = default;
76 ~SpectrumSettings() noexcept = default;
77
78 // Assignment operator
79 SpectrumSettings & operator=(const SpectrumSettings &) = default;
81 SpectrumSettings& operator=(SpectrumSettings&&) & = default;
82
84 bool operator==(const SpectrumSettings & rhs) const;
86 bool operator!=(const SpectrumSettings & rhs) const;
87
89 void unify(const SpectrumSettings & rhs);
90
92 SpectrumType getType() const;
94 void setType(SpectrumType type);
95
98 void setIMFormat(const IMFormat& im_type);
99
104 IMFormat getIMFormat() const;
105
108 void setIMPeakType(IMPeakType im_peak_type);
109
112 IMPeakType getIMPeakType() const;
113
115 const String & getNativeID() const;
117 void setNativeID(const String & native_id);
118
120 const String & getComment() const;
122 void setComment(const String & comment);
123
125 const InstrumentSettings & getInstrumentSettings() const;
127 InstrumentSettings & getInstrumentSettings();
129 void setInstrumentSettings(const InstrumentSettings & instrument_settings);
130
132 const AcquisitionInfo & getAcquisitionInfo() const;
134 AcquisitionInfo & getAcquisitionInfo();
136 void setAcquisitionInfo(const AcquisitionInfo & acquisition_info);
137
139 const SourceFile & getSourceFile() const;
141 SourceFile & getSourceFile();
143 void setSourceFile(const SourceFile & source_file);
144
146 const std::vector<Precursor> & getPrecursors() const;
148 std::vector<Precursor> & getPrecursors();
150 void setPrecursors(const std::vector<Precursor> & precursors);
151
153 const std::vector<Product> & getProducts() const;
155 std::vector<Product> & getProducts();
157 void setProducts(const std::vector<Product> & products);
158
160 void setDataProcessing(const std::vector< DataProcessingPtr > & data_processing);
161
163 std::vector< DataProcessingPtr > & getDataProcessing();
164
166 const std::vector< std::shared_ptr<const DataProcessing > > getDataProcessing() const;
167
168protected:
169
170 SpectrumType type_ = SpectrumType::UNKNOWN;
171 IMFormat im_type_ = IMFormat::UNKNOWN;
172 IMPeakType im_peak_type_ = IMPeakType::UNKNOWN;
173 String native_id_;
174 String comment_;
175 InstrumentSettings instrument_settings_;
176 SourceFile source_file_;
177 AcquisitionInfo acquisition_info_;
178 std::vector<Precursor> precursors_;
179 std::vector<Product> products_;
180 std::vector< DataProcessingPtr > data_processing_;
181 };
182
184 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const SpectrumSettings & spec);
185
186} // namespace OpenMS
187
188namespace std
189{
210 template<>
211 struct hash<OpenMS::SpectrumSettings>
212 {
213 std::size_t operator()(const OpenMS::SpectrumSettings& s) const noexcept
214 {
215 std::size_t seed = 0;
216
217 // Hash type_ (enum)
218 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getType())));
219
220 // Hash native_id_ (String)
221 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getNativeID()));
222
223 // Hash comment_ (String)
224 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getComment()));
225
226 // Hash instrument_settings_ (all fields from operator==)
227 const auto& is = s.getInstrumentSettings();
228 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanMode())));
229 OpenMS::hash_combine(seed, OpenMS::hash_int(is.getZoomScan() ? 1 : 0));
230 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getPolarity())));
231 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanWindows().size())));
232 for (const auto& sw : is.getScanWindows())
233 {
236 }
237 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(is));
238
239 // Hash acquisition_info_ (all fields from operator==)
240 const auto& ai = s.getAcquisitionInfo();
241 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(ai.getMethodOfCombination()));
242 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(ai));
243 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(ai.size())));
244 for (const auto& acq : ai)
245 {
246 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(acq.getIdentifier()));
247 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(acq));
248 }
249
250 // Hash source_file_ (all fields from operator==, including CVTermList base)
251 const auto& sf = s.getSourceFile();
253 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNameOfFile()));
254 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getPathToFile()));
255 OpenMS::hash_combine(seed, OpenMS::hash_float(sf.getFileSize()));
256 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getFileType()));
257 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getChecksum()));
258 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(sf.getChecksumType())));
259 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDType()));
260 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDTypeAccession()));
261
262 // Hash precursors_ (using std::hash<Precursor>)
263 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getPrecursors().size())));
264 for (const auto& p : s.getPrecursors())
265 {
266 OpenMS::hash_combine(seed, std::hash<OpenMS::Precursor>{}(p));
267 }
268
269 // Hash products_ (using std::hash<Product>)
270 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getProducts().size())));
271 for (const auto& p : s.getProducts())
272 {
273 OpenMS::hash_combine(seed, std::hash<OpenMS::Product>{}(p));
274 }
275
276 // Hash data_processing_ (dereferenced contents)
277 const auto dp = s.getDataProcessing();
278 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(dp.size())));
279 for (const auto& dp_ptr : dp)
280 {
281 if (dp_ptr)
282 {
283 // Hash Software name and version
284 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getName()));
285 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getVersion()));
286 // Hash processing actions
287 for (const auto& action : dp_ptr->getProcessingActions())
288 {
289 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(action)));
290 }
291 // Hash completion time
292 OpenMS::hash_combine(seed, std::hash<OpenMS::DateTime>{}(dp_ptr->getCompletionTime()));
293 }
294 }
295
296 // Hash MetaInfoInterface base class
297 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(s));
298
299 return seed;
300 }
301 };
302} // namespace std
303
Description of the combination of raw data to a single spectrum.
Definition AcquisitionInfo.h:29
Description of the applied preprocessing steps.
Definition DataProcessing.h:28
Description of the settings a MS Instrument was run with.
Definition InstrumentSettings.h:24
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:36
Precursor meta information.
Definition Precursor.h:37
Product meta information.
Definition Product.h:26
Description of a file location, used to store the origin of (meta) data.
Definition SourceFile.h:23
Representation of 1D spectrum settings.
Definition SpectrumSettings.h:43
SpectrumSettings()=default
Constructor.
SpectrumSettings(SpectrumSettings &&) noexcept=default
Move constructor.
SpectrumSettings(const SpectrumSettings &)=default
Copy constructor.
SpectrumType
Spectrum peak type.
Definition SpectrumSettings.h:49
static const std::string & spectrumTypeToString(SpectrumType type)
static SpectrumType toSpectrumType(const std::string &name)
static StringList getAllNamesOfSpectrumType()
returns all spectrum type names known to OpenMS
A more convenient string class.
Definition String.h:32
@ UNKNOWN
Unknown or unrecognized ion type.
std::vector< String > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
IMFormat
Definition IMTypes.h:47
std::size_t hashCVTermList(const CVTermList &cvtl) noexcept
Definition TargetedExperimentHelper.h:657
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
IMPeakType
Definition IMTypes.h:67
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
std::size_t fnv1a_hash_string(const std::string &s) noexcept
FNV-1a hash for a string.
Definition HashUtils.h:70
std::shared_ptr< DataProcessing > DataProcessingPtr
Definition DataProcessing.h:123
STL namespace.
std::size_t operator()(const OpenMS::SpectrumSettings &s) const noexcept
Definition SpectrumSettings.h:213