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
27
28#ifndef DOXYGEN_SHOULD_SKIP_THIS
29extern "C" {
30#endif
32#ifndef DOXYGEN_SHOULD_SKIP_THIS
33}
34#endif
35
39namespace dyscostman {
40
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) { _normalization = normalization; }
122
123 void SetStaticSeed(bool staticSeed) { _staticSeed = staticSeed; }
124
137
142 DyscoStMan(const DyscoStMan &source);
143
146
151 DyscoStMan &operator=(const DyscoStMan &source) = delete;
152
156 virtual casacore::DataManager *clone() const final override { return new DyscoStMan(*this); }
157
160 virtual casacore::String dataManagerType() const final override { return "DyscoStMan"; }
161
163 virtual casacore::String dataManagerName() const final override { return _name; }
164
169 virtual casacore::Record dataManagerSpec() const final override;
170
175 uint getNRow() const { return _nRow; }
176
181 virtual casacore::Bool canAddRow() const final override { return true; }
182
187 virtual casacore::Bool canRemoveRow() const final override { return true; }
188
194 virtual casacore::Bool canAddColumn() const final override { return true; }
195
201 virtual casacore::Bool canRemoveColumn() const final override { return true; }
202
212 const casacore::Record &spec) {
213 return new DyscoStMan(name, spec);
214 }
215
224 static void registerClass();
225
226 protected:
231 uint64_t nBlocksInFile() const {
232 std::lock_guard<std::mutex> lock(_mutex);
233 return _nBlocksInFile;
234 }
235
243 size_t nRowsInBlock() const { return _rowsPerBlock; }
244
252 size_t nAntennae() const { return _antennaCount; }
253
261 size_t getBlockIndex(uint64_t row) const { return row / _rowsPerBlock; }
262
271 size_t getRowWithinBlock(uint64_t row) const { return row % _rowsPerBlock; }
272
278 uint64_t getRowIndex(size_t block) const { return uint64_t(block) * uint64_t(_rowsPerBlock); }
279
286 bool areOffsetsInitialized() const { return _rowsPerBlock != 0; }
287
294 void initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount, bool writeToHeader);
295
296 private:
297 friend class DyscoStManColumn;
298
299 const static unsigned short VERSION_MAJOR, VERSION_MINOR;
300
301 void readCompressedData(size_t blockIndex, const DyscoStManColumn *column, unsigned char *dest,
302 size_t size);
303
304 void writeCompressedData(size_t blockIndex, const DyscoStManColumn *column,
305 const unsigned char *data, size_t size);
306
308
310
311 void makeEmpty();
312
313 void setFromSpec(const casacore::Record &spec);
314
315 size_t getFileOffset(size_t blockIndex) const { return _blockSize * blockIndex + _headerSize; }
316
317 // Flush and optionally fsync the data.
318 // The AipsIO stream represents the main table file and can be
319 // used by virtual column engines to store SMALL amounts of data.
320 virtual casacore::Bool flush(casacore::AipsIO &, casacore::Bool doFsync) final override;
321
322 // Let the storage manager create files as needed for a new table.
323 // This allows a column with an indirect array to create its file.
324 virtual void create64(casacore::rownr_t nRow) final override;
325
326 // Open the storage manager file for an existing table.
327 // Return the number of rows in the data file.
329
330 // Create a column in the storage manager on behalf of a table column.
331 // The caller will NOT delete the newly created object.
332 // Create a scalar column.
334 const casacore::String &name, int dataType,
335 const casacore::String &dataTypeID) final override;
336
337 // Create a direct array column.
339 const casacore::String &name, int dataType,
340 const casacore::String &dataTypeID) final override;
341
342 // Create an indirect array column.
344 const casacore::String &name, int dataType,
345 const casacore::String &dataTypeID) final override;
346
347 virtual casacore::rownr_t resync64(casacore::rownr_t nRow) final override;
348
349 virtual void deleteManager() final override;
350
351 // Prepare the columns, let the data manager initialize itself further.
352 // Prepare is called after create/open has been called for all
353 // columns. In this way one can be sure that referenced columns
354 // are read back and partly initialized.
355 virtual void prepare() final override;
356
357 // Reopen the storage manager files for read/write.
358 virtual void reopenRW() final override;
359
360 // Add rows to the storage manager.
361 virtual void addRow64(casacore::rownr_t nrrow) final override;
362
363 // Delete a row from all columns.
364 virtual void removeRow64(casacore::rownr_t rowNr) final override;
365
366 // Do the final addition of a column.
367 virtual void addColumn(casacore::DataManagerColumn *) final override;
368
369 // Remove a column from the data file.
370 virtual void removeColumn(casacore::DataManagerColumn *) final override;
371
372 uint64_t _nRow;
376 uint32_t _blockSize;
377
378 unsigned _headerSize;
379 mutable std::mutex _mutex;
380 std::unique_ptr<std::fstream> _fStream;
381
382 std::string _name;
389
390 std::vector<std::unique_ptr<DyscoStManColumn>> _columns;
391};
392
393} // namespace dyscostman
394
395#endif
Abstract base class for a data manager.
String: the storage and methods of handling collections of characters.
Definition String.h:355
Base class for columns of the DyscoStMan.
virtual casacore::Bool canRemoveColumn() const final override
Whether columns can be removed.
Definition dyscostman.h:201
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:160
static void registerClass()
This function makes the DyscoStMan known to casacore.
std::unique_ptr< std::fstream > _fStream
Definition dyscostman.h:380
Normalization _normalization
Definition dyscostman.h:386
virtual casacore::String dataManagerName() const final override
Returns the name of this manager as specified during construction.
Definition dyscostman.h:163
void writeCompressedData(size_t blockIndex, const DyscoStManColumn *column, const unsigned char *data, size_t size)
static const unsigned short VERSION_MAJOR
Definition dyscostman.h:299
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:123
size_t nAntennae() const
Number of antennae used in a time block.
Definition dyscostman.h:252
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:156
size_t getFileOffset(size_t blockIndex) const
Definition dyscostman.h:315
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:194
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:231
static const unsigned short VERSION_MINOR
Definition dyscostman.h:299
friend class DyscoStManColumn
Definition dyscostman.h:297
uint getNRow() const
Get the number of rows in the measurement set.
Definition dyscostman.h:175
DyscoDistribution _distribution
Definition dyscostman.h:385
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:243
std::vector< std::unique_ptr< DyscoStManColumn > > _columns
Definition dyscostman.h:390
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:278
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:181
virtual casacore::Bool canRemoveRow() const final override
Whether rows can be removed.
Definition dyscostman.h:187
size_t getRowWithinBlock(uint64_t row) const
Return the offset of the row within the block.
Definition dyscostman.h:271
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:261
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:211
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:286
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()
For temporary backward namespace compatibility, use casa as alias for casacore.
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:344
Header file for UVector and its relational and swap functions.