casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
casa::ScaledArrayEngine< VirtualType, StoredType > Class Template Reference

Templated virtual column engine to scale a table array. More...

#include <ScaledArrayEngine.h>

Inheritance diagram for casa::ScaledArrayEngine< VirtualType, StoredType >:
casa::BaseMappedArrayEngine< VirtualType, StoredType > casa::VirtualColumnEngine casa::VirtualArrayColumn< VirtualType > casa::DataManager casa::DataManagerColumn

List of all members.

Public Member Functions

 ScaledArrayEngine (const String &virtualColumnName, const String &storedColumnName, VirtualType scale, VirtualType offset=0)
 Construct an engine to scale all arrays in a column with the given offset and scale factor.
 ScaledArrayEngine (const String &virtualColumnName, const String &storedColumnName, const String &scaleColumnName, VirtualType offset=0)
 Construct an engine to scale the arrays in a column.
 ScaledArrayEngine (const String &virtualColumnName, const String &storedColumnName, const String &scaleColumnName, const String &offsetColumnName)
 ScaledArrayEngine (const Record &spec)
 Construct from a record specification as created by getmanagerSpec().
 ~ScaledArrayEngine ()
 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 DataManagermakeObject (const String &dataManagerType, const Record &spec)

Private Member Functions

 ScaledArrayEngine (const ScaledArrayEngine< VirtualType, StoredType > &)
 Copy constructor is only used by clone().
ScaledArrayEngine< VirtualType,
StoredType > & 
operator= (const ScaledArrayEngine< VirtualType, StoredType > &)
 Assignment is not needed and therefore forbidden (so it is made private and not implemented).
DataManagerclone () const
 Clone the engine object.
void create (uInt initialNrrow)
 Initialize the object for a new table.
void prepare ()
 Preparing consists of setting the writable switch and adding the initial number of rows in case of create.
void getArray (uInt rownr, Array< VirtualType > &array)
 Get an array in the given row.
void putArray (uInt rownr, const Array< VirtualType > &array)
 Put an array in the given row.
void getSlice (uInt rownr, const Slicer &slicer, Array< VirtualType > &array)
 Get a section of the array in the given row.
void putSlice (uInt rownr, const Slicer &slicer, const Array< VirtualType > &array)
 Put into a section of the array in the given row.
void getArrayColumn (Array< VirtualType > &array)
 Get an entire column.
void putArrayColumn (const Array< VirtualType > &array)
 Put an entire column.
void getColumnSlice (const Slicer &slicer, Array< VirtualType > &array)
 Get a section of all arrays in the column.
void putColumnSlice (const Slicer &slicer, const Array< VirtualType > &array)
 Put a section of all arrays in the column.
void scaleOnGet (VirtualType scale, VirtualType offset, Array< VirtualType > &array, const Array< StoredType > &stored)
 Scale and/or offset stored to array.
void scaleOnPut (VirtualType scale, VirtualType offset, const Array< VirtualType > &array, Array< StoredType > &stored)
 Scale and/or offset array to stored.
void scaleColumnOnGet (Array< VirtualType > &array, const Array< StoredType > &stored)
 Scale and/or offset stored to array for the entire column.
void scaleColumnOnPut (const Array< VirtualType > &array, Array< StoredType > &stored)
 Scale and/or offset array to stored for the entire column.
VirtualType getScale (uInt rownr)
 Get the scale value for this row.
VirtualType getOffset (uInt rownr)
 Get the offset value for this row.

Private Attributes

String scaleName_p
String offsetName_p
VirtualType scale_p
VirtualType offset_p
Bool fixedScale_p
Bool fixedOffset_p
ScalarColumn< VirtualType > * scaleColumn_p
ScalarColumn< VirtualType > * offsetColumn_p

Detailed Description

template<class VirtualType, class StoredType>
class casa::ScaledArrayEngine< VirtualType, StoredType >

Templated virtual column engine to scale a table array.

Intended use:

Public interface

Review Status

Reviewed By:
Gareth Hunt
Date Reviewed:
94Nov17

Prerequisite

Synopsis

ScaledArrayEngine 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 float to short. The scale factor and offset value can be given in two ways:

It is also possible to have a variable scale factor with a fixed offset value. 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.

Motivation

