casa
$Rev:20696$
|
Virtual column engine to scale a table Complex array. More...
#include <CompressComplex.h>
Public Member Functions | |
CompressComplex (const String &virtualColumnName, const String &storedColumnName, Float scale, Float offset=0) | |
Construct an engine to scale all arrays in a column with the given offset and scale factor. | |
CompressComplex (const String &virtualColumnName, const String &storedColumnName, const String &scaleColumnName, const String &offsetColumnName, Bool autoScale=True) | |
Construct an engine to scale the arrays in a column. | |
CompressComplex (const Record &spec) | |
Construct from a record specification as created by getmanagerSpec(). | |
~CompressComplex () | |
Destructor is mandatory. | |
virtual String | dataManagerType () const |
Return the type name of the engine (i.e. | |
virtual String | dataManagerName () const |
Get the name given to the engine (is the virtual column name). | |
virtual Record | dataManagerSpec () const |
Record a record containing data manager specifications. | |
Static Public Member Functions | |
static String | className () |
Return the name of the class. | |
static void | registerClass () |
Register the class name and the static makeObject "constructor". | |
static DataManager * | makeObject (const String &dataManagerType, const Record &spec) |
Define the "constructor" to construct this engine when a table is read back. | |
Protected Member Functions | |
CompressComplex (const CompressComplex &) | |
Copy constructor is only used by clone() and derived class. | |
virtual void | create (uInt initialNrrow) |
Initialize the object for a new table. | |
Float | getScale (uInt rownr) |
Get the scale value for this row. | |
Float | getOffset (uInt rownr) |
Get the offset value for this row. | |
virtual void | findMinMax (Float &minVal, Float &maxVal, const Array< Complex > &array) const |
Find minimum and maximum from the array data. | |
void | makeScaleOffset (Float &scale, Float &offset, Float minVal, Float maxVal) const |
Make scale and offset from the minimum and maximum of the array data. | |
void | putPart (uInt rownr, const Slicer &slicer, const Array< Complex > &array, Float scale, Float offset) |
Put a part of an array in a row using given scale/offset values. | |
void | putFullPart (uInt rownr, const Slicer &slicer, Array< Complex > &fullArray, const Array< Complex > &partArray, Float minVal, Float maxVal) |
Fill the array part into the full array and put it using the given min/max values. | |
Protected Attributes | |
String | scaleName_p |
String | offsetName_p |
Float | scale_p |
Float | offset_p |
Bool | fixed_p |
Bool | autoScale_p |
ROScalarColumn< Float > * | scaleColumn_p |
ROScalarColumn< Float > * | offsetColumn_p |
ScalarColumn< Float > * | rwScaleColumn_p |
ScalarColumn< Float > * | rwOffsetColumn_p |
Array< Int > | buffer_p |
Private Member Functions | |
CompressComplex & | operator= (const CompressComplex &) |
Assignment is not needed and therefore forbidden (so it is made private and not implemented). | |
virtual DataManager * | clone () const |
Clone the engine object. | |
virtual void | prepare () |
Preparing consists of setting the writable switch and adding the initial number of rows in case of create. | |
virtual void | reopenRW () |
Reopen the engine for read/write access. | |
virtual void | addRowInit (uInt startRow, uInt nrrow) |
Add rows to the table. | |
virtual void | getArray (uInt rownr, Array< Complex > &array) |
Get an array in the given row. | |
virtual void | putArray (uInt rownr, const Array< Complex > &array) |
Put an array in the given row. | |
virtual void | getSlice (uInt rownr, const Slicer &slicer, Array< Complex > &array) |
Get a section of the array in the given row. | |
virtual void | putSlice (uInt rownr, const Slicer &slicer, const Array< Complex > &array) |
Put into a section of the array in the given row. | |
virtual void | getArrayColumn (Array< Complex > &array) |
Get an entire column. | |
virtual void | putArrayColumn (const Array< Complex > &array) |
Put an entire column. | |
virtual void | getColumnSlice (const Slicer &slicer, Array< Complex > &array) |
Get a section of all arrays in the column. | |
virtual void | putColumnSlice (const Slicer &slicer, const Array< Complex > &array) |
Put a section of all arrays in the column. | |
virtual void | scaleOnGet (Float scale, Float offset, Array< Complex > &array, const Array< Int > &target) |
Scale and/or offset target to array. | |
virtual void | scaleOnPut (Float scale, Float offset, const Array< Complex > &array, Array< Int > &target) |
Scale and/or offset array to target. | |
void | scaleColumnOnGet (Array< Complex > &array, const Array< Int > &target) |
Scale and/or offset target to array for the entire column. | |
void | scaleColumnOnPut (const Array< Complex > &array, Array< Int > &target) |
Scale and/or offset array to target for the entire column. |
Virtual column engine to scale a table Complex array.
Public interface
CompressComplex is a virtual column engine which scales an array of one type to another type to save disk storage. This resembles the classic AIPS compress method which scales the data from Complex to int. The scale factor and offset values can be given in two ways:
Auto-scaling means that the engine will determine the scale and offset value itself when an array (or a slice) is put. It does it by mapping the values in the array to the range [-32767,32767]. At each put the scale/offset values are changed as needed. Note that with auto-scaling putSlice
can be somewhat slower, because the entire array might need to be rescaled.
As in FITS the scale and offset values are used as:
True_value = Stored_value * scale + offset;
An engine object should be used for one column only, because the stored column name is part of the engine. If it would be used for more than one column, they would all share the same stored column. When the engine is bound to a column, it is checked if the name of that column matches the given virtual column name.
The engine can be used for a column containing any kind of array (thus direct or indirect, fixed or variable shaped)) as long as the virtual array can be stored in the stored array. Thus a fixed shaped virtual can use a variable shaped stored, but not vice versa. A fixed shape indirect virtual can use a stored with direct arrays.
This class can also serve as an example of how to implement a virtual column engine.
This class allows to store data in a smaller representation. It is needed to resemble the classic AIPS compress option.
Because the engine can serve only one column, it was possible to combine the engine and the column functionality in one class.
// Create the table description and 2 columns with indirect arrays in it. // The Int column will be stored, while the double will be // used as virtual. TableDesc tableDesc ("", TableDesc::Scratch); tableDesc.addColumn (ArrayColumnDesc<Int> ("storedArray")); tableDesc.addColumn (ArrayColumnDesc<Complex> ("virtualArray")); tableDesc.addColumn (ScalarColumnDesc<Complex> ("scale")); tableDesc.addColumn (ScalarColumnDesc<Float> ("offset")); // Create a new table using the table description. SetupNewTable newtab (tableDesc, "tab.data", Table::New); // Create the array scaling engine (with auto-scale) // and bind it to the Complex column. CompressComplex scalingEngine("virtualArray", "storedArray", "scale", "offset"); newtab.bindColumn ("virtualArray", scalingEngine); // Create the table. Table table (newtab); // Store a 3-D array (with dim. 2,3,4) into each row of the column. // The shape of each array in the column is implicitly set by the put // function. This will also set the shape of the underlying Int array. ArrayColumn data (table, "virtualArray"); Array<double> someArray(IPosition(4,2,3,4)); someArray = 0; for (uInt i=0, i<10; i++) { // table will have 10 rows table.addRow(); data.put (i, someArray) }
Definition at line 139 of file CompressComplex.h.
casa::CompressComplex::CompressComplex | ( | const String & | virtualColumnName, |
const String & | storedColumnName, | ||
Float | scale, | ||
Float | offset = 0 |
||
) |
Construct an engine to scale all arrays in a column with the given offset and scale factor.
StoredColumnName is the name of the column where the scaled data will be put and must have data type Int. The virtual column using this engine must have data type Complex.
casa::CompressComplex::CompressComplex | ( | const String & | virtualColumnName, |
const String & | storedColumnName, | ||
const String & | scaleColumnName, | ||
const String & | offsetColumnName, | ||
Bool | autoScale = True |
||
) |
Construct an engine to scale the arrays in a column.
The scale and offset values are taken from a column with the given names. In that way each array has its own scale factor and offset value. An exception is thrown if these columns do not exist. VirtualColumnName is the name of the virtual column and is used to check if the engine gets bound to the correct column. StoredColumnName is the name of the column where the scaled data will be put and must have data type Int. The virtual column using this engine must have data type Complex.
casa::CompressComplex::CompressComplex | ( | const Record & | spec | ) |
Construct from a record specification as created by getmanagerSpec().
Destructor is mandatory.
casa::CompressComplex::CompressComplex | ( | const CompressComplex & | ) | [protected] |
Copy constructor is only used by clone() and derived class.
(so it is made private).
virtual void casa::CompressComplex::addRowInit | ( | uInt | startRow, |
uInt | nrrow | ||
) | [private, virtual] |
Add rows to the table.
If auto-scaling, it initializes the scale column with 0 to indicate that no data has been processed yet.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
static String casa::CompressComplex::className | ( | ) | [static] |
Return the name of the class.
This includes the names of the template arguments.
Reimplemented in casa::CompressComplexSD.
virtual DataManager* casa::CompressComplex::clone | ( | ) | const [private, virtual] |
virtual void casa::CompressComplex::create | ( | uInt | initialNrrow | ) | [protected, virtual] |
Initialize the object for a new table.
It defines the keywords containing the engine parameters.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
Reimplemented in casa::CompressComplexSD.
virtual String casa::CompressComplex::dataManagerName | ( | ) | const [virtual] |
Get the name given to the engine (is the virtual column name).
Reimplemented from casa::DataManager.
virtual Record casa::CompressComplex::dataManagerSpec | ( | ) | const [virtual] |
Record a record containing data manager specifications.
Reimplemented from casa::DataManager.
virtual String casa::CompressComplex::dataManagerType | ( | ) | const [virtual] |
Return the type name of the engine (i.e.
its class name).
Implements casa::DataManager.
Reimplemented in casa::CompressComplexSD.
virtual void casa::CompressComplex::findMinMax | ( | Float & | minVal, |
Float & | maxVal, | ||
const Array< Complex > & | array | ||
) | const [protected, virtual] |
Find minimum and maximum from the array data.
NaN and infinite values are ignored. If no values are finite, minimum and maximum are set to NaN.
Reimplemented in casa::CompressComplexSD.
virtual void casa::CompressComplex::getArray | ( | uInt | rownr, |
Array< Complex > & | array | ||
) | [private, virtual] |
Get an array in the given row.
This will scale and offset from the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
virtual void casa::CompressComplex::getArrayColumn | ( | Array< Complex > & | array | ) | [private, virtual] |
Get an entire column.
This will scale and offset from the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
virtual void casa::CompressComplex::getColumnSlice | ( | const Slicer & | slicer, |
Array< Complex > & | array | ||
) | [private, virtual] |
Get a section of all arrays in the column.
This will scale and offset from the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
Float casa::CompressComplex::getOffset | ( | uInt | rownr | ) | [inline, protected] |
Get the offset value for this row.
Definition at line 515 of file CompressComplex.h.
References fixed_p, offset_p, and offsetColumn_p.
Float casa::CompressComplex::getScale | ( | uInt | rownr | ) | [inline, protected] |
Get the scale value for this row.
Definition at line 511 of file CompressComplex.h.
References fixed_p, scale_p, and scaleColumn_p.
virtual void casa::CompressComplex::getSlice | ( | uInt | rownr, |
const Slicer & | slicer, | ||
Array< Complex > & | array | ||
) | [private, virtual] |
Get a section of the array in the given row.
This will scale and offset from the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
static DataManager* casa::CompressComplex::makeObject | ( | const String & | dataManagerType, |
const Record & | spec | ||
) | [static] |
Define the "constructor" to construct this engine when a table is read back.
This "constructor" has to be registered by the user of the engine. If the engine is commonly used, its registration can be added to the registerAllCtor function in DataManager.cc. That function gets automatically invoked by the table system.
Reimplemented in casa::CompressComplexSD.
void casa::CompressComplex::makeScaleOffset | ( | Float & | scale, |
Float & | offset, | ||
Float | minVal, | ||
Float | maxVal | ||
) | const [protected] |
Make scale and offset from the minimum and maximum of the array data.
If minVal is NaN, scale is set to 0.
CompressComplex& casa::CompressComplex::operator= | ( | const CompressComplex & | ) | [private] |
Assignment is not needed and therefore forbidden (so it is made private and not implemented).
virtual void casa::CompressComplex::prepare | ( | ) | [private, virtual] |
Preparing consists of setting the writable switch and adding the initial number of rows in case of create.
Furthermore it reads the keywords containing the engine parameters.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
virtual void casa::CompressComplex::putArray | ( | uInt | rownr, |
const Array< Complex > & | array | ||
) | [private, virtual] |
Put an array in the given row.
This will scale and offset to the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
virtual void casa::CompressComplex::putArrayColumn | ( | const Array< Complex > & | array | ) | [private, virtual] |
Put an entire column.
This will scale and offset to the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
virtual void casa::CompressComplex::putColumnSlice | ( | const Slicer & | slicer, |
const Array< Complex > & | array | ||
) | [private, virtual] |
Put a section of all arrays in the column.
This will scale and offset to the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
void casa::CompressComplex::putFullPart | ( | uInt | rownr, |
const Slicer & | slicer, | ||
Array< Complex > & | fullArray, | ||
const Array< Complex > & | partArray, | ||
Float | minVal, | ||
Float | maxVal | ||
) | [protected] |
Fill the array part into the full array and put it using the given min/max values.
void casa::CompressComplex::putPart | ( | uInt | rownr, |
const Slicer & | slicer, | ||
const Array< Complex > & | array, | ||
Float | scale, | ||
Float | offset | ||
) | [protected] |
Put a part of an array in a row using given scale/offset values.
virtual void casa::CompressComplex::putSlice | ( | uInt | rownr, |
const Slicer & | slicer, | ||
const Array< Complex > & | array | ||
) | [private, virtual] |
Put into a section of the array in the given row.
This will scale and offset to the underlying array.
Reimplemented from casa::BaseMappedArrayEngine< Complex, Int >.
static void casa::CompressComplex::registerClass | ( | ) | [static] |
Register the class name and the static makeObject "constructor".
This will make the engine known to the table system.
Reimplemented in casa::CompressComplexSD.
virtual void casa::CompressComplex::reopenRW | ( | ) | [private, virtual] |
Reopen the engine for read/write access.
It makes the column writable if the underlying column is writable.
Reimplemented from casa::DataManager.
void casa::CompressComplex::scaleColumnOnGet | ( | Array< Complex > & | array, |
const Array< Int > & | target | ||
) | [private] |
Scale and/or offset target to array for the entire column.
When the scale and offset are fixed, it will do the entire array. Otherwise it iterates through the array and applies the scale and offset per row.
void casa::CompressComplex::scaleColumnOnPut | ( | const Array< Complex > & | array, |
Array< Int > & | target | ||
) | [private] |
Scale and/or offset array to target for the entire column.
When the scale and offset are fixed, it will do the entire array. Otherwise it iterates through the array and applies the scale and offset per row.
virtual void casa::CompressComplex::scaleOnGet | ( | Float | scale, |
Float | offset, | ||
Array< Complex > & | array, | ||
const Array< Int > & | target | ||
) | [private, virtual] |
Scale and/or offset target to array.
This is meant when reading an array from the stored column. It optimizes for scale=1 and/or offset=0.
Reimplemented in casa::CompressComplexSD.
virtual void casa::CompressComplex::scaleOnPut | ( | Float | scale, |
Float | offset, | ||
const Array< Complex > & | array, | ||
Array< Int > & | target | ||
) | [private, virtual] |
Scale and/or offset array to target.
This is meant when writing an array into the stored column. It optimizes for scale=1 and/or offset=0.
Reimplemented in casa::CompressComplexSD.
Bool casa::CompressComplex::autoScale_p [protected] |
Definition at line 295 of file CompressComplex.h.
Array<Int> casa::CompressComplex::buffer_p [protected] |
Definition at line 300 of file CompressComplex.h.
Bool casa::CompressComplex::fixed_p [protected] |
Definition at line 294 of file CompressComplex.h.
Referenced by getOffset(), and getScale().
Float casa::CompressComplex::offset_p [protected] |
Definition at line 293 of file CompressComplex.h.
Referenced by getOffset().
ROScalarColumn<Float>* casa::CompressComplex::offsetColumn_p [protected] |
Definition at line 297 of file CompressComplex.h.
Referenced by getOffset().
String casa::CompressComplex::offsetName_p [protected] |
Definition at line 291 of file CompressComplex.h.
ScalarColumn<Float>* casa::CompressComplex::rwOffsetColumn_p [protected] |
Definition at line 299 of file CompressComplex.h.
ScalarColumn<Float>* casa::CompressComplex::rwScaleColumn_p [protected] |
Definition at line 298 of file CompressComplex.h.
Float casa::CompressComplex::scale_p [protected] |
Definition at line 292 of file CompressComplex.h.
Referenced by getScale().
ROScalarColumn<Float>* casa::CompressComplex::scaleColumn_p [protected] |
Definition at line 296 of file CompressComplex.h.
Referenced by getScale().
String casa::CompressComplex::scaleName_p [protected] |
Definition at line 290 of file CompressComplex.h.