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

 Templated virtual column engine to map bit flags to a Bool.
More...

#include <BitFlagsEngine.h>

Inheritance diagram for casa::BitFlagsEngine< StoredType >:
casa::BaseMappedArrayEngine< Bool, StoredType > casa::VirtualColumnEngine casa::VirtualArrayColumn< Bool > casa::DataManager casa::DataManagerColumn

List of all members.

Classes

struct  BoolToFlags
 Functor to convert Bools to flags using a mask. More...
struct  FlagsToBool
 Functor to and an array and mask and convert to Bool. More...

Public Member Functions

 BitFlagsEngine (const String &virtualColumnName, const String &storedColumnName, StoredType readMask=StoredType(0xffffffff), StoredType writeMask=1)
 Construct an engine to map integer arrays in a column to Bool arrays.
 BitFlagsEngine (const String &virtualColumnName, const String &storedColumnName, const Array< String > &readMaskKeys, const Array< String > &writeMaskKeys)
 Construct an engine to map integer arrays in a column to Bool arrays.
 BitFlagsEngine (const Record &spec)
 Construct from a record specification as created by dataManagerSpec().
 ~BitFlagsEngine ()
 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.
virtual Record getProperties () const
 Get data manager properties that can be modified.
virtual void setProperties (const Record &spec)
 Modify data manager properties.

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)
 Define the "constructor" to construct this engine when a table is read back.

Private Member Functions

 BitFlagsEngine (const BitFlagsEngine< StoredType > &)
 Copy constructor is only used by clone().
BitFlagsEngine< StoredType > & operator= (const BitFlagsEngine< 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< Bool > &array)
 Get an array in the given row.
void putArray (uInt rownr, const Array< Bool > &array)
 Put an array in the given row.
void getSlice (uInt rownr, const Slicer &slicer, Array< Bool > &array)
 Get a section of the array in the given row.
void putSlice (uInt rownr, const Slicer &slicer, const Array< Bool > &array)
 Put into a section of the array in the given row.
void getArrayColumn (Array< Bool > &array)
 Get an entire column.
void putArrayColumn (const Array< Bool > &array)
 Put an entire column.
virtual void getArrayColumnCells (const RefRows &rownrs, Array< Bool > &data)
 Get some array values in the column.
virtual void putArrayColumnCells (const RefRows &rownrs, const Array< Bool > &data)
 Put some array values in the column.
void getColumnSlice (const Slicer &slicer, Array< Bool > &array)
 Get a section of all arrays in the column.
void putColumnSlice (const Slicer &slicer, const Array< Bool > &array)
 Put a section of all arrays in the column.
virtual void getColumnSliceCells (const RefRows &rownrs, const Slicer &slicer, Array< Bool > &data)
 Get a section of some arrays in the column.
virtual void putColumnSliceCells (const RefRows &rownrs, const Slicer &slicer, const Array< Bool > &data)
 Put into a section of some arrays in the column.
void mapOnGet (Array< Bool > &array, const Array< StoredType > &stored)
 Map bit flags array to Bool array.
void mapOnPut (const Array< Bool > &array, Array< StoredType > &stored)
 Map Bool array to bit flags array.

Private Attributes

BFEngineMask itsBFEReadMask
BFEngineMask itsBFEWriteMask
StoredType itsReadMask
StoredType itsWriteMask
Bool itsIsNew

Detailed Description

template<typename StoredType>
class casa::BitFlagsEngine< StoredType >

 Templated virtual column engine to map bit flags to a Bool.
 <h3>Intended use:</h3> Public interface

  <h3>Review Status</h3><dl><dt>Reviewed By:<dd>Gareth Hunt<dt>Date Reviewed:<dd>94Nov17</dl> 

<h3>Prerequisite</h3><ul>    <li> VirtualColumnEngine
   <li> VirtualArrayColumn
