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

Class for a table as a view of another table. More...

#include <RefTable.h>

Inheritance diagram for casa::RefTable:
casa::BaseTable

List of all members.

Public Member Functions

 RefTable (BaseTable *, Bool rowOrder, uInt initialNrrow)
 Create a reference table object referencing the given BaseTable object.
 RefTable (BaseTable *, const Vector< uInt > &rowNumbers)
 A RefTable with the given row numbers is constructed.
 RefTable (BaseTable *, const Vector< Bool > &rowMask)
 Create a reference table object out of a mask.
 RefTable (BaseTable *, const Vector< String > &columnNames)
 Create a reference table object via projection (i.e.
 RefTable (AipsIO &, const String &name, uInt nrrow, int option, const TableLock &lockOptions, const TSMOption &tsmOption)
 Create a reference table out of a file (written by writeRefTable).
virtual ~RefTable ()
 The destructor flushes (i.e.
virtual void reopenRW ()
 Try to reopen the table (the underlying one) for read/write access.
virtual Bool asBigEndian () const
 Is the table stored in big or little endian format?
virtual Bool isMultiUsed (Bool checkSubTable) const
 Is the table in use (i.e.
virtual const TableLocklockOptions () const
 Get the locking info.
virtual void mergeLock (const TableLock &lockOptions)
 Merge the given lock info with the existing one.
virtual Bool hasLock (FileLocker::LockType) const
 Has this process the read or write lock, thus can the table be read or written safely?
virtual Bool lock (FileLocker::LockType, uInt nattempts)
 Try to lock the table for read or write access.
virtual void unlock ()
 Unlock the table.
virtual void flush (Bool fsync, Bool recursive)
 Flush the table, i.e.
virtual void resync ()
 Resync the Table object with the table file.
virtual uInt getModifyCounter () const
 Get the modify counter.
virtual Bool isWritable () const
 Test if the parent table is opened as writable.
void getRef (AipsIO &, int option, const TableLock &lockOptions, const TSMOption &tsmOption)
 Read a reference table from a file.
virtual void copy (const String &newName, int tableOption) const
 This is doing a shallow copy.
virtual void deepCopy (const String &newName, const Record &dataManagerInfo, int tableOption, Bool, int endianFormat, Bool noRows) const
 Copy the table and all its subtables.
virtual int tableType () const
 It returns the type of the parent table.
virtual TableDesc actualTableDesc () const
 Get the actual table description.
virtual Record dataManagerInfo () const
 Get the data manager info.
virtual TableRecordkeywordSet ()
 Get readonly access to the table keyword set.
virtual TableRecordrwKeywordSet ()
 Get read/write access to the table keyword set.
virtual BaseColumngetColumn (uInt columnIndex) const
 Get a column object using its index.
virtual BaseColumngetColumn (const String &columnName) const
 Get a column object using its name.
virtual Bool canRemoveRow () const
 Test if it is possible to remove a row from this table.
virtual void removeRow (uInt rownr)
 Remove the given row.
virtual void addColumn (const ColumnDesc &columnDesc, Bool addToParent)
 Add one or more columns to the table.
virtual void addColumn (const ColumnDesc &columnDesc, const String &dataManager, Bool byName, Bool addToParent)
virtual void addColumn (const ColumnDesc &columnDesc, const DataManager &dataManager, Bool addToParent)
virtual void addColumn (const TableDesc &tableDesc, const DataManager &dataManager, Bool addToParent)
virtual Bool canRemoveColumn (const Vector< String > &columnNames) const
 Test if columns can be removed (yes).
virtual void removeColumn (const Vector< String > &columnNames)
 Remove columns.
virtual Bool canRenameColumn (const String &columnName) const
 Test if a column can be renamed (yes).
virtual void renameColumn (const String &newName, const String &oldName)
 Rename a column.
virtual void renameHypercolumn (const String &newName, const String &oldName)
 Rename a hypercolumn.
virtual DataManagerfindDataManager (const String &name, Bool byColumn) const
 Find the data manager with the given name or for the given column.
virtual Vector< uIntrowNumbers () const
 Get a vector of row numbers.
virtual BaseTableroot ()
 Get parent of this table.
uInt rootRownr (uInt rownr) const
 Get rownr in root table.
Vector< uIntrootRownr (const Vector< uInt > &rownrs) const
 Get vector of rownrs in root table.
virtual Bool rowOrder () const
 Tell if the table is in row order.
virtual Vector< uInt > * rowStorage ()
 Get row number vector.
void addRownr (uInt rownr)
 Add a rownr to reference table.
void setNrrow (uInt nrrow)
 Set the exact number of rows in the table.
virtual Bool adjustRownrs (uInt nrrow, Vector< uInt > &rownrs, Bool determineOrder) const
 Adjust the row numbers to be the actual row numbers in the root table.
void refAnd (uInt nr1, const uInt *rows1, uInt nr2, const uInt *rows2)
 And, or, subtract or xor the row numbers of 2 tables.
void refOr (uInt nr1, const uInt *rows1, uInt nr2, const uInt *rows2)
void refSub (uInt nr1, const uInt *rows1, uInt nr2, const uInt *rows2)
void refXor (uInt nr1, const uInt *rows1, uInt nr2, const uInt *rows2)
void refNot (uInt nr1, const uInt *rows1, uInt nrmain)

Static Public Member Functions

static void getLayout (TableDesc &desc, AipsIO &ios)
 Return the layout of a table (i.e.
static uIntgetStorage (Vector< uInt > &rownrs)
 Get the internal pointer in a rowStorage vector.

Private Member Functions

 RefTable (const RefTable &)
 Copy constructor is forbidden, because copying a table requires some more knowledge (like table name of result).
RefTableoperator= (const RefTable &)
 Assignment is forbidden, because copying a table requires some more knowledge (like table name of result).
virtual void getPartNames (Block< String > &names, Bool recursive) const
 Get the names of the tables this table consists of.
void showStructureExtra (std::ostream &) const
 Show the extra table structure info (name of root table).
void setup (BaseTable *btp, const Vector< String > &columnNames)
 Setup the main parts of the object.
void makeRefCol ()
 Create the RefColumn objects for all columns in the description.
void writeRefTable (Bool fsync)
 Write a reference table.
void copyRefTable (const String &newName, int tableOption)
 Copy a RefTable that is not persistent.
Bool checkAddColumn (const String &name, Bool addToParent)
 Check if a column can be added.
void addRefCol (const ColumnDesc &cd)
 Add a column.
void addRefCol (const TableDesc &tdesc)
 Add multiple columns.

Static Private Member Functions

static void makeDesc (TableDesc &desc, const TableDesc &rootDesc, SimpleOrderedMap< String, String > &nameMap, Vector< String > &names)
 Make a table description for the given columns.

Private Attributes

BaseTablebaseTabPtr_p
Bool rowOrd_p
Vector< uIntrowStorage_p
uIntrows_p
SimpleOrderedMap< String, StringnameMap_p
SimpleOrderedMap< String,
RefColumn * > 
colMap_p
Bool changed_p

Detailed Description

Class for a table as a view of another table.

Intended use:

Internal

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Prerequisite

Etymology

RefTable represents a table which is a view on another table, thus which references another table.

Synopsis

RefTable is used to make a view on another table. Usually it is a view on a subset of the table, either in vertical or horizontal direction. Thus a subset of rows and/or columns. It will be the result of a select, sort, project or iterate function.

It acts to the user as a normal table. All gets and puts are handled by RefColumn which directs them to the referenced column while (if needed) converting the given row number to the row number in the referenced table. For that purpose RefTable maintains a Vector of the row numbers in the referenced table.

The RefTable constructor acts in a way that it will always reference the original table. This means that if a select is done on a RefTable, the resulting RefTable will also reference the original PlainTable. This is done to avoid long chains of RefTables. However, if ever some other kind of table views are introduced (like a join or a concatenation of similar tables), this cannot be used anymore. Most software already anticipates on that. The only exception is the code anding, oring tables (refAnd, etc.).

To Do

Definition at line 104 of file RefTable.h.


Constructor & Destructor Documentation

casa::RefTable::RefTable ( BaseTable ,
Bool  rowOrder,
uInt  initialNrrow 
)

Create a reference table object referencing the given BaseTable object.

If the BaseTable is actually another RefTable, it will reference its referenced table (thus the original table) and it will take its vector of row numbers and projected column names into account. Thus if a select is done on a projected table, the resulting RefTable will have the same projection.

Construct a RefTable with an empty row number vector. rowOrder=True indicates that the order of the rows will not be disturbed (as will be the case for a sort). A row number vector of the given size is initially allocated. Later this RefTable will be filled in by the select, etc..

casa::RefTable::RefTable ( BaseTable ,
const Vector< uInt > &  rowNumbers 
)

A RefTable with the given row numbers is constructed.

casa::RefTable::RefTable ( BaseTable ,
const Vector< Bool > &  rowMask 
)

Create a reference table object out of a mask.

The row number vector will consist of the rows for which the mask has a True value. The length of the mask must be the number of rows in the BaseTable.

casa::RefTable::RefTable ( BaseTable ,
const Vector< String > &  columnNames 
)

Create a reference table object via projection (i.e.

column selection). The row number vector is a copy of the given table.

casa::RefTable::RefTable ( AipsIO ,
const String name,
uInt  nrrow,
int  option,
const TableLock lockOptions,
const TSMOption tsmOption 
)

Create a reference table out of a file (written by writeRefTable).

The referenced table will also be created (if not stored in the cache).

virtual casa::RefTable::~RefTable ( ) [virtual]

The destructor flushes (i.e.

writes) the table if it is opened for output and not marked for delete.

casa::RefTable::RefTable ( const RefTable ) [private]

Copy constructor is forbidden, because copying a table requires some more knowledge (like table name of result).

Declaring it private, makes it unusable.


Member Function Documentation

virtual TableDesc casa::RefTable::actualTableDesc ( ) const [virtual]

Get the actual table description.

Implements casa::BaseTable.

virtual void casa::RefTable::addColumn ( const ColumnDesc columnDesc,
Bool  addToParent 
) [virtual]

Add one or more columns to the table.

The column is added to the parent table if told so and if not existing.

Reimplemented from casa::BaseTable.

virtual void casa::RefTable::addColumn ( const ColumnDesc columnDesc,
const String dataManager,
Bool  byName,
Bool  addToParent 
) [virtual]

Reimplemented from casa::BaseTable.

virtual void casa::RefTable::addColumn ( const ColumnDesc columnDesc,
const DataManager dataManager,
Bool  addToParent 
) [virtual]

Reimplemented from casa::BaseTable.

virtual void casa::RefTable::addColumn ( const TableDesc tableDesc,
const DataManager dataManager,
Bool  addToParent 
) [virtual]

Reimplemented from casa::BaseTable.

void casa::RefTable::addRefCol ( const ColumnDesc cd) [private]

Add a column.

void casa::RefTable::addRefCol ( const TableDesc tdesc) [private]

Add multiple columns.

void casa::RefTable::addRownr ( uInt  rownr)

Add a rownr to reference table.

virtual Bool casa::RefTable::adjustRownrs ( uInt  nrrow,
Vector< uInt > &  rownrs,
Bool  determineOrder 
) const [virtual]

Adjust the row numbers to be the actual row numbers in the root table.

This is, for instance, used when a RefTable is sorted. Optionally it also determines if the resulting rows are in row order.

Reimplemented from casa::BaseTable.

virtual Bool casa::RefTable::asBigEndian ( ) const [virtual]

Is the table stored in big or little endian format?

Implements casa::BaseTable.

virtual Bool casa::RefTable::canRemoveColumn ( const Vector< String > &  columnNames) const [virtual]

Test if columns can be removed (yes).

Implements casa::BaseTable.

virtual Bool casa::RefTable::canRemoveRow ( ) const [virtual]

Test if it is possible to remove a row from this table.

Reimplemented from casa::BaseTable.

virtual Bool casa::RefTable::canRenameColumn ( const String columnName) const [virtual]

Test if a column can be renamed (yes).

Implements casa::BaseTable.

Bool casa::RefTable::checkAddColumn ( const String name,
Bool  addToParent 
) [private]

Check if a column can be added.

Return True if it can and must be added to the parent table first.

virtual void casa::RefTable::copy ( const String newName,
int  tableOption 
) const [virtual]

This is doing a shallow copy.

It gives an error if the RefTable has not been stored yet.

Reimplemented from casa::BaseTable.

void casa::RefTable::copyRefTable ( const String newName,
int  tableOption 
) [private]

Copy a RefTable that is not persistent.

It requires some special logic.

virtual Record casa::RefTable::dataManagerInfo ( ) const [virtual]

Get the data manager info.

Implements casa::BaseTable.

virtual void casa::RefTable::deepCopy ( const String newName,
const Record dataManagerInfo,
int  tableOption,
Bool  ,
int  endianFormat,
Bool  noRows 
) const [virtual]

Copy the table and all its subtables.

It copies the contents of each row to get a real copy.

Reimplemented from casa::BaseTable.

virtual DataManager* casa::RefTable::findDataManager ( const String name,
Bool  byColumn 
) const [virtual]

Find the data manager with the given name or for the given column.

Implements casa::BaseTable.

virtual void casa::RefTable::flush ( Bool  fsync,
Bool  recursive 
) [virtual]

Flush the table, i.e.

write it to disk. Nothing will be done if the table is not writable. A flush can be executed at any time. When a table is marked for delete, the destructor will remove files written by intermediate flushes. Note that if necessary the destructor will do an implicit flush, unless it is executed due to an exception.

Implements casa::BaseTable.

virtual BaseColumn* casa::RefTable::getColumn ( uInt  columnIndex) const [virtual]

Get a column object using its index.

Implements casa::BaseTable.

virtual BaseColumn* casa::RefTable::getColumn ( const String columnName) const [virtual]

Get a column object using its name.

Implements casa::BaseTable.

static void casa::RefTable::getLayout ( TableDesc desc,
AipsIO ios 
) [static]

Return the layout of a table (i.e.

description and #rows). This function has the advantage that only the minimal amount of information required is read from the table, thus it is much faster than a normal table open.
The number of rows is returned. The description of the table is stored in desc (its contents will be overwritten).

virtual uInt casa::RefTable::getModifyCounter ( ) const [virtual]

Get the modify counter.

Implements casa::BaseTable.

virtual void casa::RefTable::getPartNames ( Block< String > &  names,
Bool  recursive 
) const [private, virtual]

Get the names of the tables this table consists of.

Reimplemented from casa::BaseTable.

void casa::RefTable::getRef ( AipsIO ,
int  option,
const TableLock lockOptions,
const TSMOption tsmOption 
)

Read a reference table from a file.

The referenced table will also be created (if not stored in the cache).

static uInt* casa::RefTable::getStorage ( Vector< uInt > &  rownrs) [static]

Get the internal pointer in a rowStorage vector.

It checks whether no copy is made of the data.

virtual Bool casa::RefTable::hasLock ( FileLocker::LockType  ) const [virtual]

Has this process the read or write lock, thus can the table be read or written safely?

Implements casa::BaseTable.

virtual Bool casa::RefTable::isMultiUsed ( Bool  checkSubTable) const [virtual]

Is the table in use (i.e.

open) in another process? It always returns False.

Implements casa::BaseTable.

virtual Bool casa::RefTable::isWritable ( ) const [virtual]

Test if the parent table is opened as writable.

Implements casa::BaseTable.

virtual TableRecord& casa::RefTable::keywordSet ( ) [virtual]

Get readonly access to the table keyword set.

Implements casa::BaseTable.

virtual Bool casa::RefTable::lock ( FileLocker::LockType  ,
uInt  nattempts 
) [virtual]

Try to lock the table for read or write access.

Implements casa::BaseTable.

virtual const TableLock& casa::RefTable::lockOptions ( ) const [virtual]

Get the locking info.

Implements casa::BaseTable.

static void casa::RefTable::makeDesc ( TableDesc desc,
const TableDesc rootDesc,
SimpleOrderedMap< String, String > &  nameMap,
Vector< String > &  names 
) [static, private]

Make a table description for the given columns.

void casa::RefTable::makeRefCol ( ) [private]

Create the RefColumn objects for all columns in the description.

virtual void casa::RefTable::mergeLock ( const TableLock lockOptions) [virtual]

Merge the given lock info with the existing one.

Implements casa::BaseTable.

RefTable& casa::RefTable::operator= ( const RefTable ) [private]

Assignment is forbidden, because copying a table requires some more knowledge (like table name of result).

Declaring it private, makes it unusable.

void casa::RefTable::refAnd ( uInt  nr1,
const uInt rows1,
uInt  nr2,
const uInt rows2 
)

And, or, subtract or xor the row numbers of 2 tables.

void casa::RefTable::refNot ( uInt  nr1,
const uInt rows1,
uInt  nrmain 
)
void casa::RefTable::refOr ( uInt  nr1,
const uInt rows1,
uInt  nr2,
const uInt rows2 
)
void casa::RefTable::refSub ( uInt  nr1,
const uInt rows1,
uInt  nr2,
const uInt rows2 
)
void casa::RefTable::refXor ( uInt  nr1,
const uInt rows1,
uInt  nr2,
const uInt rows2 
)
virtual void casa::RefTable::removeColumn ( const Vector< String > &  columnNames) [virtual]

Remove columns.

Implements casa::BaseTable.

virtual void casa::RefTable::removeRow ( uInt  rownr) [virtual]

Remove the given row.

Reimplemented from casa::BaseTable.

virtual void casa::RefTable::renameColumn ( const String newName,
const String oldName 
) [virtual]

Rename a column.

Implements casa::BaseTable.

virtual void casa::RefTable::renameHypercolumn ( const String newName,
const String oldName 
) [virtual]

Rename a hypercolumn.

Implements casa::BaseTable.

virtual void casa::RefTable::reopenRW ( ) [virtual]

Try to reopen the table (the underlying one) for read/write access.

An exception is thrown if the table is not writable. Nothing is done if the table is already open for read/write.

Implements casa::BaseTable.

virtual void casa::RefTable::resync ( ) [virtual]

Resync the Table object with the table file.

Implements casa::BaseTable.

virtual BaseTable* casa::RefTable::root ( ) [virtual]

Get parent of this table.

Reimplemented from casa::BaseTable.

uInt casa::RefTable::rootRownr ( uInt  rownr) const [inline]

Get rownr in root table.

This converts the given row number to the row number in the root table.

Definition at line 388 of file RefTable.h.

References rows_p.

Vector<uInt> casa::RefTable::rootRownr ( const Vector< uInt > &  rownrs) const

Get vector of rownrs in root table.

This converts the given row numbers to row numbers in the root table.

virtual Vector<uInt> casa::RefTable::rowNumbers ( ) const [virtual]

Get a vector of row numbers.

Reimplemented from casa::BaseTable.

virtual Bool casa::RefTable::rowOrder ( ) const [virtual]

Tell if the table is in row order.

Reimplemented from casa::BaseTable.

virtual Vector<uInt>* casa::RefTable::rowStorage ( ) [virtual]

Get row number vector.

This is used by the BaseTable logic and sort routines.

Reimplemented from casa::BaseTable.

virtual TableRecord& casa::RefTable::rwKeywordSet ( ) [virtual]

Get read/write access to the table keyword set.

This requires that the table is locked (or it gets locked when using AutoLocking mode).

Implements casa::BaseTable.

void casa::RefTable::setNrrow ( uInt  nrrow)

Set the exact number of rows in the table.

An exception is thrown if more than current nrrow.

void casa::RefTable::setup ( BaseTable btp,
const Vector< String > &  columnNames 
) [private]

Setup the main parts of the object.


First create the name map (mapping column name in RefTable to the column in the original table). If the BaseTable is a RefTable, use its name map. Otherwise create the initial name map from the table description. A rename might change the map.
Create the RefColumn objects.
Create the initial TableInfo as a copy of the original BaseTable.

void casa::RefTable::showStructureExtra ( std::ostream &  ) const [private, virtual]

Show the extra table structure info (name of root table).

Reimplemented from casa::BaseTable.

virtual int casa::RefTable::tableType ( ) const [virtual]

It returns the type of the parent table.

Reimplemented from casa::BaseTable.

virtual void casa::RefTable::unlock ( ) [virtual]

Unlock the table.

This will also synchronize the table data, thus force the data to be written to disk.

Implements casa::BaseTable.

void casa::RefTable::writeRefTable ( Bool  fsync) [private]

Write a reference table.


Member Data Documentation

Definition at line 328 of file RefTable.h.

Definition at line 334 of file RefTable.h.

Definition at line 333 of file RefTable.h.

Definition at line 332 of file RefTable.h.

Definition at line 329 of file RefTable.h.

Definition at line 331 of file RefTable.h.

Referenced by rootRownr().

Definition at line 330 of file RefTable.h.


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