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
23
24#include <functional>
25#include <map>
26#include <vector>
27
28namespace OpenMS
29{
42 class OPENMS_DLLAPI SpectrumSettings :
44 {
45
46public:
47
50 {
54 SIZE_OF_SPECTRUMTYPE
55 };
57 static const std::string NamesOfSpectrumType[SIZE_OF_SPECTRUMTYPE];
58
61
64 static const std::string& spectrumTypeToString(SpectrumType type);
65
68 static SpectrumType toSpectrumType(const std::string& name);
69
71 SpectrumSettings() = default;
75 SpectrumSettings(SpectrumSettings&&) noexcept = default;
77 ~SpectrumSettings() noexcept = default;
78
79 // Assignment operator
80 SpectrumSettings & operator=(const SpectrumSettings &) = default;
82 SpectrumSettings& operator=(SpectrumSettings&&) & = default;
83
85 bool operator==(const SpectrumSettings & rhs) const;
87 bool operator!=(const SpectrumSettings & rhs) const;
88
90 void unify(const SpectrumSettings & rhs);
91
93 SpectrumType getType() const;
95 void setType(SpectrumType type);
96
99 void setIMFormat(const IMFormat& im_type);
100
105 IMFormat getIMFormat() const;
106
108 const String & getNativeID() const;
110 void setNativeID(const String & native_id);
111
113 const String & getComment() const;
115 void setComment(const String & comment);
116
118 const InstrumentSettings & getInstrumentSettings() const;
120 InstrumentSettings & getInstrumentSettings();
122 void setInstrumentSettings(const InstrumentSettings & instrument_settings);
123
125 const AcquisitionInfo & getAcquisitionInfo() const;
127 AcquisitionInfo & getAcquisitionInfo();
129 void setAcquisitionInfo(const AcquisitionInfo & acquisition_info);
130
132 const SourceFile & getSourceFile() const;
134 SourceFile & getSourceFile();
136 void setSourceFile(const SourceFile & source_file);
137
139 const std::vector<Precursor> & getPrecursors() const;
141 std::vector<Precursor> & getPrecursors();
143 void setPrecursors(const std::vector<Precursor> & precursors);
144
146 const std::vector<Product> & getProducts() const;
148 std::vector<Product> & getProducts();
150 void setProducts(const std::vector<Product> & products);
151
153 void setDataProcessing(const std::vector< DataProcessingPtr > & data_processing);
154
156 std::vector< DataProcessingPtr > & getDataProcessing();
157
159 const std::vector< std::shared_ptr<const DataProcessing > > getDataProcessing() const;
160
161protected:
162
163 SpectrumType type_ = UNKNOWN;
164 IMFormat im_type_ = IMFormat::UNKNOWN;
165 String native_id_;
166 String comment_;
167 InstrumentSettings instrument_settings_;
168 SourceFile source_file_;
169 AcquisitionInfo acquisition_info_;
170 std::vector<Precursor> precursors_;
171 std::vector<Product> products_;
172 std::vector< DataProcessingPtr > data_processing_;
173 };
174
176 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const SpectrumSettings & spec);
177
178} // namespace OpenMS
179
180namespace std
181{
202 template<>
203 struct hash<OpenMS::SpectrumSettings>
204 {
205 std::size_t operator()(const OpenMS::SpectrumSettings& s) const noexcept
206 {
207 std::size_t seed = 0;
208
209 // Hash type_ (enum)
210 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getType())));
211
212 // Hash native_id_ (String)
213 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getNativeID()));
214
215 // Hash comment_ (String)
216 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(s.getComment()));
217
218 // Hash instrument_settings_ (all fields from operator==)
219 const auto& is = s.getInstrumentSettings();
220 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanMode())));
221 OpenMS::hash_combine(seed, OpenMS::hash_int(is.getZoomScan() ? 1 : 0));
222 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getPolarity())));
223 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(is.getScanWindows().size())));
224 for (const auto& sw : is.getScanWindows())
225 {
228 }
229 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(is));
230
231 // Hash acquisition_info_ (all fields from operator==)
232 const auto& ai = s.getAcquisitionInfo();
233 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(ai.getMethodOfCombination()));
234 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(ai));
235 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(ai.size())));
236 for (const auto& acq : ai)
237 {
238 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(acq.getIdentifier()));
239 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(acq));
240 }
241
242 // Hash source_file_ (all fields from operator==, including CVTermList base)
243 const auto& sf = s.getSourceFile();
245 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNameOfFile()));
246 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getPathToFile()));
247 OpenMS::hash_combine(seed, OpenMS::hash_float(sf.getFileSize()));
248 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getFileType()));
249 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getChecksum()));
250 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(sf.getChecksumType())));
251 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDType()));
252 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(sf.getNativeIDTypeAccession()));
253
254 // Hash precursors_ (using std::hash<Precursor>)
255 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getPrecursors().size())));
256 for (const auto& p : s.getPrecursors())
257 {
258 OpenMS::hash_combine(seed, std::hash<OpenMS::Precursor>{}(p));
259 }
260
261 // Hash products_ (using std::hash<Product>)
262 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(s.getProducts().size())));
263 for (const auto& p : s.getProducts())
264 {
265 OpenMS::hash_combine(seed, std::hash<OpenMS::Product>{}(p));
266 }
267
268 // Hash data_processing_ (dereferenced contents)
269 const auto dp = s.getDataProcessing();
270 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(dp.size())));
271 for (const auto& dp_ptr : dp)
272 {
273 if (dp_ptr)
274 {
275 // Hash Software name and version
276 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getName()));
277 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(dp_ptr->getSoftware().getVersion()));
278 // Hash processing actions
279 for (const auto& action : dp_ptr->getProcessingActions())
280 {
281 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(action)));
282 }
283 // Hash completion time
284 OpenMS::hash_combine(seed, std::hash<OpenMS::DateTime>{}(dp_ptr->getCompletionTime()));
285 }
286 }
287
288 // Hash MetaInfoInterface base class
289 OpenMS::hash_combine(seed, std::hash<OpenMS::MetaInfoInterface>{}(s));
290
291 return seed;
292 }
293 };
294} // namespace std
295
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:44
SpectrumSettings()=default
Constructor.
SpectrumSettings(SpectrumSettings &&) noexcept=default
Move constructor.
SpectrumSettings(const SpectrumSettings &)=default
Copy constructor.
SpectrumType
Spectrum peak type.
Definition SpectrumSettings.h:50
@ UNKNOWN
Unknown spectrum type.
Definition SpectrumSettings.h:51
@ PROFILE
profile data
Definition SpectrumSettings.h:53
@ CENTROID
centroid data or stick data
Definition SpectrumSettings.h:52
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
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:48
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:205