OpenMS
MzDataHandler.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Marc Sturm $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
17 
18 #include <sstream>
19 
20 namespace OpenMS
21 {
22  namespace Internal
23  {
33  typedef PeakMap MapType;
36 
37  class OPENMS_DLLAPI MzDataHandler :
38  public XMLHandler
39  {
40 public:
44  MzDataHandler(MapType & exp, const String & filename, const String & version, ProgressLogger & logger);
45 
47  MzDataHandler(const MapType & exp, const String & filename, const String & version, const ProgressLogger & logger);
48 
50  ~MzDataHandler() override
51  {
52  }
53 
55 
56 
57  // Docu in base class
58  void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
59 
60  // Docu in base class
61  void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
62 
63  // Docu in base class
64  void characters(const XMLCh * const chars, const XMLSize_t length) override;
65 
67  void writeTo(std::ostream & os) override;
68 
70  void setOptions(const PeakFileOptions & options)
71  {
72  options_ = options;
73  }
74 
75 private:
76  void init_();
77 
78 protected:
79 
84 
88  const MapType * cexp_;
89 
92 
100  std::vector<std::pair<String, MetaInfoDescription> > meta_id_descs_;
102  std::vector<String> data_to_decode_;
104  std::vector<float> data_to_encode_;
105  std::vector<std::vector<float> > decoded_list_;
106  std::vector<std::vector<double> > decoded_double_list_;
107  std::vector<String> precisions_;
108  std::vector<String> endians_;
110 
113 
116 
118  void fillData_();
119 
121 
122 
133  inline void writeCVS_(std::ostream & os, double value, const String & acc, const String & name, UInt indent = 4) const;
134 
146  inline void writeCVS_(std::ostream & os, const String & value, const String & acc, const String & name, UInt indent = 4) const;
147 
161  inline void writeCVS_(std::ostream & os, UInt value, UInt map, const String & acc, const String & name, UInt indent = 4);
162 
164  inline void writeUserParam_(std::ostream & os, const MetaInfoInterface & meta, UInt indent = 4);
165 
173  void cvParam_(const String & name, const String & value);
175 
181  inline void writeBinary_(std::ostream & os, Size size, const String & tag, const String & name = "", SignedSize id = -1);
182 
183  //Data processing auxiliary variable
184  boost::shared_ptr< DataProcessing > data_processing_;
185 
186  };
187 
188  //--------------------------------------------------------------------------------
189  } // namespace Internal
190 
191 } // namespace OpenMS
192 
Definition: MzDataHandler.h:39
void writeCVS_(std::ostream &os, double value, const String &acc, const String &name, UInt indent=4) const
write cvParam containing strings to stream
std::vector< String > data_to_decode_
encoded data which is read and has to be decoded
Definition: MzDataHandler.h:102
std::vector< std::vector< double > > decoded_double_list_
Definition: MzDataHandler.h:106
UInt peak_count_
The number of peaks in the current spectrum (according to the length attribute – which should not be ...
Definition: MzDataHandler.h:96
std::vector< String > endians_
Definition: MzDataHandler.h:108
~MzDataHandler() override
Destructor.
Definition: MzDataHandler.h:50
boost::shared_ptr< DataProcessing > data_processing_
Definition: MzDataHandler.h:184
MzDataHandler(MapType &exp, const String &filename, const String &version, ProgressLogger &logger)
Constructor for a write-only handler.
MapType * exp_
map pointer for reading
Definition: MzDataHandler.h:86
void cvParam_(const String &name, const String &value)
read attributes of MzData's cvParamType
void setOptions(const PeakFileOptions &options)
Sets the options.
Definition: MzDataHandler.h:70
void writeTo(std::ostream &os) override
Writes the contents to a stream.
MzDataHandler(const MapType &exp, const String &filename, const String &version, const ProgressLogger &logger)
Constructor for a read-only handler.
const ProgressLogger & logger_
Progress logger.
Definition: MzDataHandler.h:115
std::vector< float > data_to_encode_
floating point numbers which have to be encoded and written
Definition: MzDataHandler.h:104
SpectrumType spec_
The current spectrum.
Definition: MzDataHandler.h:98
MSSpectrum SpectrumType
Spectrum type.
Definition: MzDataHandler.h:83
PeakFileOptions options_
Options that can be set for loading/storing.
Definition: MzDataHandler.h:91
MapType::PeakType PeakType
Peak type.
Definition: MzDataHandler.h:81
bool skip_spectrum_
Flag that indicates whether this spectrum should be skipped (due to options)
Definition: MzDataHandler.h:112
std::vector< std::vector< float > > decoded_list_
Definition: MzDataHandler.h:105
void writeCVS_(std::ostream &os, const String &value, const String &acc, const String &name, UInt indent=4) const
write cvParam containing strings to stream
void writeCVS_(std::ostream &os, UInt value, UInt map, const String &acc, const String &name, UInt indent=4)
write cvParam element to stream
void writeBinary_(std::ostream &os, Size size, const String &tag, const String &name="", SignedSize id=-1)
write binary data to stream (first one)
void startElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname, const xercesc::Attributes &attributes) override
std::vector< std::pair< String, MetaInfoDescription > > meta_id_descs_
An array of pairs MetaInfodescriptions and their ids.
Definition: MzDataHandler.h:100
std::vector< String > precisions_
Definition: MzDataHandler.h:107
void characters(const XMLCh *const chars, const XMLSize_t length) override
void endElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname) override
void writeUserParam_(std::ostream &os, const MetaInfoInterface &meta, UInt indent=4)
Writing the MetaInfo as UserParam to the file.
void fillData_()
fills the current spectrum with peaks and meta data
const MapType * cexp_
map pointer for writing
Definition: MzDataHandler.h:88
Base class for XML handlers.
Definition: XMLHandler.h:302
The representation of a chromatogram.
Definition: MSChromatogram.h:30
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:45
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:35
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:28
Options for loading files containing peak data.
Definition: PeakFileOptions.h:22
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:104
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
MSChromatogram ChromatogramType
Definition: MzDataHandler.h:35
MSSpectrum SpectrumType
Definition: MzDataHandler.h:34
PeakMap MapType
XML handler for MzDataFile.
Definition: MzDataHandler.h:33
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19