This class allows to store data in a smaller representation. It is needed to resemble the classic AIPS compress option. It adds the scale and offset value on a per row basis.

Because the engine can serve only one column, it was possible to combine the engine and the column functionality in one class. This has been achieved using multiple inheritance. The advantage of this is that only one templated class is used, so less template instantiations are needed.

Example

    // 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<double> ("virtualArray"));
   
    // Create a new table using the table description.
    SetupNewTable newtab (tableDesc, "tab.data", Table::New);
   
    // Create the array scaling engine to scale from double to Int
    // and bind it to the double column.
    // Create the table.
    ScaledArrayEngine<double,Int> scalingEngine("virtualArray",
                                                "storedArray", 10);
    newtab.bindColumn ("virtualArray", scalingEngine);
    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)
    }

Template Type Argument Requirements (VirtualType)

Template Type Argument Requirements (StoredType)

Definition at line 142 of file ScaledArrayEngine.h.


Constructor & Destructor Documentation

template<class VirtualType , class StoredType >
casa::ScaledArrayEngine< VirtualType, StoredType >::ScaledArrayEngine ( const String virtualColumnName,
const String storedColumnName,
VirtualType  scale,
VirtualType  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 StoredType. The virtual column using this engine must have data type VirtualType.

template<class VirtualType , class StoredType >
casa::ScaledArrayEngine< VirtualType, StoredType >::ScaledArrayEngine ( const String virtualColumnName,
const String storedColumnName,
const String scaleColumnName,
VirtualType  offset = 0 
)

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 StoredType. The virtual column using this engine must have data type VirtualType.

template<class VirtualType , class StoredType >
casa::ScaledArrayEngine< VirtualType, StoredType >::ScaledArrayEngine ( const String virtualColumnName,
const String storedColumnName,
const String scaleColumnName,
const String offsetColumnName 
)
template<class VirtualType , class StoredType >
casa::ScaledArrayEngine< VirtualType, StoredType >::ScaledArrayEngine ( const Record spec)

Construct from a record specification as created by getmanagerSpec().

template<class VirtualType , class StoredType >
casa::ScaledArrayEngine< VirtualType, StoredType >::~ScaledArrayEngine ( )

Destructor is mandatory.

template<class VirtualType , class StoredType >
casa::ScaledArrayEngine< VirtualType, StoredType >::ScaledArrayEngine ( const ScaledArrayEngine< VirtualType, StoredType > &  ) [private]

Copy constructor is only used by clone().

(so it is made private).


Member Function Documentation

template<class VirtualType , class StoredType >
static String casa::ScaledArrayEngine< VirtualType, StoredType >::className ( ) [static]

Return the name of the class.

This includes the names of the template arguments.

template<class VirtualType , class StoredType >
DataManager* casa::ScaledArrayEngine< VirtualType, StoredType >::clone ( ) const [private, virtual]

Clone the engine object.

Implements casa::DataManager.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::create ( uInt  initialNrrow) [private, virtual]

Initialize the object for a new table.

It defines the keywords containing the engine parameters.

Reimplemented from casa::BaseMappedArrayEngine< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
virtual String casa::ScaledArrayEngine< VirtualType, StoredType >::dataManagerName ( ) const [virtual]

Get the name given to the engine (is the virtual column name).

Reimplemented from casa::DataManager.

template<class VirtualType , class StoredType >
virtual Record casa::ScaledArrayEngine< VirtualType, StoredType >::dataManagerSpec ( ) const [virtual]

Record a record containing data manager specifications.

Reimplemented from casa::DataManager.

template<class VirtualType , class StoredType >
virtual String casa::ScaledArrayEngine< VirtualType, StoredType >::dataManagerType ( ) const [virtual]

Return the type name of the engine (i.e.

its class name).

Implements casa::DataManager.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::getArray ( uInt  rownr,
Array< VirtualType > &  array 
) [private, virtual]

Get an array in the given row.

This will scale and offset from the underlying array.

Reimplemented from casa::BaseMappedArrayEngine< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::getArrayColumn ( Array< VirtualType > &  array) [private, virtual]

Get an entire column.

This will scale and offset from the underlying array.

Reimplemented from casa::BaseMappedArrayEngine< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::getColumnSlice ( const Slicer slicer,
Array< VirtualType > &  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< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
VirtualType casa::ScaledArrayEngine< VirtualType, StoredType >::getOffset ( uInt  rownr) [private]

Get the offset value for this row.

template<class VirtualType , class StoredType >
VirtualType casa::ScaledArrayEngine< VirtualType, StoredType >::getScale ( uInt  rownr) [private]

Get the scale value for this row.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::getSlice ( uInt  rownr,
const Slicer slicer,
Array< VirtualType > &  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< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
static DataManager* casa::ScaledArrayEngine< VirtualType, StoredType >::makeObject ( const String dataManagerType,
const Record spec 
) [static]
template<class VirtualType , class StoredType >
ScaledArrayEngine<VirtualType,StoredType>& casa::ScaledArrayEngine< VirtualType, StoredType >::operator= ( const ScaledArrayEngine< VirtualType, StoredType > &  ) [private]

Assignment is not needed and therefore forbidden (so it is made private and not implemented).

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::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< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::putArray ( uInt  rownr,
const Array< VirtualType > &  array 
) [private, virtual]

Put an array in the given row.

This will scale and offset to the underlying array.

Reimplemented from casa::BaseMappedArrayEngine< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::putArrayColumn ( const Array< VirtualType > &  array) [private, virtual]

Put an entire column.

This will scale and offset to the underlying array.

Reimplemented from casa::BaseMappedArrayEngine< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::putColumnSlice ( const Slicer slicer,
const Array< VirtualType > &  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< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::putSlice ( uInt  rownr,
const Slicer slicer,
const Array< VirtualType > &  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< VirtualType, StoredType >.

template<class VirtualType , class StoredType >
static void casa::ScaledArrayEngine< VirtualType, StoredType >::registerClass ( ) [static]

Register the class name and the static makeObject "constructor".

This will make the engine known to the table system. The automatically invoked registration function in DataManReg.cc contains ScaledArrayEngine<double,Int>. Any other instantiation of this class must be registered "manually" (or added to DataManReg.cc).

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::scaleColumnOnGet ( Array< VirtualType > &  array,
const Array< StoredType > &  stored 
) [private]

Scale and/or offset stored 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.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::scaleColumnOnPut ( const Array< VirtualType > &  array,
Array< StoredType > &  stored 
) [private]

Scale and/or offset array to stored 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.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::scaleOnGet ( VirtualType  scale,
VirtualType  offset,
Array< VirtualType > &  array,
const Array< StoredType > &  stored 
) [private]

Scale and/or offset stored to array.

This is meant when reading an array from the stored column. It optimizes for scale=1 and/or offset=0.

template<class VirtualType , class StoredType >
void casa::ScaledArrayEngine< VirtualType, StoredType >::scaleOnPut ( VirtualType  scale,
VirtualType  offset,
const Array< VirtualType > &  array,
Array< StoredType > &  stored 
) [private]

Scale and/or offset array to stored.

This is meant when writing an array into the stored column. It optimizes for scale=1 and/or offset=0.


Member Data Documentation

template<class VirtualType , class StoredType >
Bool casa::ScaledArrayEngine< VirtualType, StoredType >::fixedOffset_p [private]

Definition at line 303 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
Bool casa::ScaledArrayEngine< VirtualType, StoredType >::fixedScale_p [private]

Definition at line 302 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
VirtualType casa::ScaledArrayEngine< VirtualType, StoredType >::offset_p [private]

Definition at line 301 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
ScalarColumn<VirtualType>* casa::ScaledArrayEngine< VirtualType, StoredType >::offsetColumn_p [private]

Definition at line 305 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
String casa::ScaledArrayEngine< VirtualType, StoredType >::offsetName_p [private]

Definition at line 299 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
VirtualType casa::ScaledArrayEngine< VirtualType, StoredType >::scale_p [private]

Definition at line 300 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
ScalarColumn<VirtualType>* casa::ScaledArrayEngine< VirtualType, StoredType >::scaleColumn_p [private]

Definition at line 304 of file ScaledArrayEngine.h.

template<class VirtualType , class StoredType >
String casa::ScaledArrayEngine< VirtualType, StoredType >::scaleName_p [private]

Definition at line 298 of file ScaledArrayEngine.h.


The documentation for this class was generated from the following file: