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-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_DATAACCESS_MSDATACACHEDCONSUMER_H
36 #define OPENMS_FORMAT_DATAACCESS_MSDATACACHEDCONSUMER_H
37 
39 
41 
42 namespace OpenMS
43 {
51  class OPENMS_DLLAPI MSDataCachedConsumer :
52  public CachedmzML,
54  {
58 
59  public:
60 
66  MSDataCachedConsumer(String filename, bool clearData=true) :
67  ofs_(filename.c_str(), std::ios::binary),
68  clearData_(clearData),
69  spectra_written_(0),
70  chromatograms_written_(0)
71  {
72  int file_identifier = CACHED_MZML_FILE_IDENTIFIER;
73  ofs_.write((char*)&file_identifier, sizeof(file_identifier));
74  }
75 
82  {
83  // Write size of file (to the end of the file)
84  ofs_.write((char*)&spectra_written_, sizeof(spectra_written_));
85  ofs_.write((char*)&chromatograms_written_, sizeof(chromatograms_written_));
86 
87  // Close file stream: close() _should_ call flush() but it might not in
88  // all cases. To be sure call flush() first.
89  ofs_.flush();
90  ofs_.close();
91  }
92 
96  void consumeSpectrum(SpectrumType & s)
97  {
98  if (chromatograms_written_ > 0)
99  {
100  throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__,
101  "Cannot write spectra after writing chromatograms.");
102  }
103  writeSpectrum_(s, ofs_);
104  spectra_written_++;
105  if (clearData_) {s.clear(false);}
106  }
107 
111  void consumeChromatogram(ChromatogramType & c)
112  {
113  writeChromatogram_(c, ofs_);
114  chromatograms_written_++;
115  if (clearData_) {c.clear(false);}
116  }
117 
118  void setExpectedSize(Size /* expectedSpectra */, Size /* expectedChromatograms */) {;}
119 
121 
122  protected:
123  std::ofstream ofs_;
127 
128  };
129 
130 } //end namespace OpenMS
131 
132 #endif
Size spectra_written_
Definition: MSDataCachedConsumer.h:125
A more convenient string class.
Definition: String.h:57
Size chromatograms_written_
Definition: MSDataCachedConsumer.h:126
~MSDataCachedConsumer()
Destructor.
Definition: MSDataCachedConsumer.h:81
STL namespace.
MapType::SpectrumType SpectrumType
Definition: MSDataCachedConsumer.h:56
Transforming and cached writing consumer of MS data.
Definition: MSDataCachedConsumer.h:51
const double c
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
MSDataCachedConsumer(String filename, bool clearData=true)
Constructor.
Definition: MSDataCachedConsumer.h:66
std::ofstream ofs_
Definition: MSDataCachedConsumer.h:123
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
MSExperiment MapType
Definition: MSDataCachedConsumer.h:55
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSSpectrum.h:635
void consumeChromatogram(ChromatogramType &c)
Write a chromatogram to the output file.
Definition: MSDataCachedConsumer.h:111
void setExperimentalSettings(const ExperimentalSettings &)
Set experimental settings (meta-data) of the data to be consumed.
Definition: MSDataCachedConsumer.h:120
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:62
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:68
MapType::ChromatogramType ChromatogramType
Definition: MSDataCachedConsumer.h:57
void setExpectedSize(Size, Size)
Set expected size of spectra and chromatograms to be consumed.
Definition: MSDataCachedConsumer.h:118
bool clearData_
Definition: MSDataCachedConsumer.h:124
#define CACHED_MZML_FILE_IDENTIFIER
Definition: CachedMzML.h:48
void clear(bool clear_meta_data)
Clears all data and meta data.
Definition: MSChromatogram.h:587
void consumeSpectrum(SpectrumType &s)
Write a spectrum to the output file.
Definition: MSDataCachedConsumer.h:96
Description of the experimental settings.
Definition: ExperimentalSettings.h:59

OpenMS / TOPP release 2.0.0 Documentation generated on Thu Aug 20 2015 01:44:25 using doxygen 1.8.9.1