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
21
22#include <functional>
23#include <map>
24#include <vector>
25
26namespace OpenMS
27{
40 class OPENMS_DLLAPI SpectrumSettings :
42 {
43
44public:
45
47 enum class SpectrumType
48 {
49 UNKNOWN,
50 CENTROID,
51 PROFILE,
52 SIZE_OF_SPECTRUMTYPE
53 };
55 static const std::string NamesOfSpectrumType[static_cast<size_t>(SpectrumType::SIZE_OF_SPECTRUMTYPE)];
56
59
62 static const std::string& spectrumTypeToString(SpectrumType type);
63
66 static SpectrumType toSpectrumType(const std::string& name);
67
69 SpectrumSettings() = default;
73 SpectrumSettings(SpectrumSettings&&) noexcept = default;
75 ~SpectrumSettings() noexcept = default;
76
77 // Assignment operator
78 SpectrumSettings & operator=(const SpectrumSettings &) = default;
80 SpectrumSettings& operator=(SpectrumSettings&&) & = default;
81
83 bool operator==(const SpectrumSettings & rhs) const;
85 bool operator!=(const SpectrumSettings & rhs) const;
86
88 void unify(const SpectrumSettings & rhs);
89
91 SpectrumType getType() const;
93 void setType(SpectrumType type);
94
97 void setIMFormat(const IMFormat& im_type);
98
103 IMFormat getIMFormat() const;
104
107 void setIMPeakType(IMPeakType im_peak_type);
108
111 IMPeakType getIMPeakType() const;
112
114 const std::string & getNativeID() const;
116 void setNativeID(const std::string & native_id);
117
119 const std::string & getComment() const;
121 void setComment(const std::string & comment);
122
124 const InstrumentSettings & getInstrumentSettings() const;
126 InstrumentSettings & getInstrumentSettings();
128 void setInstrumentSettings(const InstrumentSettings & instrument_settings);
129
131 const AcquisitionInfo & getAcquisitionInfo() const;
133 AcquisitionInfo & getAcquisitionInfo();
135 void setAcquisitionInfo(const AcquisitionInfo & acquisition_info);
136
138 const SourceFile & getSourceFile() const;
140 SourceFile & getSourceFile();
142 void setSourceFile(const SourceFile & source_file);
143
145 const std::vector<Precursor> & getPrecursors() const;
147 std::vector<Precursor> & getPrecursors();
149 void setPrecursors(const std::vector<Precursor> & precursors);
150
152 const std::vector<Product> & getProducts() const;
154 std::vector<Product> & getProducts();
156 void setProducts(const std::vector<Product> & products);
157
159 void setDataProcessing(const std::vector< DataProcessingPtr > & data_processing);
160
162 std::vector< DataProcessingPtr > & getDataProcessing();
163
165 const std::vector< std::shared_ptr<const DataProcessing > > getDataProcessing() const;
166
167protected:
168
169 SpectrumType type_ = SpectrumType::UNKNOWN;
170 IMFormat im_type_ = IMFormat::UNKNOWN;
171 IMPeakType im_peak_type_ = IMPeakType::UNKNOWN;
172 std::string native_id_;
173 std::string comment_;
174 InstrumentSettings instrument_settings_;
175 SourceFile source_file_;
176 AcquisitionInfo acquisition_info_;
177 std::vector<Precursor> precursors_;
178 std::vector<Product> products_;
179 std::vector< DataProcessingPtr > data_processing_;
180 };
181
183 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const SpectrumSettings & spec);
184
185} // namespace OpenMS
186
187namespace std
188{
209 template<>
210 struct hash<OpenMS::SpectrumSettings>
211 {
212 std::size_t operator()(const OpenMS::SpectrumSettings& s) const noexcept
213 {
214 std::size_t seed = 0;
215
216 // Hash type_ (enum)
217 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getType())));
218
219 // Hash native_id_ (String)
220 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getNativeID()));
221
222 // Hash comment_ (String)
223 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getComment()));
224
225 // Hash instrument_settings_ (all fields from operator==)
226 const auto& is = s.getInstrumentSettings();
227 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanMode())));
228 OpenMS::hash_combine(seed, OpenMS::hash_int(is.getZoomScan() ? 1 : 0));
229 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getPolarity())));
230 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanWindows().size())));
231 for (const auto& sw : is.getScanWindows())
232 {
235 }
236 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(is));
237
238 // Hash acquisition_info_ (all fields from operator==)
239 const auto& ai = s.getAcquisitionInfo();
240 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(ai.getMethodOfCombination()));
241 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(ai));
242 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(ai.size())));
243 for (const auto& acq : ai)
244 {
245 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(acq.getIdentifier()));
246 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(acq));
247 }
248
249 // Hash source_file_ (all fields from operator==, including CVTermList base)
250 const auto& sf = s.getSourceFile();
252 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNameOfFile()));
253 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getPathToFile()));
254 OpenMS::hash_combine(seed, OpenMS::hash_float(sf.getFileSize()));
255 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getFileType()));
256 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getChecksum()));
257 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(sf.getChecksumType())));
258 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDType()));
259 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDTypeAccession()));
260
261 // Hash precursors_ (using std::hash<Precursor>)
262 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getPrecursors().size())));
263 for (const auto& p : s.getPrecursors())
264 {
265 OpenMS::hash_combine(seed, std::hash<OpenMS::Precursor>{}(p));
266 }
267
268 // Hash products_ (using std::hash<Product>)
269 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getProducts().size())));
270 for (const auto& p : s.getProducts())
271 {
272 OpenMS::hash_combine(seed, std::hash<OpenMS::Product>{}(p));
273 }
274
275 // Hash data_processing_ (dereferenced contents)
276 const auto dp = s.getDataProcessing();
277 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(dp.size())));
278 for (const auto& dp_ptr : dp)
279 {
280 if (dp_ptr)
281 {
282 // Hash Software name and version
283 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getName()));
284 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getVersion()));
285 // Hash processing actions
286 for (const auto& action : dp_ptr->getProcessingActions())
287 {
288 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(action)));
289 }
290 // Hash completion time
291 OpenMS::hash_combine(seed, std::hash<OpenMS::DateTime>{}(dp_ptr->getCompletionTime()));
292 }
293 }
294
295 // Hash MetaInfoInterface base class
296 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(s));
297
298 return seed;
299 }
300 };
301} // namespace std
302
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:35
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:42
SpectrumSettings()=default
Constructor.
SpectrumSettings(SpectrumSettings &&) noexcept=default
Move constructor.
SpectrumSettings(const SpectrumSettings &)=default
Copy constructor.
SpectrumType
Spectrum peak type.
Definition SpectrumSettings.h:48
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
@ UNKNOWN
Unknown or unrecognized ion type.
std::vector< std::string > StringList
Vector of String.
Definition TypeAliases.h:39
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 CVTermList.h:139
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:212