</ul>

 <h3>Synopsis</h3> 
 BitFlagsEngine is a virtual column engine which maps an integer column
 containing flag bits to a Bool column. It can be used in a MeasurementSet
 to have multiple flag categories, yet use all existing software that
 deals with the Bool FLAG column.

 The engine support read as well as write access.
 For both cases a mask can be defined telling which bits have to be taken
 into account. For example, when writing to the Bool FLAG column, the data
 in the bitflags column twill be or-ed with the bits as defined in the
 writemask. Similary when reading FLAG, only the bits of the readmask are
 taken into account.

 The masks can be defined in two ways:
 <ul>
  <li> The mask can be given directly as an integer value.
       The default write mask is 1 (thus only bit 0), while the default
       read mask is all bits.
  <li> Symbolic names for mask bits can be defined as keywords in the
       flagbits column. They define the bit value, not the bit number.
       It makes it possible to combine bits in a keyword.
       The keywords are stored in a subrecord of keyword FLAGSETS.
       Example of keyword and their values could be:
       <br>RFI=1, CAL=2, CLIP=4, OTHER=8, RFICAL=3
       <br>Note that in this example RFICAL is defined such that it
       contains RFI and CAL.
 </ul>
 A mask can be set at construction time, but it can be changed at runtime
 using the <tt>setProperties</tt> function.
 The masks are kept in special keywords (which are different from the
 keywords defining the flag bits), so it is possible to change a mask
 by changing those keywords before opening a table. However, that is
 not recommended.

 BitFlagsEngine is known to the table system for data types uChar, Short,
 and Int.

 <h3>Motivation</h3>
 The FLAG_CATEGORY defined the Measurement does not work because adding
 an extra flag means resizing the entire array which is slow.
 This class makes it possible to use an integer column to store flags
 and map it directly to a Bool column.

 <h3>Example</h3> @anchor BitFlagsEngine_example
      // Create the table description and 2 columns with indirect arrays in it.
      // The Int column will be stored, while the Bool will be used as virtual.
      TableDesc tableDesc ("", TableDesc::Scratch);
      tableDesc.addColumn (ArrayColumnDesc<Int> ("BitBlags"));
      tableDesc.addColumn (ArrayColumnDesc<Bool> ("FLAG"));
     
      // Create a new table using the table description.
      SetupNewTable newtab (tableDesc, "tab.data", Table::New);
     
      // Create the engine and bind the FLAG column to it.
      BitFlagsEngine<Int> flagsEngine("FLAG", "BitFlags");
      newtab.bindColumn ("FLAG", flagsEngine);
      // 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<Bool> someArray(IPosition(4,2,3,4));
      someArray = True;
      for (uInt i=0, i<10; i++) {          // table will have 10 rows
          table.addRow();
          data.put (i, someArray)
      }

The underlying integer array will be stored according to the writemask which defaults to 1.

Template Type Argument Requirements (StoredType)

Definition at line 169 of file BitFlagsEngine.h.


Constructor & Destructor Documentation

template<typename StoredType>
casa::BitFlagsEngine< StoredType >::BitFlagsEngine ( const String virtualColumnName,
const String storedColumnName,
StoredType  readMask = StoredType(0xffffffff),
StoredType  writeMask = 1 
)

Construct an engine to map integer arrays in a column to Bool arrays.

StoredColumnName is the name of the column where the integer data will be put and must have data type StoredType. The virtual column using this engine must have data type Bool.
A mask can be given that specifies which bits to use in the mapping from StoredType to Bool. Similarly a mask can be given defining which bits to set when mapping from Bool to StoredType.

template<typename StoredType>
casa::BitFlagsEngine< StoredType >::BitFlagsEngine ( const String virtualColumnName,
const String storedColumnName,
const Array< String > &  readMaskKeys,
const Array< String > &  writeMaskKeys 
)

Construct an engine to map integer arrays in a column to Bool arrays.

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 Bool.
A mask can be given that specifies which bits to use in the mapping from StoredType to Bool. Similarly a mask can be given defining which bits to set when mapping from Bool to StoredType. The masks are given using the values of keywords in the stored column. Each keyword should be an integer defining one or more bits and can be seen as a symbolic name. The keyword values are or-ed to form the mask. The keywords are stored in a subrecord of keyword FLAGSETS.

template<typename StoredType>
casa::BitFlagsEngine< StoredType >::BitFlagsEngine ( const Record spec)

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

template<typename StoredType>
casa::BitFlagsEngine< StoredType >::~BitFlagsEngine ( )

Destructor is mandatory.

template<typename StoredType>
casa::BitFlagsEngine< StoredType >::BitFlagsEngine ( const BitFlagsEngine< StoredType > &  ) [private]

Copy constructor is only used by clone().

(so it is made private).


Member Function Documentation

template<typename StoredType>
static String casa::BitFlagsEngine< StoredType >::className ( ) [static]

Return the name of the class.

This includes the names of the template arguments.

template<typename StoredType>
DataManager* casa::BitFlagsEngine< StoredType >::clone ( ) const [private, virtual]

Clone the engine object.

Implements casa::DataManager.

template<typename StoredType>
void casa::BitFlagsEngine< 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< Bool, StoredType >.

template<typename StoredType>
virtual String casa::BitFlagsEngine< StoredType >::dataManagerName ( ) const [virtual]

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

Reimplemented from casa::DataManager.

template<typename StoredType>
virtual Record casa::BitFlagsEngine< StoredType >::dataManagerSpec ( ) const [virtual]

Record a record containing data manager specifications.

