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 { return chunk_index < rhs.chunk_index; }
35 };
36
37 private:
46
47 public:
48 SiscoReader(const std::string& filename);
50
57 void Open(std::span<std::byte> header_data);
58
59 size_t GetRequestBufferSize() const { return kRequestBufferSize; }
60
74 void Request(size_t baseline_index, size_t n_values);
75
80 void GetNextResult(std::span<std::complex<float>> data);
81
82 int PredictLevel() const { return predict_level_; }
83
84 private:
85 void Close();
86
87 void ResultLoop();
88
89 struct Result {
90 std::vector<float> real_data;
91 std::vector<float> imaginary_data;
92 size_t result_index = 0;
93 bool operator<(const Result& rhs) const { return result_index < rhs.result_index; }
94 };
95 void ReadLoop();
97 void GetNextChunk(Chunk& chunk);
99 size_t ReadChunk(std::vector<std::byte>& buffer);
100
101 static constexpr size_t kRequestBufferSize = 4096;
102 std::set<Chunk> decompressed_queue;
103
105 std::list<Chunk> chunks_;
106
108 size_t chunk_sequence = 0;
110 size_t result_counter_ = 0;
113
114 bool open_ = false;
115
120 std::set<Result> result_queue;
121
122 std::thread read_thread_;
123 std::vector<std::thread> result_workers_;
124 std::mutex mutex_;
125 std::set<size_t> busy_baselines_;
126
131
132 // Indexed by baseline_index.
133 std::map<size_t, BaselineData> baseline_data_;
134 std::string filename_;
135 std::ifstream file_;
136};
137
138} // namespace casacore::sisco
139
140#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:59
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:93
std::vector< float > imaginary_data
Definition SiscoReader.h:91