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
107 const String & getNativeID() const;
109 void setNativeID(const String & native_id);
110
112 const String & getComment() const;
114 void setComment(const String & comment);
115
117 const InstrumentSettings & getInstrumentSettings() const;
119 InstrumentSettings & getInstrumentSettings();
121 void setInstrumentSettings(const InstrumentSettings & instrument_settings);
122
124 const AcquisitionInfo & getAcquisitionInfo() const;
126 AcquisitionInfo & getAcquisitionInfo();
128 void setAcquisitionInfo(const AcquisitionInfo & acquisition_info);
129
131 const SourceFile & getSourceFile() const;
133 SourceFile & getSourceFile();
135 void setSourceFile(const SourceFile & source_file);
136
138 const std::vector<Precursor> & getPrecursors() const;
140 std::vector<Precursor> & getPrecursors();
142 void setPrecursors(const std::vector<Precursor> & precursors);
143
145 const std::vector<Product> & getProducts() const;
147 std::vector<Product> & getProducts();
149 void setProducts(const std::vector<Product> & products);
150
152 void setDataProcessing(const std::vector< DataProcessingPtr > & data_processing);
153
155 std::vector< DataProcessingPtr > & getDataProcessing();
156
158 const std::vector< std::shared_ptr<const DataProcessing > > getDataProcessing() const;
159
160protected:
161
162 SpectrumType type_ = SpectrumType::UNKNOWN;
163 IMFormat im_type_ = IMFormat::UNKNOWN;
164 String native_id_;
165 String comment_;
166 InstrumentSettings instrument_settings_;
167 SourceFile source_file_;
168 AcquisitionInfo acquisition_info_;
169 std::vector<Precursor> precursors_;
170 std::vector<Product> products_;
171 std::vector< DataProcessingPtr > data_processing_;
172 };
173
175 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const SpectrumSettings & spec);
176
177} // namespace OpenMS
178
179namespace std
180{
201 template<>
202 struct hash<OpenMS::SpectrumSettings>
203 {
204 std::size_t operator()(const OpenMS::SpectrumSettings& s) const noexcept
205 {
206 std::size_t seed = 0;
207
208 // Hash type_ (enum)
209 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getType())));
210
211 // Hash native_id_ (String)
212 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getNativeID()));
213
214 // Hash comment_ (String)
215 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getComment()));
216
217 // Hash instrument_settings_ (all fields from operator==)
218 const auto& is = s.getInstrumentSettings();
219 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanMode())));
220 OpenMS::hash_combine(seed, OpenMS::hash_int(is.getZoomScan() ? 1 : 0));
221 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getPolarity())));
222 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanWindows().size())));
223 for (const auto& sw : is.getScanWindows())
224 {
227 }
228 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(is));
229
230 // Hash acquisition_info_ (all fields from operator==)
231 const auto& ai = s.getAcquisitionInfo();
232 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(ai.getMethodOfCombination()));
233 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(ai));
234 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(ai.size())));
235 for (const auto& acq : ai)
236 {
237 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(acq.getIdentifier()));
238 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(acq));
239 }
240
241 // Hash source_file_ (all fields from operator==, including CVTermList base)
242 const auto& sf = s.getSourceFile();
244 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNameOfFile()));
245 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getPathToFile()));
246 OpenMS::hash_combine(seed, OpenMS::hash_float(sf.getFileSize()));
247 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getFileType()));
248 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getChecksum()));
249 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(sf.getChecksumType())));
250 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDType()));
251 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDTypeAccession()));
252
253 // Hash precursors_ (using std::hash<Precursor>)
254 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getPrecursors().size())));
255 for (const auto& p : s.getPrecursors())
256 {
257 OpenMS::hash_combine(seed, std::hash<OpenMS::Precursor>{}(p));
258 }
259
260 // Hash products_ (using std::hash<Product>)
261 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getProducts().size())));
262 for (const auto& p : s.getProducts())
263 {
264 OpenMS::hash_combine(seed, std::hash<OpenMS::Product>{}(p));
265 }
266
267 // Hash data_processing_ (dereferenced contents)
268 const auto dp = s.getDataProcessing();
269 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(dp.size())));
270 for (const auto& dp_ptr : dp)
271 {
272 if (dp_ptr)
273 {
274 // Hash Software name and version
275 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getName()));
276 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getVersion()));
277 // Hash processing actions
278 for (const auto& action : dp_ptr->getProcessingActions())
279 {
280 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(action)));
281 }
282 // Hash completion time
283 OpenMS::hash_combine(seed, std::hash<OpenMS::DateTime>{}(dp_ptr->getCompletionTime()));
284 }
285 }
286
287 // Hash MetaInfoInterface base class
288 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(s));
289
290 return seed;
291 }
292 };
293} // namespace std
294
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:34
@ 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:49
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
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:204