casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dyscostman.h
Go to the documentation of this file.
1 #ifndef DYSCO_STORAGE_MANAGER_H
2 #define DYSCO_STORAGE_MANAGER_H
3 
5 
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
29 extern "C" {
30 #endif
31 void register_dyscostman();
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 }
34 #endif
35 
39 namespace dyscostman {
40 
41 class DyscoStManColumn;
42 
47  public:
59  DyscoStMan(unsigned dataBitRate, unsigned weightBitRate,
60  const casacore::String &name = "DyscoStMan");
61 
73 
85 
95  void SetStudentsTDistribution(double nu) {
97  _studentTNu = nu;
98  }
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 
138  DyscoStMan(const casacore::String &name, const casacore::Record &spec);
139 
144  DyscoStMan(const DyscoStMan &source);
145 
147  ~DyscoStMan();
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 
318  void readHeader();
319 
320  void writeHeader();
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.
342  virtual casacore::rownr_t open64(casacore::rownr_t nRow, casacore::AipsIO &) final override;
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.
347  virtual casacore::DataManagerColumn *makeScalarColumn(
348  const casacore::String &name, int dataType,
349  const casacore::String &dataTypeID) final override;
350 
351  // Create a direct array column.
352  virtual casacore::DataManagerColumn *makeDirArrColumn(
353  const casacore::String &name, int dataType,
354  const casacore::String &dataTypeID) final override;
355 
356  // Create an indirect array column.
357  virtual casacore::DataManagerColumn *makeIndArrColumn(
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;
387  uint64_t _nBlocksInFile;
388  uint32_t _rowsPerBlock;
389  uint32_t _antennaCount;
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;
397  unsigned _dataBitCount;
398  unsigned _weightBitCount;
403 
404  std::vector<std::unique_ptr<DyscoStManColumn>> _columns;
405 };
406 
407 } // namespace dyscostman
408 
409 #endif
virtual casacore::Bool canRemoveColumn() const finaloverride
Whether columns can be removed.
Definition: dyscostman.h:209
virtual casacore::DataManagerColumn * makeScalarColumn(const casacore::String &name, int dataType, const casacore::String &dataTypeID) finaloverride
Create a column in the storage manager on behalf of a table column.
double _distributionTruncation
Definition: dyscostman.h:401
void SetStaticSeed(bool staticSeed)
Definition: dyscostman.h:125
virtual void prepare() finaloverride
Prepare the columns, let the data manager initialize itself further.
std::unique_ptr< std::fstream > _fStream
Definition: dyscostman.h:394
void readCompressedData(size_t blockIndex, const DyscoStManColumn *column, unsigned char *dest, size_t size)
virtual casacore::Record dataManagerSpec() const finaloverride
Get manager specifications.
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
size_t getBlockIndex(uint64_t row) const
Return index of block that contains the given measurement set row.
Definition: dyscostman.h:269
virtual casacore::Bool canRemoveRow() const finaloverride
Whether rows can be removed.
Definition: dyscostman.h:195
uint getNRow() const
Get the number of rows in the measurement set.
Definition: dyscostman.h:183
void register_dyscostman()
void SetStudentsTDistribution(double nu)
Initialize the storage manager to use a Student T distribution for the quantization (i...
Definition: dyscostman.h:95
static const unsigned short VERSION_MINOR
Definition: dyscostman.h:310
virtual casacore::Bool canAddRow() const finaloverride
Whether rows can be added.
Definition: dyscostman.h:189
DyscoDistribution _distribution
Definition: dyscostman.h:399
size_t nRowsInBlock() const
Number of rows in one &quot;time-block&quot;, i.e.
Definition: dyscostman.h:251
size_t nAntennae() const
Number of antennae used in a time block.
Definition: dyscostman.h:260
void SetNormalization(Normalization normalization)
Set the type of normalization.
Definition: dyscostman.h:121
virtual void addRow64(casacore::rownr_t nrrow) finaloverride
Add rows to the storage manager.
void SetTruncatedGaussianDistribution(double truncationSigma)
Initialize the storage manager to use a Uniform distribution for the quantization (i...
Definition: dyscostman.h:111
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) finaloverride
uint64_t getRowIndex(size_t block) const
Calculate first measurement set row index of a given block index.
Definition: dyscostman.h:286
virtual casacore::rownr_t open64(casacore::rownr_t nRow, casacore::AipsIO &) finaloverride
Open the storage manager file for an existing table.
void SetGaussianDistribution()
Initialize the storage manager to use a Gaussian distribution for the quantization.
Definition: dyscostman.h:72
virtual void reopenRW() finaloverride
Reopen the storage manager files for read/write.
void writeCompressedData(size_t blockIndex, const DyscoStManColumn *column, const unsigned char *data, size_t size)
virtual casacore::Bool flush(casacore::AipsIO &, casacore::Bool doFsync) finaloverride
Flush and optionally fsync the data.
virtual void create64(casacore::rownr_t nRow) finaloverride
Let the storage manager create files as needed for a new table.
~DyscoStMan()
Destructor.
Normalization _normalization
Definition: dyscostman.h:400
static const unsigned short VERSION_MAJOR
Definition: dyscostman.h:310
virtual void deleteManager() finaloverride
The data manager will be deleted (because all its columns are requested to be deleted).
A hierarchical collection of named fields of various types.
Definition: Record.h:180
uint64_t nBlocksInFile() const
The number of rows that are actually stored in the file.
Definition: dyscostman.h:239
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Base class for columns of the DyscoStMan.
Definition: dyscostmancol.h:22
virtual void removeColumn(casacore::DataManagerColumn *) finaloverride
Remove a column from the data file.
Header file for uvector and its relational and swap functions.
virtual casacore::String dataManagerType() const finaloverride
Type of manager.
Definition: dyscostman.h:164
void SetUniformDistribution()
Initialize the storage manager to use a Uniform distribution for the quantization (i...
Definition: dyscostman.h:84
size_t getFileOffset(size_t blockIndex) const
Definition: dyscostman.h:326
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 &#39;...
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
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
virtual casacore::DataManagerColumn * makeDirArrColumn(const casacore::String &name, int dataType, const casacore::String &dataTypeID) finaloverride
Create a direct array column.
virtual void addColumn(casacore::DataManagerColumn *) finaloverride
Do the final addition of a column.
static casacore::DataManager * makeObject(const casacore::String &name, const casacore::Record &spec)
Create an object with given name and spec.
Definition: dyscostman.h:219
Abstract base class for a data manager.
Definition: DataManager.h:220
std::vector< std::unique_ptr< DyscoStManColumn > > _columns
Definition: dyscostman.h:404
String: the storage and methods of handling collections of characters.
Definition: String.h:225
virtual casacore::DataManagerColumn * makeIndArrColumn(const casacore::String &name, int dataType, const casacore::String &dataTypeID) finaloverride
Create an indirect array column.
static void registerClass()
This function makes the DyscoStMan known to casacore.
void setFromSpec(const casacore::Record &spec)
virtual void removeRow64(casacore::rownr_t rowNr) finaloverride
Delete a row from all columns.
virtual casacore::Bool canAddColumn() const finaloverride
Whether columns can be added.
Definition: dyscostman.h:202
DyscoStMan & operator=(const DyscoStMan &source)=delete
Assignment – new dyscostman takes the settings of the source (but not the columns and/or data)...
virtual casacore::String dataManagerName() const finaloverride
Returns the name of this manager as specified during construction.
Definition: dyscostman.h:169
void initializeRowsPerBlock(size_t rowsPerBlock, size_t antennaCount, bool writeToHeader)
To be called by a column once it determines rowsPerBlock and antennaCount.
virtual casacore::DataManager * clone() const finaloverride
Polymorphical copy constructor, equal to DyscoStMan(const DyscoStMan&amp;).
Definition: dyscostman.h:158
The main class for the Dysco storage manager.
Definition: dyscostman.h:46