ProteoWizard
DemuxDebugReader.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 _DEMUXDEBUGREADER_HPP
21#define _DEMUXDEBUGREADER_HPP
22
23#include "DemuxTypes.hpp"
24#include <cstdint>
25#include <fstream>
26#include <vector>
27
28namespace pwiz {
29namespace analysis {
30 using std::uint64_t;
31 using std::int64_t;
32
33 /// A class for reading demux matrices from file. The primary purpose of writing demux matrices to file is for
34 /// analysis externally, so the intent of this class is to provide a method to test the output of the
35 /// DemuxDebugWriter class. This class follows the RAII of ifstream and so the file is kept open until the
36 /// destructor is called.
38 {
39 public:
40
41 /// Constructs a DemuxDebugReader to read the debug file with the given filename. During construction the
42 /// file header is read to inform the NumBlocks() function of the filesize and to build a map of pointers
43 /// to the matrix blocks for random access.
44 /// @param fileName Filename of debug matrices file
45 explicit DemuxDebugReader(const std::string& fileName);
46
47 /// Destructor closes the file
49
50 /// Number of blocks (sets of matrices) that are contained in the file. This is the number of times that ReadDeconvBlock
51 /// can be called sequentially. Throws error if IsOpen() returns false.
52 /// @return Number of blocks in the file
53 size_t NumBlocks() const;
54
55 /// Can be used to read through the blocks sequntially. Each time this is called the next set of blocks is returned. This
56 /// can be called NumBlocks() times before an out_of_range error will be thrown. Throws error if IsOpen() returns false.
57 /// @param[out] spectrumIndex The index of the spectrum corresponding to this block
58 /// @param[out] masks The masks matrix
59 /// @param[out] solution The solution matrix
60 /// @param[out] signal The signal matrix
61 void ReadDeconvBlock(uint64_t& spectrumIndex,
63 DemuxTypes::MatrixPtr solution,
65
66 /// Used for random-access reading of the blocks. The block indices range from 0 to NumBlocks() - 1. Throws error if IsOpen() returns false.
67 /// @param[in] blockIndex index of the block to read
68 /// @param[out] spectrumIndex The index of the spectrum corresponding to this block
69 /// @param[out] masks The masks matrix
70 /// @param[out] solution The solution matrix
71 /// @param[out] signal The signal matrix
72 void ReadDeconvBlock(size_t blockIndex,
73 uint64_t& spectrumIndex,
75 DemuxTypes::MatrixPtr solution,
77
78 /// Should be called after construction to verify that the file was opened successfully
79 /// @return true if file was successfully opened and its header read and verified, false otherwise
80 bool IsOpen() const;
81
82 private:
83
84 /// Reads the header/footer which contains information about the number of blocks and their locations in the file for random access.
85 void ReadHeader();
86
87 /// Input file stream of the debug file
88 std::ifstream _reader;
89
90 /// Set of pointers to blocks in the file extracted from the header/footer information
91 std::vector<std::pair<uint64_t, int64_t>> _fileIndex;
92
93 /// Current block index used for tracking progress through file when sequential iteration of ReadDeconvBlock() is used
95 };
96
97} //namespace analysis
98} //namespace pwiz
99#endif //_DEMUXDEBUGREADER_HPP
A class for reading demux matrices from file.
size_t _currentBlockIndex
Current block index used for tracking progress through file when sequential iteration of ReadDeconvBl...
DemuxDebugReader(const std::string &fileName)
Constructs a DemuxDebugReader to read the debug file with the given filename.
std::vector< std::pair< uint64_t, int64_t > > _fileIndex
Set of pointers to blocks in the file extracted from the header/footer information.
~DemuxDebugReader()
Destructor closes the file.
std::ifstream _reader
Input file stream of the debug file.
bool IsOpen() const
Should be called after construction to verify that the file was opened successfully.
size_t NumBlocks() const
Number of blocks (sets of matrices) that are contained in the file.
void ReadHeader()
Reads the header/footer which contains information about the number of blocks and their locations in ...
void ReadDeconvBlock(size_t blockIndex, uint64_t &spectrumIndex, DemuxTypes::MatrixPtr masks, DemuxTypes::MatrixPtr solution, DemuxTypes::MatrixPtr signal)
Used for random-access reading of the blocks.
void ReadDeconvBlock(uint64_t &spectrumIndex, DemuxTypes::MatrixPtr masks, DemuxTypes::MatrixPtr solution, DemuxTypes::MatrixPtr signal)
Can be used to read through the blocks sequntially.
boost::shared_ptr< MatrixType > MatrixPtr