casacore
Loading...
Searching...
No Matches
SiscoReader.h
Go to the documentation of this file.
1#ifndef SISCO_SISCO_READER_H_
2#define SISCO_SISCO_READER_H_
3
4#include <complex>
5#include <fstream>
6#include <list>
7#include <map>
8#include <set>
9#include <span>
10#include <string>
11#include <thread>
12#include <vector>
13
14#include "ConditionalQueue.h"
15#include "Deflate.h"
16#include "Lane.h"
17#include "Sisco.h"
18
19namespace casacore::sisco {
20
26 struct Chunk {
31 std::vector<std::byte> read_buffer;
32 std::vector<std::byte> decompress_buffer;
33
34 bool operator<(const Chunk& rhs) const {
35 return chunk_index < rhs.chunk_index;
36 }
37 };
38
39 private:
48
49 public:
50 SiscoReader(const std::string& filename);
52
59 void Open(std::span<std::byte> header_data);
60
61 size_t GetRequestBufferSize() const { return kRequestBufferSize; }
62
76 void Request(size_t baseline_index, size_t n_values);
77
82 void GetNextResult(std::span<std::complex<float>> data);
83
84 int PredictLevel() const { return predict_level_; }
85
86 private:
87 void Close();
88
89 void ResultLoop();
90
91 struct Result {
92 std::vector<float> real_data;
93 std::vector<float> imaginary_data;
94 size_t result_index = 0;
95 bool operator<(const Result& rhs) const {
96 return result_index < rhs.result_index;
97 }
98 };
99 void ReadLoop();
101 void GetNextChunk(Chunk& chunk);
103 size_t ReadChunk(std::vector<std::byte>& buffer);
104
105 static constexpr size_t kRequestBufferSize = 4096;
106 std::set<Chunk> decompressed_queue;
107
109 std::list<Chunk> chunks_;
110
112 size_t chunk_sequence = 0;
114 size_t result_counter_ = 0;
117
118 bool open_ = false;
119
124 std::set<Result> result_queue;
125
126 std::thread read_thread_;
127 std::vector<std::thread> result_workers_;
128 std::mutex mutex_;
129 std::set<size_t> busy_baselines_;
130
135
136 // Indexed by baseline_index.
137 std::map<size_t, BaselineData> baseline_data_;
138 std::string filename_;
139 std::ifstream file_;
140};
141
142} // namespace casacore::sisco
143
144#endif
Internal header file for the Lane.
The Lane is an efficient cyclic buffer that is synchronized.
Definition Lane.h:100
A queue with a limited size and the ability to query only specific values.
std::set< Result > result_queue
std::list< Chunk > chunks_
std::vector< std::thread > result_workers_
aocommon::Lane< Chunk > decompress_lane_
void GetNextResult(std::span< std::complex< float > > data)
Retrieve the data associated with an earlier Request() call.
size_t GetRequestBufferSize() const
Definition SiscoReader.h:61
void Open(std::span< std::byte > header_data)
Open the file and prepare for decompression.
void GetNextChunk(Chunk &chunk)
std::set< Chunk > decompressed_queue
std::map< size_t, BaselineData > baseline_data_
Indexed by baseline_index.
size_t ReadChunk(std::vector< std::byte > &buffer)
Read current chunk and returns the decompressed size.
std::set< size_t > busy_baselines_
ConditionalQueue< RequestData > request_queue_
aocommon::Lane< Chunk > read_lane_
static constexpr size_t kRequestBufferSize
void Request(size_t baseline_index, size_t n_values)
This is an interface that allows parallelism over the decompression.
SiscoReader(const std::string &filename)
aocommon::Lane< Result > result_lane_
std::vector< std::byte > decompress_buffer
Definition SiscoReader.h:32
bool operator<(const Chunk &rhs) const
Definition SiscoReader.h:34
std::vector< std::byte > read_buffer
Definition SiscoReader.h:31
bool operator<(const Result &rhs) const
Definition SiscoReader.h:95
std::vector< float > imaginary_data
Definition SiscoReader.h:93