Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
CachedMzML.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-2015.
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 #ifndef OPENMS_FORMAT_CACHEDMZML_H
36 #define OPENMS_FORMAT_CACHEDMZML_H
37 
39 
40 #include <OpenMS/CONCEPT/Types.h>
42 
44 #include <OpenMS/FORMAT/MzMLFile.h>
45 
46 #include <fstream>
47 
48 #define CACHED_MZML_FILE_IDENTIFIER 8093
49 
50 namespace OpenMS
51 {
52 
62  class OPENMS_DLLAPI CachedmzML :
63  public ProgressLogger
64  {
66  double dbl_field_;
67 
68 public:
69 
73 
74  // using double precision to store all data (has to agree with type of BinaryDataArrayPtr)
75  typedef double DatumSingleton;
76 
77  typedef std::vector<DatumSingleton> Datavector;
78 
82  CachedmzML();
84 
86  ~CachedmzML();
87 
89  CachedmzML& operator=(const CachedmzML& rhs);
91 
95 
97  void writeMemdump(MapType& exp, String out);
98 
100  void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false);
101 
103  void readMemdump(MapType& exp_reading, String filename) const;
105 
109  void createMemdumpIndex(String filename);
111 
113  const std::vector<std::streampos>& getSpectraIndex() const;
114 
116  const std::vector<std::streampos>& getChromatogramIndex() const;
118 
122 
129  OpenSwath::BinaryDataArrayPtr data2, std::ifstream& ifs, int& ms_level,
130  double& rt)
131  {
132  Size spec_size = -1;
133  ifs.read((char*) &spec_size, sizeof(spec_size));
134  ifs.read((char*) &ms_level, sizeof(ms_level));
135  ifs.read((char*) &rt, sizeof(rt));
136 
137  if ( static_cast<int>(spec_size) < 0)
138  {
139  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__,
140  "Read an invalid spectrum length, something is wrong here. Aborting.", "filestream");
141  }
142 
143  data1->data.resize(spec_size);
144  data2->data.resize(spec_size);
145 
146  if (spec_size > 0)
147  {
148  ifs.read((char*) &(data1->data)[0], spec_size * sizeof(double));
149  ifs.read((char*) &(data2->data)[0], spec_size * sizeof(double));
150  }
151  }
152 
159  OpenSwath::BinaryDataArrayPtr data2, std::ifstream& ifs)
160  {
161  Size spec_size = -1;
162  ifs.read((char*) &spec_size, sizeof(spec_size));
163 
164  if ( static_cast<int>(spec_size) < 0)
165  {
166  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__,
167  "Read an invalid chromatogram length, something is wrong here. Aborting.", "filestream");
168  }
169 
170  data1->data.resize(spec_size);
171  data2->data.resize(spec_size);
172  ifs.read((char*) &(data1->data)[0], spec_size * sizeof(double));
173  ifs.read((char*) &(data2->data)[0], spec_size * sizeof(double));
174  }
176 
177 protected:
178 
180  void readSpectrum_(Datavector& data1, Datavector& data2, std::ifstream& ifs, int& ms_level, double& rt) const;
181 
183  void readChromatogram_(Datavector& data1, Datavector& data2, std::ifstream& ifs) const;
184 
186  void readSpectrum_(SpectrumType& spectrum, std::ifstream& ifs) const;
187 
189  void readChromatogram_(ChromatogramType& chromatogram, std::ifstream& ifs) const;
190 
192  void writeSpectrum_(const SpectrumType& spectrum, std::ofstream& ofs);
193 
195  void writeChromatogram_(const ChromatogramType& chromatogram, std::ofstream& ofs);
196 
198  std::vector<std::streampos> spectra_index_;
199  std::vector<std::streampos> chrom_index_;
200 
201  };
202 }
203 #endif
MSSpectrum< Peak1D > SpectrumType
Definition: CachedMzML.h:71
A more convenient string class.
Definition: String.h:57
The representation of a chromatogram.
Definition: MSChromatogram.h:52
double DatumSingleton
Definition: CachedMzML.h:75
std::vector< std::streampos > chrom_index_
Definition: CachedMzML.h:199
MSChromatogram< ChromatogramPeak > ChromatogramType
Definition: CachedMzML.h:72
MSExperiment< Peak1D > MapType
Definition: CachedMzML.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openswathalgo/include/OpenMS/ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/DataStructures.h:77
std::vector< DatumSingleton > Datavector
Definition: CachedMzML.h:77
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:62
static void readChromatogramFast(OpenSwath::BinaryDataArrayPtr data1, OpenSwath::BinaryDataArrayPtr data2, std::ifstream &ifs)
fast access to a chromatogram (a direct copy of the data into the provided arrays) ...
Definition: CachedMzML.h:158
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
double dbl_field_
Definition: CachedMzML.h:66
int int_field_
Definition: CachedMzML.h:65
std::vector< std::streampos > spectra_index_
Members.
Definition: CachedMzML.h:198
static void readSpectrumFast(OpenSwath::BinaryDataArrayPtr data1, OpenSwath::BinaryDataArrayPtr data2, std::ifstream &ifs, int &ms_level, double &rt)
fast access to a spectrum (a direct copy of the data into the provided arrays)
Definition: CachedMzML.h:128
Parse Error exception.
Definition: Exception.h:608

OpenMS / TOPP release 2.0.0 Documentation generated on Sat May 16 2015 16:13:15 using doxygen 1.8.9.1