ProteoWizard
MatrixIO.hpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: Austin Keller <atkeller .@. uw.edu>
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 
20 #ifndef _MATRIXIO_HPP
21 #define _MATRIXIO_HPP
22 
23 #include "DemuxTypes.hpp"
24 #include <boost/smart_ptr/shared_ptr.hpp>
25 #include <fstream>
26 
27 namespace pwiz
28 {
29 namespace analysis
30 {
31  /// Provides static methods for writing and reading matrices to/from files. An example file format used is as follows:
32  /// byte | type | description
33  /// --------------------------- | --------- | -----------
34  /// 0 | int64 | num_rows
35  /// 8 | int64 | num_cols
36  /// 16 | double | element_0
37  /// 24 | double | element_1
38  /// 32 | double | element_2
39  /// ... | double(s) | ...
40  /// (num_elements - 1) * 8 + 16 | double | element_n
41  ///
42  /// Note that the type of the index (shown as int64) is subject to change and is dependent on the type of Matrix::Index.
43  /// Similarly, the type of each element is dependent on the type of the Scalar type of the Matrix. However, in the current
44  /// (as of 8/30/2016) implementation of DemuxTypes::MatrixType the types shown above are accurate.
45  class MatrixIO
46  {
47  public:
48 
49  /// Factory method for generating output streams with fixed properties set for writing matrices
50  static void GetWriteStream(std::ofstream& out, const std::string& filename);
51 
52  /// Writes a matrix to filestream including header information about the number of rows and columns. Matrices are written in row-major format.
53  static void WriteBinary(std::ofstream& out, boost::shared_ptr<DemuxTypes::MatrixType> matrix);
54 
55  /// Convience function for writing a single matrix to file.
56  static void WriteBinary(const std::string& filename, boost::shared_ptr<DemuxTypes::MatrixType> matrix);
57 
58  /// Factory method for generating input streams with fixed properties set for reading matrices
59  static void GetReadStream(std::ifstream& in, const std::string& filename);
60 
61  /// Convenience function for reading a single matrix from a file
62  static void ReadBinary(std::ifstream& in, boost::shared_ptr<DemuxTypes::MatrixType> matrix);
63 
64  /// Reads a matrix from filestream. Matrices are written in row-major format.
65  static void ReadBinary(const std::string& filename, boost::shared_ptr<DemuxTypes::MatrixType> matrix);
66  };
67 } // namespace analysis
68 } // namespace pwiz
69 #endif //_MATRIXIO_HPP
pwiz::analysis::MatrixIO::ReadBinary
static void ReadBinary(std::ifstream &in, boost::shared_ptr< DemuxTypes::MatrixType > matrix)
Convenience function for reading a single matrix from a file.
pwiz::analysis::MatrixIO::GetWriteStream
static void GetWriteStream(std::ofstream &out, const std::string &filename)
Factory method for generating output streams with fixed properties set for writing matrices.
pwiz
Definition: ChromatogramList_Filter.hpp:36
DemuxTypes.hpp
pwiz::analysis::MatrixIO::WriteBinary
static void WriteBinary(std::ofstream &out, boost::shared_ptr< DemuxTypes::MatrixType > matrix)
Writes a matrix to filestream including header information about the number of rows and columns....
pwiz::analysis::MatrixIO
Provides static methods for writing and reading matrices to/from files.
Definition: MatrixIO.hpp:45
pwiz::analysis::MatrixIO::GetReadStream
static void GetReadStream(std::ifstream &in, const std::string &filename)
Factory method for generating input streams with fixed properties set for reading matrices.