PlainTable.h

Go to the documentation of this file.
00001 //# PlainTable.h: Class defining a plain regular table
00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 
00028 #ifndef TABLES_PLAINTABLE_H
00029 #define TABLES_PLAINTABLE_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <tables/Tables/BaseTable.h>
00035 #include <tables/Tables/TableCache.h>
00036 #include <tables/Tables/TableRecord.h>
00037 #include <tables/Tables/TableSyncData.h>
00038 #include <casa/IO/AipsIO.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 //# Forward Declarations
00043 class SetupNewTable;
00044 class TableLock;
00045 class TableLockData;
00046 class ColumnSet;
00047 class IPosition;
00048 class AipsIO;
00049 class MemoryIO;
00050 
00051 
00052 // <summary>
00053 // Class defining a plain regular table
00054 // </summary>
00055 
00056 // <use visibility=local>
00057 
00058 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
00059 // </reviewed>
00060 
00061 // <prerequisite>
00062 //# Classes you should understand before using this one.
00063 //   <li> BaseTable
00064 //   <li> BaseColumn
00065 // </prerequisite>
00066 
00067 // <etymology>
00068 // PlainTable represents a plain regular table. This is opposed to a
00069 // RefTable, which is a view on a PlainTable.
00070 // </etymology>
00071 
00072 // <synopsis> 
00073 // PlainTable is a table consisting of a keyword set and a number of
00074 // filled and virtual columns. The table control information and the
00075 // keyword set is stored in an AipsIO file. The data in the filled columns
00076 // are stored separately by storage managers.
00077 // </synopsis> 
00078 
00079 // <todo asof="$DATE:$">
00080 //# A List of bugs, limitations, extensions or planned refinements.
00081 //   <li> notify RefTable's when deleting rows
00082 // </todo>
00083 
00084 class PlainTable : public BaseTable
00085 {
00086 public:
00087 
00088     // Construct the object for a new table.
00089     // It creates storage manager(s) for unbound columns and initializes
00090     // all storage managers. The given number of rows is stored in
00091     // the table and initialized if the flag is set.
00092     PlainTable (SetupNewTable&, uInt nrrow, Bool initialize,
00093                 const TableLock& lockOptions, int endianFormat);
00094 
00095     // Construct the object for an existing table.
00096     // It opens the table file, reads the table control information
00097     // and creates and initializes the required storage managers.
00098     PlainTable (AipsIO&, uInt version, const String& name, const String& type,
00099                 uInt nrrow, int option, const TableLock& lockOptions,
00100                 Bool addToCache, uInt locknr);
00101 
00102     // The destructor flushes (i.e. writes) the table if it is opened
00103     // for output and not marked for delete.
00104     virtual ~PlainTable();
00105 
00106     // Return the layout of a table (i.e. description and #rows).
00107     // This function has the advantage that only the minimal amount of
00108     // information required is read from the table, thus it is much
00109     // faster than a normal table open.
00110     // <br> The number of rows is returned. The description of the table
00111     // is stored in desc (its contents will be overwritten).
00112     static void getLayout (TableDesc& desc, AipsIO& ios);
00113 
00114     // Try to reopen the table for read/write access.
00115     // An exception is thrown if the table is not writable.
00116     // Nothing is done if the table is already open for read/write.
00117     virtual void reopenRW();
00118 
00119     // Is the table stored in big or little endian format?
00120     virtual Bool asBigEndian() const;
00121 
00122     // Is the table in use (i.e. open) in another process?
00123     // If <src>checkSubTables</src> is set, it is also checked if
00124     // a subtable is used in another process.
00125     virtual Bool isMultiUsed (Bool checkSubTables) const;
00126 
00127     // Get the locking info.
00128     virtual const TableLock& lockOptions() const;
00129 
00130     // Merge the given lock info with the existing one.
00131     virtual void mergeLock (const TableLock& lockOptions);
00132 
00133     // Has this process the read or write lock, thus can the table
00134     // be read or written safely?
00135     virtual Bool hasLock (FileLocker::LockType) const;
00136 
00137     // Try to lock the table for read or write access.
00138     virtual Bool lock (FileLocker::LockType, uInt nattempts);
00139 
00140     // Unlock the table. This will also synchronize the table data,
00141     // thus force the data to be written to disk.
00142     virtual void unlock();
00143 
00144     // Do a release of an AutoLock when the inspection interval has expired.
00145     // <src>always=True</src> means that the inspection is always done,
00146     // thus not every 25th call or so.
00147     void autoReleaseLock (Bool always = False);
00148 
00149     // Flush the table, i.e. write it to disk.
00150     // Nothing will be done if the table is not writable.
00151     // A flush can be executed at any time.
00152     // When a table is marked for delete, the destructor will remove
00153     // files written by intermediate flushes.
00154     // Note that if necessary the destructor will do an implicit flush,
00155     // unless it is executed due to an exception.
00156     virtual void flush (Bool fsync, Bool recursive);
00157 
00158     // Resync the Table object with the table file.
00159     virtual void resync();
00160 
00161     // Get the modify counter.
00162     virtual uInt getModifyCounter() const;
00163 
00164     // Set the table to being changed.
00165     virtual void setTableChanged();
00166 
00167     // Convert a Table option to an AipsIO file option.
00168     // This is used by storage managers.
00169     static ByteIO::OpenOption toAipsIOFoption (int tableOption);
00170 
00171     // Test if the table is opened as writable.
00172     virtual Bool isWritable() const;
00173 
00174     // Get the actual table description.
00175     virtual TableDesc actualTableDesc() const;
00176 
00177     // Get the data manager info.
00178     virtual Record dataManagerInfo() const;
00179 
00180     // Get readonly access to the table keyword set.
00181     virtual TableRecord& keywordSet();
00182 
00183     // Get read/write access to the table keyword set.
00184     // This requires that the table is locked (or it gets locked
00185     // when using AutoLocking mode).
00186     virtual TableRecord& rwKeywordSet();
00187 
00188     // Get a column object using its index.
00189     virtual BaseColumn* getColumn (uInt columnIndex) const;
00190 
00191     // Get a column object using its name.
00192     virtual BaseColumn* getColumn (const String& columnName) const;
00193 
00194     // Test if it is possible to add a row to this table.
00195     virtual Bool canAddRow() const;
00196 
00197     // Add one or more rows and possibly initialize them.
00198     // This will fail for tables not supporting addition of rows.
00199     virtual void addRow (uInt nrrow, Bool initialize);
00200 
00201     // Test if it is possible to remove a row from this table.
00202     virtual Bool canRemoveRow() const;
00203 
00204     // Remove the given row.
00205     // This will fail for tables not supporting removal of rows.
00206     virtual void removeRow (uInt rownr);
00207 
00208     // Add a column to the table.
00209     // The default implementation throws an "invalid operation" exception.
00210     // <group>
00211     virtual void addColumn (const ColumnDesc& columnDesc);
00212     virtual void addColumn (const ColumnDesc& columnDesc,
00213                             const String& dataManager, Bool byName);
00214     virtual void addColumn (const ColumnDesc& columnDesc,
00215                             const DataManager& dataManager);
00216     virtual void addColumn (const TableDesc& tableDesc,
00217                             const DataManager& dataManager);
00218     // </group>
00219 
00220     // Test if columns can be removed.
00221     virtual Bool canRemoveColumn (const Vector<String>& columnNames) const;
00222 
00223     // Remove columns.
00224     virtual void removeColumn (const Vector<String>& columnNames);
00225 
00226     // Test if a column can be renamed (yes).
00227     virtual Bool canRenameColumn (const String& columnName) const;
00228 
00229     // Rename a column.
00230     virtual void renameColumn (const String& newName, const String& oldName);
00231 
00232     // Find the data manager with the given name.
00233     virtual DataManager* findDataManager (const String& dataManagerName) const;
00234 
00235 
00236     static TableCache tableCache;           //# cache of open (plain) tables
00237 
00238 private:
00239     // Copy constructor is forbidden, because copying a table requires
00240     // some more knowledge (like table name of result).
00241     // Declaring it private, makes it unusable.
00242     PlainTable (const PlainTable&);
00243 
00244     // Assignment is forbidden, because copying a table requires
00245     // some more knowledge (like table name of result).
00246     // Declaring it private, makes it unusable.
00247     PlainTable& operator= (const PlainTable&);
00248 
00249     // Rename the subtables (used by rename function).
00250     virtual void renameSubTables (const String& newName,
00251                                   const String& oldName);
00252 
00253     // The callback function when a lock is released.
00254     // This flushes the table data, writes the synchronization data
00255     // into the MemoryIO object, and returns a pointer to it.
00256     // <group>
00257     static MemoryIO* releaseCallBack (void* plainTableObject, Bool always);
00258     MemoryIO* doReleaseCallBack (Bool always);
00259     // </group>
00260 
00261     // When needed, write the table control information in an AipsIO file.
00262     // Tell the storage managers to flush and close their files.
00263     // It returns a switch to tell if the table control information has
00264     // been written.
00265     Bool putFile (Bool always);
00266 
00267     // Synchronize the table after having acquired a lock which says
00268     // that main table data has changed.
00269     // It check if the columns did not change.
00270     // It updates the table and column keywords.
00271     void syncTable();
00272 
00273     // Determine and set the endian format (big or little).
00274     void setEndian (int endianFormat);
00275 
00276 
00277     ColumnSet*     colSetPtr_p;        //# pointer to set of columns
00278     Bool           tableChanged_p;     //# Has the main data changed?
00279     Bool           addToCache_p;       //# Is table added to cache?
00280     TableLockData* lockPtr_p;          //# pointer to lock object
00281     TableSyncData  lockSync_p;         //# table synchronization
00282     Bool           bigEndian_p;        //# True  = big endian canonical
00283                                        //# False = little endian canonical
00284 };
00285 
00286 
00287 
00288 } //# NAMESPACE CASA - END
00289 
00290 #endif

Generated on Mon Sep 1 22:36:23 2008 for NRAOCASA by  doxygen 1.5.1