casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
casacore::RetypedArrayEngine< VirtualType, StoredType > Class Template Reference

Virtual column engine to retype and reshape arrays. More...

#include <RetypedArrayEngine.h>

Inheritance diagram for casacore::RetypedArrayEngine< VirtualType, StoredType >:
casacore::BaseMappedArrayEngine< VirtualType, StoredType > casacore::VirtualColumnEngine casacore::VirtualArrayColumn< VirtualType > casacore::DataManager casacore::VirtualArrayColumnBase casacore::DataManagerColumn

Public Member Functions

 RetypedArrayEngine (const String &virtualColumnName, const String &storedColumnName)
 Construct an engine to map a virtual column containing arrays with an arbitrary data type to arrays in a stored column. More...
 
 RetypedArrayEngine (const String &virtualColumnName, const String &storedColumnName, const IPosition &virtualElementShape, const TableRecord &extraInformation)
 Construct an engine to map a virtual column containing arrays with an arbitrary data type to arrays in a stored column. More...
 
 RetypedArrayEngine (const Record &spec)
 Construct from a record specification as created by getmanagerSpec(). More...
 
 ~RetypedArrayEngine ()
 Destructor is mandatory. More...
 
virtual String dataManagerType () const
 Return the type name of the engine (i.e. More...
 
virtual String dataManagerName () const
 Get the name given to the engine (is the virtual column name). More...
 
virtual Record dataManagerSpec () const
 Record a record containing data manager specifications. More...
 
- Public Member Functions inherited from casacore::BaseMappedArrayEngine< VirtualType, StoredType >
const StringvirtualName () const
 Get the virtual column name. More...
 
const StringstoredName () const
 Get the stored column name. More...
 
virtual Bool isWritable () const
 The column is writable if the underlying stored column is writable. More...
 
- Public Member Functions inherited from casacore::VirtualColumnEngine
 VirtualColumnEngine ()
 Create the object. More...
 
virtual ~VirtualColumnEngine ()
 
- Public Member Functions inherited from casacore::DataManager
 DataManager ()
 Default constructor. More...
 
virtual ~DataManager ()
 
void dataManagerInfo (Record &info) const
 Add SEQNR and SPEC (the DataManagerSpec subrecord) to the info. More...
 
virtual Record getProperties () const
 Get data manager properties that can be modified. More...
 
virtual void setProperties (const Record &spec)
 Modify data manager properties given in record fields. More...
 
virtual Bool canReallocateColumns () const
 Tell if the data manager wants to reallocate the data manager column objects. More...
 
virtual DataManagerColumnreallocateColumn (DataManagerColumn *column)
 Reallocate the column object if it is part of this data manager. More...
 
uInt sequenceNr () const
 Get the (unique) sequence nr of this data manager. More...
 
uInt ncolumn () const
 Get the nr of columns in this data manager (can be zero). More...
 
Bool asBigEndian () const
 Have the data to be stored in big or little endian canonical format? More...
 
const TSMOptiontsmOption () const
 Get the TSM option. More...
 
MultiFileBasemultiFile ()
 Get the MultiFile pointer (can be 0). More...
 
String keywordName (const String &keyword) const
 Compose a keyword name from the given keyword appended with the sequence number (e.g. More...
 
String fileName () const
 Compose a unique filename from the table name and sequence number. More...
 
ByteIO::OpenOption fileOption () const
 Get the AipsIO option of the underlying file. More...
 
virtual Bool isRegular () const
 Is this a regular storage manager? It is regular if it allows addition of rows and writing data in them. More...
 
Tabletable () const
 Get the table this object is associated with. More...
 
virtual void reopenRW ()
 Reopen the data manager for read/write access. More...
 
virtual Bool canAddColumn () const
 Does the data manager allow to add columns? (default no) More...
 
virtual Bool canRemoveColumn () const
 Does the data manager allow to delete columns? (default no) More...
 
virtual Bool canRenameColumn () const
 Does the data manager allow to rename columns? (default yes) More...
 
virtual void setMaximumCacheSize (uInt nMiB)
 Set the maximum cache size (in bytes) to be used by a storage manager. More...
 
virtual void showCacheStatistics (std::ostream &) const
 Show the data manager's IO statistics. More...
 
DataManagerColumncreateScalarColumn (const String &columnName, int dataType, const String &dataTypeId)
 Create a column in the data manager on behalf of a table column. More...
 
DataManagerColumncreateDirArrColumn (const String &columnName, int dataType, const String &dataTypeId)
 Create a direct array column. More...
 
DataManagerColumncreateIndArrColumn (const String &columnName, int dataType, const String &dataTypeId)
 Create an indirect array column. More...
 
DataManagergetClone () const
 Has the object already been cloned? More...
 
void setClone (DataManager *clone) const
 Set the pointer to the clone. More...
 
- Public Member Functions inherited from casacore::VirtualArrayColumn< VirtualType >
 VirtualArrayColumn ()
 Create a column. More...
 
virtual ~VirtualArrayColumn ()
 
virtual int dataType () const
 Return the data type of the column. More...
 
virtual String dataTypeId () const
 Return the data type Id of the column. More...
 
- Public Member Functions inherited from casacore::VirtualArrayColumnBase
 VirtualArrayColumnBase ()
 Create a column. More...
 
virtual ~VirtualArrayColumnBase ()
 
- Public Member Functions inherited from casacore::DataManagerColumn
 DataManagerColumn ()
 Create a column. More...
 
virtual ~DataManagerColumn ()
 Frees up the storage. More...
 
void setIsFixedShape (Bool isFixedShape)
 Set the isFixedShape flag. More...
 
Bool isFixedShape () const
 Is this a fixed shape column? More...
 
virtual void setMaxLength (uInt maxLength)
 Set the maximum length of the value (can be used for strings). More...
 
void setFixedShapeColumn (const IPosition &shape)
 Set the shape of all (fixed-shaped) arrays in the column. More...
 
virtual void setShapeTiled (rownr_t rownr, const IPosition &shape, const IPosition &tileShape)
 Set the shape and tile shape of an (variable-shaped) array in the given row. More...
 
virtual IPosition tileShape (rownr_t rownr)
 Get the tile shape of the item in the given row. More...
 
ColumnCachecolumnCache ()
 Get access to the ColumnCache object. More...
 
const ColumnCachecolumnCachePtr () const
 
void get (rownr_t rownr, Bool *dataPtr)
 Get the scalar value in the given row. More...
 
void get (rownr_t rownr, uChar *dataPtr)
 
void get (rownr_t rownr, Short *dataPtr)
 
void get (rownr_t rownr, uShort *dataPtr)
 
void get (rownr_t rownr, Int *dataPtr)
 
void get (rownr_t rownr, uInt *dataPtr)
 
void get (rownr_t rownr, Int64 *dataPtr)
 
void get (rownr_t rownr, float *dataPtr)
 
void get (rownr_t rownr, double *dataPtr)
 
void get (rownr_t rownr, Complex *dataPtr)
 
void get (rownr_t rownr, DComplex *dataPtr)
 
void get (rownr_t rownr, String *dataPtr)
 
void get (rownr_t rownr, void *dataPtr)
 This function is the get for all non-standard data types. More...
 
void put (rownr_t rownr, const Bool *dataPtr)
 Put the scalar value into the given row. More...
 
void put (rownr_t rownr, const uChar *dataPtr)
 
void put (rownr_t rownr, const Short *dataPtr)
 
void put (rownr_t rownr, const uShort *dataPtr)
 
void put (rownr_t rownr, const Int *dataPtr)
 
void put (rownr_t rownr, const uInt *dataPtr)
 
void put (rownr_t rownr, const Int64 *dataPtr)
 
void put (rownr_t rownr, const float *dataPtr)
 
void put (rownr_t rownr, const double *dataPtr)
 
void put (rownr_t rownr, const Complex *dataPtr)
 
void put (rownr_t rownr, const DComplex *dataPtr)
 
void put (rownr_t rownr, const String *dataPtr)
 
void put (rownr_t rownr, const void *dataPtr)
 This function is the put for all non-standard data types. More...
 
void throwGet () const
 Throw an "invalid operation" exception for the default implementation of get. More...
 
void throwPut () const
 Throw an "invalid operation" exception for the default implementation of put. More...
 
void setColumnName (const String &colName)
 Set the column name. More...
 
const StringcolumnName () const
 Get rhe column name. More...
 

Static Public Member Functions

static String className ()
 Return the name of the class. More...
 
static void registerClass ()
 Register the class name and the static makeObject "constructor". More...
 
static DataManagermakeObject (const String &dataManagerType, const Record &spec)
 
- Static Public Member Functions inherited from casacore::DataManager
static void registerCtor (const String &type, DataManagerCtor func)
 Register a mapping of a data manager type to its static construction function. More...
 
static DataManagerCtor getCtor (const String &dataManagerType)
 Get the "constructor" of a data manager (thread-safe). More...
 
static Bool isRegistered (const String &dataManagerType)
 Test if a data manager is registered (thread-safe). More...
 
static DataManagerunknownDataManager (const String &dataManagerType, const Record &spec)
 Serve as default function for theirRegisterMap, which catches all unknown data manager types. More...
 

Private Member Functions

 RetypedArrayEngine (const RetypedArrayEngine< VirtualType, StoredType > &)
 Copy constructor is only used by clone(). More...
 
RetypedArrayEngine
< VirtualType, StoredType > & 
operator= (const RetypedArrayEngine< VirtualType, StoredType > &)
 Assignment is not needed and therefore forbidden (so it is made private and not implemented). More...
 
DataManagerclone () const
 Clone the engine object. More...
 
void create64 (rownr_t initialNrrow)
 Initialize the object for a new table. More...
 
void prepare ()
 Preparing consists of setting the writable switch and adding the initial number of rows in case of create. More...
 
void setShapeColumn (const IPosition &shape)
 Set the shape of the FixedShape arrays in the column. More...
 
void setShape (rownr_t rownr, const IPosition &shape)
 Define the shape of the array in the given row. More...
 
uInt ndim (rownr_t rownr)
 Get the dimensionality of the array in the given row. More...
 
IPosition shape (rownr_t rownr)
 Get the shape of the array in the given row. More...
 
IPosition checkShape (const Array< VirtualType > &source, const Array< StoredType > &target)
 Check if the shapes of virtual and stored match. More...
 
virtual IPosition getStoredShape (rownr_t rownr, const IPosition &virtualShape)
 Map the virtual shape to the stored shape. More...
 
virtual Slicer getStoredSlicer (const Slicer &virtualSlicer) const
 Convert the Slicer for a virtual to a Slicer for the stored. More...
 
virtual void mapOnGet (Array< VirtualType > &array, const Array< StoredType > &stored)
 Copy the stored array to the virtual array. More...
 
virtual void mapOnPut (const Array< VirtualType > &array, Array< StoredType > &stored)
 Copy the virtual array to the stored array. More...
 

Private Attributes

IPosition shape_p
 
IPosition virtualFixedShape_p
 
Bool isVirtualFixedShape_p
 
TableRecord record_p
 
void * copyInfo_p
 

Additional Inherited Members

- Static Public Attributes inherited from casacore::DataManager
static rownr_t MAXROWNR32
 Define the highest row number that can be represented as signed 32-bit. More...
 
- Protected Member Functions inherited from casacore::BaseMappedArrayEngine< VirtualType, StoredType >
 BaseMappedArrayEngine (const String &virtualColumnName, const String &storedColumnName)
 Construct an engine to convert the virtual column to the stored column. More...
 
 ~BaseMappedArrayEngine ()
 Destructor is mandatory. More...
 
 BaseMappedArrayEngine ()
 The default constructor is required for reconstruction of the engine when a table is read back. More...
 
 BaseMappedArrayEngine (const BaseMappedArrayEngine< VirtualType, StoredType > &)
 Copy constructor is only used by copy constructor of derived classes. More...
 
void setWritable (Bool isWritable)
 Set if the column is writable or not. More...
 
void setNames (const String &virtualName, const String &storedName)
 Set the virtual and stored column name. More...
 
ArrayColumn< StoredType > & column ()
 Give access to the stored column. More...
 
virtual DataManagerColumnmakeIndArrColumn (const String &columnName, int dataType, const String &dataTypeId)
 Create the column object for the array column in this engine. More...
 
void prepare1 ()
 Do the 2 stages of the prepare (define columns and adding rows). More...
 
void prepare2 ()
 
virtual void addRow64 (rownr_t nrrow)
 Rows are added to the end of the table. More...
 
virtual void addRowInit (rownr_t startRow, rownr_t nrrow)
 
virtual Bool isShapeDefined (rownr_t rownr)
 Test if the (underlying) array is defined in the given row. More...
 
virtual Bool canChangeShape () const
 The data manager can handle changing the shape of an existing array when the underlying stored column can do it. More...
 
TableColumn makeTableColumn (const String &columnName)
 Make a table column object for the given column. More...
 
virtual void getArray (rownr_t rownr, Array< VirtualType > &array)
 Get an array in the given row. More...
 
virtual void putArray (rownr_t rownr, const Array< VirtualType > &array)
 Put an array in the given row. More...
 
virtual void getSlice (rownr_t rownr, const Slicer &slicer, Array< VirtualType > &array)
 Get a section of the array in the given row. More...
 
virtual void putSlice (rownr_t rownr, const Slicer &slicer, const Array< VirtualType > &array)
 Put into a section of the array in the given row. More...
 
virtual void getArrayColumn (Array< VirtualType > &array)
 Get an entire column. More...
 
virtual void putArrayColumn (const Array< VirtualType > &array)
 Put an entire column. More...
 
virtual void getArrayColumnCells (const RefRows &rownrs, Array< VirtualType > &data)
 Get some array values in the column. More...
 
virtual void putArrayColumnCells (const RefRows &rownrs, const Array< VirtualType > &data)
 Put some array values in the column. More...
 
void getColumnSlice (const Slicer &slicer, Array< VirtualType > &array)
 Get a section of all arrays in the column. More...
 
void putColumnSlice (const Slicer &slicer, const Array< VirtualType > &array)
 Put a section of all arrays in the column. More...
 
virtual void getColumnSliceCells (const RefRows &rownrs, const Slicer &slicer, Array< VirtualType > &data)
 Get a section of some arrays in the column. More...
 
virtual void putColumnSliceCells (const RefRows &rownrs, const Slicer &slicer, const Array< VirtualType > &data)
 Put into a section of some arrays in the column. More...
 
- Protected Member Functions inherited from casacore::DataManager
void decrementNcolumn ()
 Decrement number of columns (in case a column is deleted). More...
 
void setEndian (Bool bigEndian)
 Tell the data manager if big or little endian format is needed. More...
 
void setTsmOption (const TSMOption &tsmOption)
 Tell the data manager which TSM option to use. More...
 
void setMultiFile (MultiFileBase *mfile)
 Tell the data manager that MultiFile can be used. More...
 
virtual Bool hasMultiFileSupport () const
 Does the data manager support use of MultiFile? A derived class has to return True if it can use the MultiFile. More...
 
void throwDataTypeOther (const String &columnName, int dataType) const
 Throw an exception in case data type is TpOther, because the storage managers (and maybe other data managers) do not support such columns. More...
 
- Protected Member Functions inherited from casacore::VirtualArrayColumnBase
virtual void getScalarColumnV (ArrayBase &dataPtr)
 The scalar access functions throw an exception. More...
 
virtual void putScalarColumnV (const ArrayBase &dataPtr)
 Put all scalar values in the column. More...
 
virtual void getScalarColumnCellsV (const RefRows &rownrs, ArrayBase &dataPtr)
 Get some scalar values in the column. More...
 
virtual void putScalarColumnCellsV (const RefRows &rownrs, const ArrayBase &dataPtr)
 Put some scalar values in the column. More...
 
- Protected Member Functions inherited from casacore::DataManagerColumn
virtual void getBool (rownr_t rownr, Bool *dataPtr)
 Get the scalar value in the given row. More...
 
virtual void getuChar (rownr_t rownr, uChar *dataPtr)
 
virtual void getShort (rownr_t rownr, Short *dataPtr)
 
virtual void getuShort (rownr_t rownr, uShort *dataPtr)
 
virtual void getInt (rownr_t rownr, Int *dataPtr)
 
virtual void getuInt (rownr_t rownr, uInt *dataPtr)
 
virtual void getInt64 (rownr_t rownr, Int64 *dataPtr)
 
virtual void getfloat (rownr_t rownr, float *dataPtr)
 
virtual void getdouble (rownr_t rownr, double *dataPtr)
 
virtual void getComplex (rownr_t rownr, Complex *dataPtr)
 
virtual void getDComplex (rownr_t rownr, DComplex *dataPtr)
 
virtual void getString (rownr_t rownr, String *dataPtr)
 
virtual void getOther (rownr_t rownr, void *dataPtr)
 This function is the get for all non-standard data types. More...
 
virtual void putBool (rownr_t rownr, const Bool *dataPtr)
 Put the scalar value into the given row. More...
 
virtual void putuChar (rownr_t rownr, const uChar *dataPtr)
 
virtual void putShort (rownr_t rownr, const Short *dataPtr)
 
virtual void putuShort (rownr_t rownr, const uShort *dataPtr)
 
virtual void putInt (rownr_t rownr, const Int *dataPtr)
 
virtual void putuInt (rownr_t rownr, const uInt *dataPtr)
 
virtual void putInt64 (rownr_t rownr, const Int64 *dataPtr)
 
virtual void putfloat (rownr_t rownr, const float *dataPtr)
 
virtual void putdouble (rownr_t rownr, const double *dataPtr)
 
virtual void putComplex (rownr_t rownr, const Complex *dataPtr)
 
virtual void putDComplex (rownr_t rownr, const DComplex *dataPtr)
 
virtual void putString (rownr_t rownr, const String *dataPtr)
 
virtual void putOther (rownr_t rownr, const void *dataPtr)
 This function is the put for all non-standard data types. More...
 
void getScalarColumnBase (ArrayBase &dataPtr)
 The default implementations of get and put functions. More...
 
void putScalarColumnBase (const ArrayBase &dataPtr)
 
void getScalarColumnCellsBase (const RefRows &rownrs, ArrayBase &dataPtr)
 
void putScalarColumnCellsBase (const RefRows &rownrs, const ArrayBase &dataPtr)
 
void getArrayColumnBase (ArrayBase &data)
 
void putArrayColumnBase (const ArrayBase &data)
 
void getArrayColumnCellsBase (const RefRows &rownrs, ArrayBase &data)
 
void putArrayColumnCellsBase (const RefRows &rownrs, const ArrayBase &data)
 
void getSliceBase (rownr_t rownr, const Slicer &slicer, ArrayBase &data)
 
void putSliceBase (rownr_t rownr, const Slicer &slicer, const ArrayBase &data)
 
void getColumnSliceBase (const Slicer &slicer, ArrayBase &data)
 
void putColumnSliceBase (const Slicer &slicer, const ArrayBase &data)
 
void getColumnSliceCellsBase (const RefRows &rownrs, const Slicer &slicer, ArrayBase &data)
 
void putColumnSliceCellsBase (const RefRows &rownrs, const Slicer &slicer, const ArrayBase &data)
 

Detailed Description

template<class VirtualType, class StoredType>
class casacore::RetypedArrayEngine< VirtualType, StoredType >

Virtual column engine to retype and reshape arrays.

Intended use:

Public interface

Review Status

Reviewed By:
Brian Glendenning
Date Reviewed:
1995/12/20
Test programs:
dRetypedArrayEngine
Demo programs:
dRetypedArrayEngine.h

Prerequisite

Synopsis

RetypedArrayEngine maps a virtual column containing arrays of objects to a stored column containing arrays of data of another type. Usually the dimensionality of the arrays get smaller during this mapping process. The engine makes it possible to store an array of any type in a table.
For example, a column with 2D arrays of StokesVector's can be mapped to a column with 3D arrays of floats (of which the first axes has, say, length 4). Another example is mapping a 2D array of StokesMatrix's to a 4D array of floats.

The mapping process has to be done by a (static) set and get function in the VirtualType class. When a RetypedArrayEngine object is constructed, it is possible to pass information in a TableRecord. This TableRecord is indirectly passed to the set/get functions. This is done by means of the function newCopyInfo, which can preprocess the information in the TableRecord and store it in another object. That object is passed to the set and get functions. At the end a function deleteCopyInfo is called to delete the object. Of course, it is not needed to allocate such an object; newCopyInfo can return a null pointer.
Tip: Because the variables have to be generic and because of limitations in the CFront compiler, several variables have to be passed as void* and need to be casted in the set/get functions;

The virtual column data type class has to contain several functions. The example shows how they can be implemented.

static String dataTypeId();
has to give the (unique) name of the class.
static IPosition shape();
This has to return the full shape of the elements in the virtual. E.g. StokesVector will return [4]. StokesMatrix will return [4,4].
static void* newCopyInfo (const TableRecord& record, const IPosition& virtualElementShape);
This function has to setup the set/get functions by preprocessing the information contained in the TableRecord and storing it in a so-called "copyInfo" object. A pointer to that object has to be returned, which is kept by the engine and passed to the set/get functions. The "copyInfo" class can be a nested class in the VirtualType (as shown in the StokesVector example), but it can also be an independent class.
The supplied TableRecord is the TableRecord given when constructing the engine. When no TableRecord was given, it will be empty. The supplied shape is the shape of a virtual element as given to the constructor of the engine. This can be a full or partial shape. E.g. for a StokesVector it will usually be [4], but it can also, say, [1] if only U is used. The function could check if the information in the TableRecord and the shape match.
Of course, a VirtualType may not need any extra information. Therefore it is possible to return a null "copyInfo" pointer.
static void deleteCopyInfo (void* copyInfo);
This function has to delete the "copyInfo" object allocated by newCopyInfo. To do so, it needs to cast the pointer to the correct type.
static void set (void* copyInfo, void* out, const Array<StoredType>& in, const IPosition& virtualElementShape);
This function is called when an Array<VirtualType> is read. It has to convert the StoredType array to the VirtualType array. In principle, there are two different cases (which can be deduced from the given shape):
  1. The stored information is complete. For example: suppose the VirtualType is a StokesVector object (containing I, Q, U and V), When the stored array contains 4 values per StokesVector, it is complete.
    In this case the entire virtual array can be directly copied from the stored array when the VirtualType object contains no virtual functions and the data are directly contained in it. The function

    <tt> retypedArrayEngineSet (Array<VirtualType>& out, const Array<StoredType>& in); </tt>
    can be used for this purpose.

  2. When in the example above the stored array contains less than 4 values per StokesVector, the stored information is incomplete. In this case the set function has to fill the data in one way or another. The information in the "copyInfo" object can assist in it.
    Each VirtualType element has to be set individually, so a loop through the array is required. To assist in this, the loop has been implemented in the function

    <tt> retypedArrayEngineSet (Array<VirtualType>& out, const Array<StoredType>& in, const void* extraArgument); </tt>
    It calls the VirtualType function

    void setElem (const StoredType* data, const IPosition& shape,
    const void* extraArgument);

    for each VirtualType element. This set function has to fill the VirtualType object from the data. It can use the shape and the extraArgument to know how it should do it.
    Note that the 3-argument function retypedArrayEngineSet is only a convenience function. For optimal performance it may be needed to handcode the loop instead of using this function.


Warning: Note that the given virtual element shape does not need to match the shape given to the constructor of the engine; It is possible that the user sets the shape of the stored array before putting the virtual array; In that case the system uses the relevant part of the stored array shape as the virtual element shape;

Tip: If the out argument is declared (as it should be) as Array<VirtualType>& out, the CFront compiler complains about unknown size of VirtualType when instantiating Array<VirtualType>; Therefore it has to be declared as void* and the set function needs to cast it to Array<VirtualType>*;
static void get (void* copyInfo, Array<float>& out, const void* in, const IPosition& virtualElementShape);
This function is similar to the set function described above, but is called when an Array<VirtualType> is written. It has to convert the VirtualType array to the StoredType array.


E.g.: A StokesVector has 4 float elements.

// Construct the column object for the Stokes column.
ArrayColumn<StokesVector> stokesColumn (table, "StokesVirtualColumn");
// Put an array of StokesVector's with shape 512,512.
// This will implicitly set the shape of the underlying
// data column to 4,512,512.
// This put is very quick (it can copy all data in one go).
Array<StokesVector> stokesData (IPosition(2,512,512));
stokesColumn.put (rownr, stokesData);
// Get the column object for the Data column.
// Set its shape explicitly to 1,512,512,
ArrayColumn<float> dataColumn (table, "DataColumn");
dataColumn.setShape (rownr, IPosition(3,1,512,512));
// Now a put of the data results in calling the StokesVector::getElem
// function for each element with an IPosition(1,1); i.e. the
// data array needs only one value for each StokesVector.
stokesColumn.put (rownr, stokesData);

When reading a table back, the engine has to be registered. Otherwise it will be unknown to the table system. Similarly, the appropriate ArrayColumnDesc object has to be registered. This can be done as follows:

 RetypedArrayEngine<StokesVector,float>::registerClass();
 ArrayColumnDesc<StokesVector> tmp(ColumnDesc::registerMap);
 

When they are not registered, the open of the table will fail telling which class could not be found.

Motivation

This class allows one to store arrays of arbitrary objects in a table. It also allows it to be done it in a very efficient way.

The class had to be doubly templated. There were 2 reasons:

  1. The typedef trick described on page 321 in Barton/Nackman did not work with the CFront-based ObjectCenter compiler.
  2. It was needed to allow derivation from BaseMappedArrayEngine.

Originally it was the idea to have a mandatory nested CopyInfo class in the VirtualType class and use syntax like VirtualType::CopyInfo to access functions in it and to keep a pointer to such an object. Alas, the CFront compiler could not handle this.

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 fewer template instantiations are needed.

Example

The following example shows how a StokesVector could be implemented. It doesn't check whether the mask is correct. Two more examples are contained in the demo/test program dRetypedArrayEngine.h and its .cc file. Their second example (class RetypedArrayEx2) is similar to the StokesVector example below, but contains more extensive checking.

//# Forward Declarations
template<class T> class Array;
template<class T> class Vector;
class StokesVector
{
public:
StokesVector(): I_p(0), Q_p(0), U_p(0), V_p(0) {}
StokesVector(double i, double q, double u, double v)
: I_p(i), Q_p(q), U_p(u), V_p(v) {}
StokesVector(const StokesVector& that): I_p(that.I_p), Q_p(that.Q_p),
U_p(that.U_p), V_p(that.V_p) {}
StokesVector& operator= (const StokesVector& that)
{ I_p=that.I_p; Q_p=that.Q_p; U_p=that.U_p; V_p=that.V_p;
return *this; }
static String dataTypeId()
{ return "StokesVector"; }
// A StokesVector is 1-dim and contains 4 elements.
static IPosition shape()
{ return IPosition (1,4); }
// Preprocess possible information in the TableRecord.
static void* newCopyInfo (const TableRecord& record,
const IPosition& shape)
{ return new CopyInfo(record, shape); }
// Delete the object containing preprocessed information.
static void* deleteSetDet (void* copyInfo)
{ delete (CopyInfo*)copyInfo; }
// Convert a StoredType array to a VirtualType array.
// Do this in a CopyInfo function to use its preprocessed information.
static void set (void* copyInfo, void* out,
const Array<double>& in, const IPosition& shape)
{ ((CopyInfo*)copyInfo)->set (out, in, shape); }
// Convert a VirtualType array to a StoredType array.
// Do this in a CopyInfo function to use its preprocessed information.
static void get (void* copyInfo, Array<double>& out,
const void* in, const IPosition& shape)
{ ((CopyInfo*)copyInfo)->get (out, in, shape); }
// This nested class is used to hold preprocessed information. It
// holds a mask extracted from the TableRecord supplied to the engine.
// One can imagine that it could also extract a flag telling
// whether the stored data is stored as I,Q,U,V or as XX,YY,XY,YX
// (although such a conversion would probably be better handled
// by a separate virtual column engine).
class CopyInfo {
public:
// The constructor extracts the mask from the record.
void CopyInfo (const TableRecord& record)
{
RORecordFieldRef<Array<Bool> > field (record, 0);
mask_p = new Vector<Bool>;
*mask_p = *field;
}
// The set function fills the StokesVector.
// It uses the general functions for that purpose.
void set (void* vout, const Array<double>& in,
const IPosition& shape)
{
Array<StokesVector>& out = *(Array<StokesVector>*)vout;
if (shape.nelements() == 1 && shape(0) == 4) {
// All values available, copy in one go.
// This can be done because a StokesVector object
// only contains 4 double values (and no virtual
// function table).
retypedArrayEngineSet (out, in);
}else{
// Only some values available. Fill each
// StokesVector object using the shape and mask.
// The set function below is called for each object.
retypedArrayEngineSet (out, in, shape, (void*)mask_p);
}
}
// get is the opposite of set.
void get (Array<double>& out, const void* vin,
const IPosition& shape)
{
const Array<StokesVector>& in =
*(const Array<StokesVector>*)vin;
if (shape.nelements() == 1 && shape(0) == 4) {
retypedArrayEngineGet (out, in);
}else{
retypedArrayEngineGet (out, in, shape, (void*)mask_p);
}
private:
Vector<Bool>* mask_p;
};
// Set values of StokesVector using the mask.
// The shape is not used here.
void setElem (const double* data, const IPosition&, const void* maskPtr)
{
const Vector<Bool>& mask = *(const Vector<Bool>*)maskPtr;
I_p = Q_p = U_p = V_p = 0;
if (mask(0)) {
I_p = *data++;
}
if (mask(1)) {
Q_p = *data++;
}
if (mask(2)) {
U_p = *data++;
}
if (mask(3)) {
V_p = *data;
}
}
// Get values of StokesVector using the mask (opposite of setElem).
void getElem (double* data, const IPosition&, const void* maskPtr);
private:
double I_p, Q_p, U_p, V_p;
};
main() {
// First register the virtual column engine.
// Add ArrayColumnDesc<StokesVector> to column type map.
ArrayColumnDesc<StokesVector> tmp(ColumnDesc::registerMap);
// Build the table description.
TableDesc td("", "1", TableDesc::Scratch);
td.addColumn (ArrayColumnDesc<double> ("Data"));
td.addColumn (ArrayColumnDesc<StokesVector> ("Stokes"));
// Now create a new table from the description.
SetupNewTable newtab("tRetypedArrayEngine_tmp.data", td, Table::New);
// Create the virtual column engine with the stored columns Data.
RetypedArrayEngine<StokesVector,double> engine ("Stokes", "Data");
newtab.bindColumn ("Stokes", engine);
Table tab(newtab, 50);
// Fill the table via the virtual columns.
ArrayColumn<StokesVector> stokesColumn (tab, "Stokes");
Vector<StokesVector> vec(10);
for (i=0; i<tab.nrow(); i++) {
stokesColumn.put (i, vec);
}
}


Caution: Due to instantiation problems with the CFront-based ObjectCenter compiler (and probably other CFront-based compilers as well) the Array and Vector have to be forward declared; Array;h and Vector;h should NOT be included in this StokesVector;h, thus the implementations should not be inlined (they are too large anyway), but put in a separate ;cc file where Array;h and Vector;h can be included;

Another compiler problem is that the variable mask_p is not automatically converted to a void*, so an explicit cast has to be done.

Template Type Argument Requirements (VirtualType)

Template Type Argument Requirements (StoredType)

Definition at line 442 of file RetypedArrayEngine.h.

Constructor & Destructor Documentation

template<class VirtualType , class StoredType >
casacore::RetypedArrayEngine< VirtualType, StoredType >::RetypedArrayEngine ( const String virtualColumnName,
const String storedColumnName 
)

Construct an engine to map a virtual column containing arrays with an arbitrary data type to arrays in a stored column.

StoredColumnName is the name of the column where the converted 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 >
casacore::RetypedArrayEngine< VirtualType, StoredType >::RetypedArrayEngine ( const String virtualColumnName,
const String storedColumnName,
const IPosition virtualElementShape,
const TableRecord extraInformation 
)

Construct an engine to map a virtual column containing arrays with an arbitrary data type to arrays in a stored column.

StoredColumnName is the name of the column where the converted data will be put and must have data type StoredType. The virtual column using this engine must have data type VirtualType. The shape and record provided is handed to the newCopyInfo function in the VirtualType class. It can be used to determine how an element has to be handled when the stored data is incomplete.

template<class VirtualType , class StoredType >
casacore::RetypedArrayEngine< VirtualType, StoredType >::RetypedArrayEngine ( const Record spec)

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

template<class VirtualType , class StoredType >
casacore::RetypedArrayEngine< VirtualType, StoredType >::~RetypedArrayEngine ( )

Destructor is mandatory.

template<class VirtualType , class StoredType >
casacore::RetypedArrayEngine< VirtualType, StoredType >::RetypedArrayEngine ( const RetypedArrayEngine< VirtualType, StoredType > &  )
private

Copy constructor is only used by clone().

(so it is made private).

Member Function Documentation

template<class VirtualType , class StoredType >
IPosition casacore::RetypedArrayEngine< VirtualType, StoredType >::checkShape ( const Array< VirtualType > &  source,
const Array< StoredType > &  target 
)
private

Check if the shapes of virtual and stored match.

Determine the shape of the virtual elements in the stored.

template<class VirtualType , class StoredType >
static String casacore::RetypedArrayEngine< VirtualType, StoredType >::className ( )
static

Return the name of the class.

This includes the names of the template arguments.

template<class VirtualType , class StoredType >
DataManager* casacore::RetypedArrayEngine< VirtualType, StoredType >::clone ( ) const
privatevirtual

Clone the engine object.

Implements casacore::DataManager.

template<class VirtualType , class StoredType >
void casacore::RetypedArrayEngine< VirtualType, StoredType >::create64 ( rownr_t  initialNrrow)
privatevirtual

Initialize the object for a new table.

It defines the keywords containing the engine parameters.

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

template<class VirtualType , class StoredType >
virtual String casacore::RetypedArrayEngine< VirtualType, StoredType >::dataManagerName ( ) const
virtual

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

Reimplemented from casacore::DataManager.

template<class VirtualType , class StoredType >
virtual Record casacore::RetypedArrayEngine< VirtualType, StoredType >::dataManagerSpec ( ) const
virtual

Record a record containing data manager specifications.

Reimplemented from casacore::DataManager.

template<class VirtualType , class StoredType >
virtual String casacore::RetypedArrayEngine< VirtualType, StoredType >::dataManagerType ( ) const
virtual

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

its class name).

Implements casacore::DataManager.

template<class VirtualType , class StoredType >
virtual IPosition casacore::RetypedArrayEngine< VirtualType, StoredType >::getStoredShape ( rownr_t  rownr,
const IPosition virtualShape 
)
privatevirtual

Map the virtual shape to the stored shape.

By default is returns the virtual shape.

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

template<class VirtualType , class StoredType >
virtual Slicer casacore::RetypedArrayEngine< VirtualType, StoredType >::getStoredSlicer ( const Slicer virtualSlicer) const
privatevirtual

Convert the Slicer for a virtual to a Slicer for the stored.

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

template<class VirtualType , class StoredType >
static DataManager* casacore::RetypedArrayEngine< VirtualType, StoredType >::makeObject ( const String dataManagerType,
const Record spec 
)
static
template<class VirtualType , class StoredType >
virtual void casacore::RetypedArrayEngine< VirtualType, StoredType >::mapOnGet ( Array< VirtualType > &  array,
const Array< StoredType > &  stored 
)
privatevirtual

Copy the stored array to the virtual array.

It tries to optimize as much as possible.

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

template<class VirtualType , class StoredType >
virtual void casacore::RetypedArrayEngine< VirtualType, StoredType >::mapOnPut ( const Array< VirtualType > &  array,
Array< StoredType > &  stored 
)
privatevirtual

Copy the virtual array to the stored array.

It tries to optimize as much as possible.

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

template<class VirtualType , class StoredType >
uInt casacore::RetypedArrayEngine< VirtualType, StoredType >::ndim ( rownr_t  rownr)
privatevirtual

Get the dimensionality of the array in the given row.

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

template<class VirtualType , class StoredType >
RetypedArrayEngine<VirtualType,StoredType>& casacore::RetypedArrayEngine< VirtualType, StoredType >::operator= ( const RetypedArrayEngine< VirtualType, StoredType > &  )
private

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

template<class VirtualType , class StoredType >
void casacore::RetypedArrayEngine< VirtualType, StoredType >::prepare ( )
privatevirtual

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 and allocates a CopyInfo object for the VirtualType.

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

template<class VirtualType , class StoredType >
static void casacore::RetypedArrayEngine< 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 RetypedArrayEngine<double,Int>. Any other instantiation of this class must be registered "manually" (or added to DataManReg.cc).

template<class VirtualType , class StoredType >
void casacore::RetypedArrayEngine< VirtualType, StoredType >::setShape ( rownr_t  rownr,
const IPosition shape 
)
privatevirtual

Define the shape of the array in the given row.

When the shape of the (underlying) stored array has already been defined, it checks whether its latter dimensions match the given virtual shape. When matching, nothing will be done. When mismatching or when the stored shape has not been defined yet, the stored shape will be defined from the virtual shape and the virtual element shape. E.g. in case of a StokesVector a virtual shape of (512,512) results in a stored shape of (4,512,512).

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

template<class VirtualType , class StoredType >
void casacore::RetypedArrayEngine< VirtualType, StoredType >::setShapeColumn ( const IPosition shape)
privatevirtual

Set the shape of the FixedShape arrays in the column.

This function only gets called if the column has FixedShape arrays. The shape gets saved and used to set the shape of the arrays in the stored in case the stored has non-FixedShape arrays.

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

template<class VirtualType , class StoredType >
IPosition casacore::RetypedArrayEngine< VirtualType, StoredType >::shape ( rownr_t  rownr)
privatevirtual

Get the shape of the array in the given row.

This is done by stripping the first dimension(s) from the shape of the underlying stored array.

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

Member Data Documentation

template<class VirtualType , class StoredType >
void* casacore::RetypedArrayEngine< VirtualType, StoredType >::copyInfo_p
private

Definition at line 580 of file RetypedArrayEngine.h.

template<class VirtualType , class StoredType >
Bool casacore::RetypedArrayEngine< VirtualType, StoredType >::isVirtualFixedShape_p
private

Definition at line 577 of file RetypedArrayEngine.h.

template<class VirtualType , class StoredType >
TableRecord casacore::RetypedArrayEngine< VirtualType, StoredType >::record_p
private

Definition at line 578 of file RetypedArrayEngine.h.

template<class VirtualType , class StoredType >
IPosition casacore::RetypedArrayEngine< VirtualType, StoredType >::shape_p
private

Definition at line 575 of file RetypedArrayEngine.h.

template<class VirtualType , class StoredType >
IPosition casacore::RetypedArrayEngine< VirtualType, StoredType >::virtualFixedShape_p
private

Definition at line 576 of file RetypedArrayEngine.h.


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