RefTable.h
Classes
- RefTable -- Class for a table as a view of another table (full description)
Interface
- Public Members
- RefTable (BaseTable*, Bool rowOrder, uInt initialNrrow)
- RefTable (BaseTable*, const Vector<uInt>& rowNumbers)
- RefTable (BaseTable*, const Vector<Bool>& rowMask)
- RefTable (BaseTable*, const Vector<String>& columnNames)
- RefTable (AipsIO&, const String& name, uInt nrrow, int option, const TableLock& lockOptions)
- virtual ~RefTable()
- static void getLayout (TableDesc& desc, AipsIO& ios)
- virtual void reopenRW()
- virtual Bool asBigEndian() const
- virtual Bool isMultiUsed (Bool checkSubTable) const
- virtual const TableLock& lockOptions() const
- virtual void mergeLock (const TableLock& lockOptions)
- virtual Bool hasLock (FileLocker::LockType) const
- virtual Bool lock (FileLocker::LockType, uInt nattempts)
- virtual void unlock()
- virtual void flush (Bool sync)
- virtual void resync()
- virtual uInt getModifyCounter() const
- virtual Bool isWritable() const
- void getRef (AipsIO&, int option, const TableLock& lockOptions)
- virtual void deepCopy (const String& newName, const Record& dataManagerInfo, int tableOption, Bool) const
- virtual TableDesc actualTableDesc() const
- virtual Record dataManagerInfo() const
- virtual TableRecord& keywordSet()
- virtual TableRecord& rwKeywordSet()
- virtual BaseColumn* getColumn (uInt columnIndex) const
- virtual BaseColumn* getColumn (const String& columnName) const
- virtual Bool canRemoveRow() const
- virtual void removeRow (uInt rownr)
- virtual Bool canRemoveColumn (const Vector<String>& columnNames) const
- virtual void removeColumn (const Vector<String>& columnNames)
- virtual Bool canRenameColumn (const String& columnName) const
- virtual void renameColumn (const String& newName, const String& oldName)
- virtual DataManager* findDataManager (const String& dataManagerName) const
- virtual Vector<uInt> rowNumbers() const
- virtual BaseTable* root()
- uInt rootRownr (uInt rownr) const
- Vector<uInt> rootRownr (const Vector<uInt>& rownrs) const
- virtual Bool rowOrder() const
- virtual Vector<uInt>* rowStorage()
- void addRownr (uInt rownr)
- void setNrrow (uInt nrrow)
- virtual Bool adjustRownrs (uInt nrrow, Vector<uInt>& rownrs, Bool determineOrder) const
- void refAnd (uInt nr1, const uInt* rows1, uInt nr2, const uInt* rows2)
- 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 uInt* getStorage (Vector<uInt>& rownrs)
- Private Members
- RefTable (const RefTable&)
- RefTable& operator= (const RefTable&)
- static void makeDesc (TableDesc& desc, const TableDesc& rootDesc, SimpleOrderedMap<String,String>& nameMap, Vector<String>& names)
- void setup (BaseTable* btp)
- void makeRefCol()
- void writeRefTable (Bool sync)
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
- Maybe not allocating the row number vector for a projection.
This saves space and time, but each rownr conversion will
take a bit more time because it has to test if there is a vector.
- Maybe maintain a Vector telling on which columns
the table is ordered. This may speed up selection, but
it is hard to check if the order is changed by a put.
- Allow to remove a row or column from the RefTable
- Allow to rename a column in the RefTable
- Maybe implement doSort one time for a more efficient sort.
(now everything is handled by BaseTable).
Member Description
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..
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.
A RefTable with the given row numbers is constructed.
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.
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.
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.
Create a reference table object via projection (i.e. column selection).
The row number vector is a copy of the given table.
RefTable (AipsIO&, const String& name, uInt nrrow, int option, const TableLock& lockOptions)
Create a reference table out of a file (written by writeRefTable).
The referenced table will also be created (if not stored in the cache).
The destructor flushes (i.e. writes) the table if it is opened
for output and not marked for delete.
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).
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.
Is the table stored in big or little endian format?
virtual Bool isMultiUsed (Bool checkSubTable) const
Is the table in use (i.e. open) in another process?
It always returns False.
Get the locking info.
Merge the given lock info with the existing one.
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. This will also synchronize the table data,
thus force the data to be written to disk.
virtual void flush (Bool sync)
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.
virtual void resync()
Resync the Table object with the table file.
Get the modify counter.
virtual Bool isWritable() const
Test if the parent table is opened as writable.
Read a reference table from a file.
The referenced table will also be created (if not stored in the cache).
virtual void deepCopy (const String& newName, const Record& dataManagerInfo, int tableOption, Bool) const
Copy the table and all its subtables.
It copies the contents of each row to get a real copy.
Get the actual table description.
Get the data manager info.
Get readonly access to the table keyword set.
Get read/write access to the table keyword set.
This requires that the table is locked (or it gets locked
when using AutoLocking mode).
Get a column object using its index.
Get a column object using its name.
Test if it is possible to remove a row from this table.
virtual void removeRow (uInt rownr)
Remove the given row.
Test if columns can be removed (yes).
Remove columns.
Test if a column can be renamed (no).
Rename a column.
Find the data manager with the given name.
Get a vector of row numbers.
Get parent of this table.
uInt rootRownr (uInt rownr) const
Get rownr in root table.
This converts the given row number to the row number in the root table.
Get vector of rownrs in root table.
This converts the given row numbers to row numbers in the root table.
virtual Bool rowOrder() const
Tell if the table is in row order.
Get row number vector.
This is used by the BaseTable logic and sort routines.
void addRownr (uInt rownr)
Add a rownr to reference table.
void setNrrow (uInt nrrow)
Set the exact number of rows in the table.
An exception is thrown if more than current nrrow.
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. This is, for instance, used when a RefTable is sorted.
Optionally it also determines if the resulting rows are in row order.
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)
Get the internal pointer in a rowStorage vector.
It checks whether no copy is made of the data.
RefTable (const RefTable&)
Copy constructor is forbidden, because copying a table requires
some more knowledge (like table name of result).
Declaring it private, makes it unusable.
RefTable& operator= (const RefTable&)
Assignment is forbidden, because copying a table requires
some more knowledge (like table name of result).
Declaring it private, makes it unusable.
Setup the main parts of the object.
Create the initial name map from the table description.
This map maps a name to the name in the original table.
A rename might change the map.
Create the RefColumn objects.
Create the initial TableInfo as a copy of the original BaseTable.
Create the RefColumn objects for all columns in the description.
Write a reference table.