Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MSDataCachedConsumer.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-2017.
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_DATAACCESS_MSDATACACHEDCONSUMER_H
36 #define OPENMS_FORMAT_DATAACCESS_MSDATACACHEDCONSUMER_H
37 
39 
43 
45 
46 namespace OpenMS
47 {
55  class OPENMS_DLLAPI MSDataCachedConsumer :
56  public CachedmzML,
58  {
61 
62  public:
63 
69  MSDataCachedConsumer(String filename, bool clearData=true) :
70  ofs_(filename.c_str(), std::ios::binary),
71  clearData_(clearData),
72  spectra_written_(0),
73  chromatograms_written_(0)
74  {
75  int file_identifier = CACHED_MZML_FILE_IDENTIFIER;
76  ofs_.write((char*)&file_identifier, sizeof(file_identifier));
77  }
78 
85  {
86  // Write size of file (to the end of the file)
87  ofs_.write((char*)&spectra_written_, sizeof(spectra_written_));
88  ofs_.write((char*)&chromatograms_written_, sizeof(chromatograms_written_));
89 
90  // Close file stream: close() _should_ call flush() but it might not in
91  // all cases. To be sure call flush() first.
92  ofs_.flush();
93  ofs_.close();
94  }
95 
99  void consumeSpectrum(SpectrumType & s)
100  {
101  if (chromatograms_written_ > 0)
102  {
103  throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
104  "Cannot write spectra after writing chromatograms.");
105  }
106  writeSpectrum_(s, ofs_);
107  spectra_written_++;
108  if (clearData_) {s.clear(false);}
109  }
110 
114  void consumeChromatogram(ChromatogramType & c)
115  {
116  writeChromatogram_(c, ofs_);
117  chromatograms_written_++;
118  if (clearData_) {c.clear(false);}
119  }
120 
121  void setExpectedSize(Size /* expectedSpectra */, Size /* expectedChromatograms */) {;}
122 
124 
125  protected:
126  std::ofstream ofs_;
130 
131  };
132 
133 } //end namespace OpenMS
134 
135 #endif
Size spectra_written_
Definition: MSDataCachedConsumer.h:128
A more convenient string class.
Definition: String.h:57
The representation of a chromatogram.
Definition: MSChromatogram.h:55
Size chromatograms_written_
Definition: MSDataCachedConsumer.h:129
~MSDataCachedConsumer()
Destructor.
Definition: MSDataCachedConsumer.h:84
STL namespace.
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:55
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
MSDataCachedConsumer(String filename, bool clearData=true)
Constructor.
Definition: MSDataCachedConsumer.h:69
std::ofstream ofs_
Definition: MSDataCachedConsumer.h:126
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
A method or algorithm argument contains illegal values.
Definition: Exception.h:649
MSSpectrum SpectrumType
Definition: MSDataCachedConsumer.h:59
void clear(bool clear_meta_data)
Clears all data and meta data.
void consumeChromatogram(ChromatogramType &c)
Write a chromatogram to the output file.
Definition: MSDataCachedConsumer.h:114
void setExperimentalSettings(const ExperimentalSettings &)
Set experimental settings (meta-data) of the data to be consumed.
Definition: MSDataCachedConsumer.h:123
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:64
MSChromatogram ChromatogramType
Definition: MSDataCachedConsumer.h:60
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:68
void setExpectedSize(Size, Size)
Set expected size of spectra and chromatograms to be consumed.
Definition: MSDataCachedConsumer.h:121
bool clearData_
Definition: MSDataCachedConsumer.h:127
#define CACHED_MZML_FILE_IDENTIFIER
Definition: CachedMzML.h:50
void clear(bool clear_meta_data)
Clears all data and meta data.
void consumeSpectrum(SpectrumType &s)
Write a spectrum to the output file.
Definition: MSDataCachedConsumer.h:99
Description of the experimental settings.
Definition: ExperimentalSettings.h:59

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13