OpenMS
MzMLHandlerHelper.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
40 
41 #include <vector>
42 
43 namespace OpenMS
44 {
45  namespace Internal
46  {
47 
55  class OPENMS_DLLAPI MzMLHandlerHelper
56  {
57 
59  static void warning(int mode, const String & msg, UInt line = 0, UInt column = 0);
60 
61  public:
62 
69  struct BinaryData
70  {
71  // ordered by size (alignment) and cache hotness in 'decode'
72 
73  enum {
76  PRE_64
77  } precision;
78 
79  enum {
83  DT_STRING
84  } data_type;
85 
87 
88  bool compression;
89  double unit_multiplier;
90 
93  std::vector<float> floats_32;
94  std::vector<double> floats_64;
95  std::vector<Int32> ints_32;
96  std::vector<Int64> ints_64;
97  std::vector<String> decoded_char;
98 
100 
103  precision(PRE_NONE),
104  data_type(DT_NONE),
105  np_compression(),
106  compression(false),
107  unit_multiplier(1.0),
108  base64(),
109  size(0),
110  floats_32(),
111  floats_64(),
112  ints_32(),
113  ints_64(),
114  decoded_char(),
115  meta()
116  {
117  }
118 
119  BinaryData(const BinaryData&) = default; // Copy constructor
120  BinaryData(BinaryData&&) = default; // Move constructor
121  BinaryData& operator=(const BinaryData&) & = default; // Copy assignment operator
122  BinaryData& operator=(BinaryData&&) & = default; // Move assignment operator
123  ~BinaryData() = default; // Destructor
124 
125  };
126 
131  MSNumpressCoder::NumpressConfig np_compression,
132  const String& indent = "",
133  bool use_numpress = false);
134 
144  static void writeFooter_(std::ostream& os,
145  const PeakFileOptions& options,
146  const std::vector< std::pair<std::string, Int64> > & spectra_offsets,
147  const std::vector< std::pair<std::string, Int64> > & chromatograms_offsets);
148 
155  static void decodeBase64Arrays(std::vector<BinaryData> & data_, const bool skipXMLCheck = false);
156 
167  static void computeDataProperties_(const std::vector<BinaryData>& data_, bool& precision_64, SignedSize& index, const String& index_name);
168 
182  static bool handleBinaryDataArrayCVParam(std::vector<BinaryData>& data_,
183  const String& accession,
184  const String& value,
185  const String& name,
186  const String& unit_accession);
187  };
188 
189 
190  } // namespace Internal
191 } // namespace OpenMS
192 
193 
Helper for mzML file format.
Definition: MzMLHandlerHelper.h:56
static void computeDataProperties_(const std::vector< BinaryData > &data_, bool &precision_64, SignedSize &index, const String &index_name)
Identify a data array from a list.
static void writeFooter_(std::ostream &os, const PeakFileOptions &options, const std::vector< std::pair< std::string, Int64 > > &spectra_offsets, const std::vector< std::pair< std::string, Int64 > > &chromatograms_offsets)
Write the indexed mzML footer the appropriate compression term given the PeakFileOptions and the Nump...
static void decodeBase64Arrays(std::vector< BinaryData > &data_, const bool skipXMLCheck=false)
Decode Base64 arrays and write into data_ array.
static void warning(int mode, const String &msg, UInt line=0, UInt column=0)
Also display some warning message when appropriate (see XMLHandler)
static bool handleBinaryDataArrayCVParam(std::vector< BinaryData > &data_, const String &accession, const String &value, const String &name, const String &unit_accession)
Handle a given CV parameter found in a binaryDataArray tag.
static String getCompressionTerm_(const PeakFileOptions &opt, MSNumpressCoder::NumpressConfig np_compression, const String &indent="", bool use_numpress=false)
Returns the appropriate compression term given the PeakFileOptions and the NumpressConfig.
NumpressCompression
Names of compression schemes.
Definition: MSNumpressCoder.h:74
Description of the meta data arrays of MSSpectrum.
Definition: MetaInfoDescription.h:50
Options for loading files containing peak data.
Definition: PeakFileOptions.h:48
A more convenient string class.
Definition: String.h:60
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Representation for binary data in mzML.
Definition: MzMLHandlerHelper.h:70
double unit_multiplier
multiplier for unit (e.g. 60 for minutes)
Definition: MzMLHandlerHelper.h:89
std::vector< Int32 > ints_32
Definition: MzMLHandlerHelper.h:95
@ PRE_32
32bit precision
Definition: MzMLHandlerHelper.h:75
@ PRE_NONE
unknown precision
Definition: MzMLHandlerHelper.h:74
std::vector< float > floats_32
Definition: MzMLHandlerHelper.h:93
bool compression
zlib compression
Definition: MzMLHandlerHelper.h:88
Size size
Raw data length.
Definition: MzMLHandlerHelper.h:92
std::vector< String > decoded_char
Definition: MzMLHandlerHelper.h:97
String base64
Raw data in base64 encoding.
Definition: MzMLHandlerHelper.h:91
BinaryData()
Constructor.
Definition: MzMLHandlerHelper.h:102
MetaInfoDescription meta
Meta data description.
Definition: MzMLHandlerHelper.h:99
std::vector< Int64 > ints_64
Definition: MzMLHandlerHelper.h:96
std::vector< double > floats_64
Definition: MzMLHandlerHelper.h:94
BinaryData & operator=(BinaryData &&) &=default
@ DT_NONE
unknown data type
Definition: MzMLHandlerHelper.h:80
@ DT_FLOAT
float data type
Definition: MzMLHandlerHelper.h:81
@ DT_INT
integer data type
Definition: MzMLHandlerHelper.h:82
BinaryData & operator=(const BinaryData &) &=default
MSNumpressCoder::NumpressCompression np_compression
numpress options
Definition: MzMLHandlerHelper.h:86
Configuration class for MSNumpress.
Definition: MSNumpressCoder.h:89