casacore
Loading...
Searching...
No Matches
dyscostman.h
Go to the documentation of this file.
1#ifndef DYSCO_STORAGE_MANAGER_H
2#define DYSCO_STORAGE_MANAGER_H
3
4#include <casacore/tables/DataMan/DataManager.h>
5
6#include <casacore/casa/Containers/Record.h>
7
8#include <cstdint>
9#include <fstream>
10#include <memory>
11#include <mutex>
12#include <vector>
13
14#include "dyscodistribution.h"
15#include "dysconormalization.h"
16#include "threadgroup.h"
17#include "uvector.h"
18
28#ifndef DOXYGEN_SHOULD_SKIP_THIS
29extern "C" {
30#endif
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33}
34#endif
35
39namespace dyscostman {
40
41class DyscoStManColumn;
42
47 public:
59 DyscoStMan(unsigned dataBitRate, unsigned weightBitRate,
60 const casacore::String &name = "DyscoStMan");
61
73
85
99
111 void SetTruncatedGaussianDistribution(double truncationSigma) {
113 _distributionTruncation = truncationSigma;
114 }
115
121 void SetNormalization(Normalization normalization) {
122 _normalization = normalization;
123 }
124
125 void SetStaticSeed(bool staticSeed) { _staticSeed = staticSeed; }
126
139
144 DyscoStMan(const DyscoStMan &source);
145
148
153 DyscoStMan &operator=(const DyscoStMan &source) = delete;
154
158 virtual casacore::DataManager *clone() const final override {
159 return new DyscoStMan(*this);
160 }
161
164 virtual casacore::String dataManagerType() const final override {
165 return "DyscoStMan";
166 }
167
169 virtual casacore::String dataManagerName() const final override {
170 return _name;
171 }
172
177 virtual casacore::Record dataManagerSpec() const final override;
178
183 uint getNRow() const { return _nRow; }
184
189 virtual casacore::Bool canAddRow() const final override { return true; }
190
195 virtual casacore::Bool canRemoveRow() const final override { return true; }
196
202 virtual casacore::Bool canAddColumn() const final override { return true; }
203
209 virtual casacore::Bool canRemoveColumn() const final override { return true; }
210
220 const casacore::Record &spec) {
221 return new DyscoStMan(name, spec);
222 }
223
232 static void registerClass();
233
234 protected:
239 uint64_t nBlocksInFile() const {
240 std::lock_guard<std::mutex> lock(_mutex);
241 return _nBlocksInFile;
242 }
243
251 size_t nRowsInBlock() const { return _rowsPerBlock; }
252
260 size_t nAntennae() const { return _antennaCount; }
261
269 size_t getBlockIndex(uint64_t row) const { return row / _rowsPerBlock; }
270
279 size_t getRowWithinBlock(uint64_t row) const { return row % _rowsPerBlock; }
280
286 uint64_t getRowIndex(size_t block) const {
287 return uint64_t(block) * uint64_t(_rowsPerBlock);
288 }
289
296 bool areOffsetsInitialized() const { return _rowsPerBlock != 0; }
297
304 void initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount,
305 bool writeToHeader);
306
307 private:
308 friend class DyscoStManColumn;
309
310 const static unsigned short VERSION_MAJOR, VERSION_MINOR;
311
312 void readCompressedData(size_t blockIndex, const DyscoStManColumn *column,
313 unsigned char *dest, size_t size);
314
315 void writeCompressedData(size_t blockIndex, const DyscoStManColumn *column,
316 const unsigned char *data, size_t size);
317
319
321
322 void makeEmpty();
323
324 void setFromSpec(const casacore::Record &spec);
325
326 size_t getFileOffset(size_t blockIndex) const {
327 return _blockSize * blockIndex + _headerSize;
328 }
329
330 // Flush and optionally fsync the data.
331 // The AipsIO stream represents the main table file and can be
332 // used by virtual column engines to store SMALL amounts of data.
334 casacore::Bool doFsync) final override;
335
336 // Let the storage manager create files as needed for a new table.
337 // This allows a column with an indirect array to create its file.
338 virtual void create64(casacore::rownr_t nRow) final override;
339
340 // Open the storage manager file for an existing table.
341 // Return the number of rows in the data file.
343
344 // Create a column in the storage manager on behalf of a table column.
345 // The caller will NOT delete the newly created object.
346 // Create a scalar column.
348 const casacore::String &name, int dataType,
349 const casacore::String &dataTypeID) final override;
350
351 // Create a direct array column.
353 const casacore::String &name, int dataType,
354 const casacore::String &dataTypeID) final override;
355
356 // Create an indirect array column.
358 const casacore::String &name, int dataType,
359 const casacore::String &dataTypeID) final override;
360
361 virtual casacore::rownr_t resync64(casacore::rownr_t nRow) final override;
362
363 virtual void deleteManager() final override;
364
365 // Prepare the columns, let the data manager initialize itself further.
366 // Prepare is called after create/open has been called for all
367 // columns. In this way one can be sure that referenced columns
368 // are read back and partly initialized.
369 virtual void prepare() final override;
370
371 // Reopen the storage manager files for read/write.
372 virtual void reopenRW() final override;
373
374 // Add rows to the storage manager.
375 virtual void addRow64(casacore::rownr_t nrrow) final override;
376
377 // Delete a row from all columns.
378 virtual void removeRow64(casacore::rownr_t rowNr) final override;
379
380 // Do the final addition of a column.
381 virtual void addColumn(casacore::DataManagerColumn *) final override;
382
383 // Remove a column from the data file.
384 virtual void removeColumn(casacore::DataManagerColumn *) final override;
385
386 uint64_t _nRow;
390 uint32_t _blockSize;
391
392 unsigned _headerSize;
393 mutable std::mutex _mutex;
394 std::unique_ptr<std::fstream> _fStream;
395
396 std::string _name;
403
404 std::vector<std::unique_ptr<DyscoStManColumn>> _columns;
405};
406
407} // namespace dyscostman
408
409#endif
Abstract base class for a data manager.
String: the storage and methods of handling collections of characters.
Definition String.h:223
Base class for columns of the DyscoStMan.
The main class for the Dysco storage manager.
Definition dyscostman.h:46
virtual casacore::Bool canRemoveColumn() const final override
Whether columns can be removed.
Definition dyscostman.h:209
virtual casacore::rownr_t open64(casacore::rownr_t nRow, casacore::AipsIO &) final override
Open the storage manager file for an existing table.
virtual void deleteManager() final override
The data manager will be deleted (because all its columns are requested to be deleted).
virtual casacore::String dataManagerType() const final override
Type of manager.
Definition dyscostman.h:164
static void registerClass()
This function makes the DyscoStMan known to casacore.
std::unique_ptr< std::fstream > _fStream
Definition dyscostman.h:394
Normalization _normalization
Definition dyscostman.h:400
virtual casacore::String dataManagerName() const final override
Returns the name of this manager as specified during construction.
Definition dyscostman.h:169
void writeCompressedData(size_t blockIndex, const DyscoStManColumn *column, const unsigned char *data, size_t size)
static const unsigned short VERSION_MAJOR
Definition dyscostman.h:310
virtual void reopenRW() final override
Reopen the storage manager files for read/write.
void SetGaussianDistribution()
Initialize the storage manager to use a Gaussian distribution for the quantization.
Definition dyscostman.h:72
virtual casacore::DataManagerColumn * makeScalarColumn(const casacore::String &name, int dataType, const casacore::String &dataTypeID) final override
Create a column in the storage manager on behalf of a table column.
void SetStudentsTDistribution(double nu)
Initialize the storage manager to use a Student T distribution for the quantization (i....
Definition dyscostman.h:95
void SetTruncatedGaussianDistribution(double truncationSigma)
Initialize the storage manager to use a Uniform distribution for the quantization (i....
Definition dyscostman.h:111
virtual void addRow64(casacore::rownr_t nrrow) final override
Add rows to the storage manager.
void readCompressedData(size_t blockIndex, const DyscoStManColumn *column, unsigned char *dest, size_t size)
virtual void prepare() final override
Prepare the columns, let the data manager initialize itself further.
void SetStaticSeed(bool staticSeed)
Definition dyscostman.h:125
size_t nAntennae() const
Number of antennae used in a time block.
Definition dyscostman.h:260
virtual casacore::Bool flush(casacore::AipsIO &, casacore::Bool doFsync) final override
Flush and optionally fsync the data.
virtual void addColumn(casacore::DataManagerColumn *) final override
Do the final addition of a column.
virtual void create64(casacore::rownr_t nRow) final override
Let the storage manager create files as needed for a new table.
virtual casacore::DataManager * clone() const final override
Polymorphical copy constructor, equal to DyscoStMan(const DyscoStMan&).
Definition dyscostman.h:158
size_t getFileOffset(size_t blockIndex) const
Definition dyscostman.h:326
void setFromSpec(const casacore::Record &spec)
~DyscoStMan()
Destructor.
virtual casacore::DataManagerColumn * makeDirArrColumn(const casacore::String &name, int dataType, const casacore::String &dataTypeID) final override
Create a direct array column.
virtual casacore::Bool canAddColumn() const final override
Whether columns can be added.
Definition dyscostman.h:202
void initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount, bool writeToHeader)
To be called by a column once it determines rowsPerBlock and antennaCount.
uint64_t nBlocksInFile() const
The number of rows that are actually stored in the file.
Definition dyscostman.h:239
static const unsigned short VERSION_MINOR
Definition dyscostman.h:310
uint getNRow() const
Get the number of rows in the measurement set.
Definition dyscostman.h:183
DyscoDistribution _distribution
Definition dyscostman.h:399
void SetUniformDistribution()
Initialize the storage manager to use a Uniform distribution for the quantization (i....
Definition dyscostman.h:84
size_t nRowsInBlock() const
Number of rows in one "time-block", i.e.
Definition dyscostman.h:251
std::vector< std::unique_ptr< DyscoStManColumn > > _columns
Definition dyscostman.h:404
DyscoStMan & operator=(const DyscoStMan &source)=delete
Assignment – new dyscostman takes the settings of the source (but not the columns and/or data).
virtual casacore::DataManagerColumn * makeIndArrColumn(const casacore::String &name, int dataType, const casacore::String &dataTypeID) final override
Create an indirect array column.
uint64_t getRowIndex(size_t block) const
Calculate first measurement set row index of a given block index.
Definition dyscostman.h:286
DyscoStMan(const DyscoStMan &source)
Copy constructor that initializes a storage manager with similar specs.
virtual casacore::Bool canAddRow() const final override
Whether rows can be added.
Definition dyscostman.h:189
virtual casacore::Bool canRemoveRow() const final override
Whether rows can be removed.
Definition dyscostman.h:195
size_t getRowWithinBlock(uint64_t row) const
Return the offset of the row within the block.
Definition dyscostman.h:279
virtual casacore::rownr_t resync64(casacore::rownr_t nRow) final override
void SetNormalization(Normalization normalization)
Set the type of normalization.
Definition dyscostman.h:121
size_t getBlockIndex(uint64_t row) const
Return index of block that contains the given measurement set row.
Definition dyscostman.h:269
virtual void removeColumn(casacore::DataManagerColumn *) final override
Remove a column from the data file.
virtual casacore::Record dataManagerSpec() const final override
Get manager specifications.
static casacore::DataManager * makeObject(const casacore::String &name, const casacore::Record &spec)
Create an object with given name and spec.
Definition dyscostman.h:219
bool areOffsetsInitialized() const
This method returns true when the number of rows per block and the number of antennae per block are k...
Definition dyscostman.h:296
DyscoStMan(const casacore::String &name, const casacore::Record &spec)
This constructor is called by Casa when it needs to create a DyscoStMan.
virtual void removeRow64(casacore::rownr_t rowNr) final override
Delete a row from all columns.
DyscoStMan(unsigned dataBitRate, unsigned weightBitRate, const casacore::String &name="DyscoStMan")
Convenience constructor to create a new storage manager with some settings without having to fill a '...
void register_dyscostman()
this file contains all the compiler specific defines
Definition mainpage.dox:28
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44
@ TruncatedGaussianDistribution
Define real & complex conjugation for non-complex types and put comparisons into std namespace.
Definition Complex.h:350
Header file for uvector and its relational and swap functions.