Reimplemented from casa::DataManager.

template<typename StoredType>
virtual String casa::BitFlagsEngine< StoredType >::dataManagerType ( ) const [virtual]

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

its class name).

Implements casa::DataManager.

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::getArray ( uInt  rownr,
Array< Bool > &  array 
) [private, virtual]

Get an array in the given row.

This will scale and offset from the underlying array.

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

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::getArrayColumn ( Array< Bool > &  array) [private, virtual]

Get an entire column.

This will scale and offset from the underlying array.

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

template<typename StoredType>
virtual void casa::BitFlagsEngine< StoredType >::getArrayColumnCells ( const RefRows rownrs,
Array< Bool > &  data 
) [private, virtual]

Get some array values in the column.

This will scale and offset from the underlying array.

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

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::getColumnSlice ( const Slicer slicer,
Array< Bool > &  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< Bool, StoredType >.

template<typename StoredType>
virtual void casa::BitFlagsEngine< StoredType >::getColumnSliceCells ( const RefRows rownrs,
const Slicer slicer,
Array< Bool > &  data 
) [private, virtual]

Get a section of some arrays in the column.

This will scale and offset from the underlying array.

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

template<typename StoredType>
virtual Record casa::BitFlagsEngine< StoredType >::getProperties ( ) const [virtual]

Get data manager properties that can be modified.

These are ReadMask, WriteMask, ReadMaskKeys, and WriteMaskKeys. It is a subset of the data manager specification.

Reimplemented from casa::DataManager.

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

template<typename StoredType>
static DataManager* casa::BitFlagsEngine< StoredType >::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 DataManReg.cc. That function gets automatically invoked by the table system.

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::mapOnGet ( Array< Bool > &  array,
const Array< StoredType > &  stored 
) [private, virtual]

Map bit flags array to Bool array.

This is meant when reading an array from the stored column.

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

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::mapOnPut ( const Array< Bool > &  array,
Array< StoredType > &  stored 
) [private, virtual]

Map Bool array to bit flags array.

This is meant when writing an array into the stored column.

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

template<typename StoredType>
BitFlagsEngine<StoredType>& casa::BitFlagsEngine< StoredType >::operator= ( const BitFlagsEngine< StoredType > &  ) [private]

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

template<typename StoredType>
void casa::BitFlagsEngine< 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< Bool, StoredType >.

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::putArray ( uInt  rownr,
const Array< Bool > &  array 
) [private, virtual]

Put an array in the given row.

This will scale and offset to the underlying array.

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

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::putArrayColumn ( const Array< Bool > &  array) [private, virtual]

Put an entire column.

This will scale and offset to the underlying array.

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

template<typename StoredType>
virtual void casa::BitFlagsEngine< StoredType >::putArrayColumnCells ( const RefRows rownrs,
const Array< Bool > &  data 
) [private, virtual]

Put some array values in the column.

This will scale and offset to the underlying array.

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

template<typename StoredType>
void casa::BitFlagsEngine< StoredType >::putColumnSlice ( const Slicer slicer,
const Array< Bool > &  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< Bool, StoredType >.

template<typename StoredType>
virtual void casa::BitFlagsEngine< StoredType >::putColumnSliceCells ( const RefRows rownrs,
const Slicer slicer,
const Array< Bool > &  data 
) [private, virtual]

Put into a section of some arrays in the column.

This will scale and offset to the underlying array.

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

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

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

template<typename StoredType>
virtual void casa::BitFlagsEngine< StoredType >::setProperties ( const Record spec) [virtual]

Modify data manager properties.

These are ReadMask, WriteMask, ReadMaskKeys, and/or WriteMaskKeys. Mask keys should be given as an array of strings giving the keyword names defining mask bits (similar to the constructor). Mask keys are only used if not empty.

Reimplemented from casa::DataManager.


Member Data Documentation

template<typename StoredType>
BFEngineMask casa::BitFlagsEngine< StoredType >::itsBFEReadMask [private]

Definition at line 367 of file BitFlagsEngine.h.

template<typename StoredType>
BFEngineMask casa::BitFlagsEngine< StoredType >::itsBFEWriteMask [private]

Definition at line 368 of file BitFlagsEngine.h.

template<typename StoredType>
Bool casa::BitFlagsEngine< StoredType >::itsIsNew [private]

Definition at line 371 of file BitFlagsEngine.h.

template<typename StoredType>
StoredType casa::BitFlagsEngine< StoredType >::itsReadMask [private]

Definition at line 369 of file BitFlagsEngine.h.

template<typename StoredType>
StoredType casa::BitFlagsEngine< StoredType >::itsWriteMask [private]

Definition at line 370 of file BitFlagsEngine.h.


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