casacore
Loading...
Searching...
No Matches
PlainTable.h
Go to the documentation of this file.
1//# PlainTable.h: Class defining a plain regular table
2//# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef TABLES_PLAINTABLE_H
27#define TABLES_PLAINTABLE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/tables/Tables/BaseTable.h>
33#include <casacore/tables/Tables/TableCache.h>
34#include <casacore/tables/Tables/TableRecord.h>
35#include <casacore/tables/Tables/TableSyncData.h>
36#include <casacore/tables/DataMan/TSMOption.h>
37#include <casacore/casa/IO/AipsIO.h>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41//# Forward Declarations
42class SetupNewTable;
43class TableLock;
44class TableLockData;
45class ColumnSet;
46class IPosition;
47class AipsIO;
48class MemoryIO;
49
50
51// <summary>
52// Class defining a plain regular table
53// </summary>
54
55// <use visibility=local>
56
57// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
58// </reviewed>
59
60// <prerequisite>
61//# Classes you should understand before using this one.
62// <li> BaseTable
63// <li> BaseColumn
64// </prerequisite>
65
66// <etymology>
67// PlainTable represents a plain regular table. This is opposed to a
68// RefTable, which is a view on a PlainTable.
69// </etymology>
70
71// <synopsis>
72// PlainTable is a table consisting of a keyword set and a number of
73// filled and virtual columns. The table control information and the
74// keyword set is stored in an AipsIO file. The data in the filled columns
75// are stored separately by storage managers.
76// <br> The PlainTable class structure is shown in this
77// <a href="PlainTable.drawio.svg.html">UML diagram</a>.
78// </synopsis>
79
80// <todo asof="$DATE:$">
81//# A List of bugs, limitations, extensions or planned refinements.
82// <li> notify RefTable's when deleting rows
83// </todo>
84
85class PlainTable : public BaseTable
86{
87public:
88
89 // Construct the object for a new table.
90 // It creates storage manager(s) for unbound columns and initializes
91 // all storage managers. The given number of rows is stored in
92 // the table and initialized if the flag is set.
93 PlainTable (SetupNewTable&, rownr_t nrrow, Bool initialize,
94 const TableLock& lockOptions, int endianFormat,
95 const TSMOption& tsmOption);
96
97#ifdef HAVE_MPI
98 // MPI version of the constructor
99 PlainTable (MPI_Comm mpiComm, SetupNewTable&, rownr_t nrrow,
100 Bool initialize, const TableLock& lockOptions,
101 int endianFormat, const TSMOption& tsmOption);
102#endif
103
104 // Common part of the constructor shared by MPI and non-MPI
105 void PlainTableCommon (SetupNewTable&, rownr_t nrrow, Bool initialize,
106 const TableLock& lockOptions, int endianFormat,
107 const TSMOption& tsmOption);
108
109 // Construct the object for an existing table.
110 // It opens the table file, reads the table control information
111 // and creates and initializes the required storage managers.
112 PlainTable (AipsIO&, uInt version, const String& name, const String& type,
113 rownr_t nrrow, int option, const TableLock& lockOptions,
114 const TSMOption& tsmOption, Bool addToCache, uInt locknr);
115
116 // The destructor flushes (i.e. writes) the table if it is opened
117 // for output and not marked for delete.
118 virtual ~PlainTable();
119
120 // Copy constructor is forbidden, because copying a table requires
121 // some more knowledge (like table name of result).
122 PlainTable (const PlainTable&) = delete;
123
124 // Assignment is forbidden, because copying a table requires
125 // some more knowledge (like table name of result).
127
128 // Return the layout of a table (i.e. description and #rows).
129 // This function has the advantage that only the minimal amount of
130 // information required is read from the table, thus it is much
131 // faster than a normal table open.
132 // <br> The number of rows is returned. The description of the table
133 // is stored in desc (its contents will be overwritten).
134 static void getLayout (TableDesc& desc, AipsIO& ios);
135
136 // Try to reopen the table for read/write access.
137 // An exception is thrown if the table is not writable.
138 // Nothing is done if the table is already open for read/write.
139 virtual void reopenRW();
140
141 // Is the table stored in big or little endian format?
142 virtual Bool asBigEndian() const;
143
144 // Get the storage option used for the table.
145 virtual const StorageOption& storageOption() const;
146
147 // Is the table in use (i.e. open) in another process?
148 // If <src>checkSubTables</src> is set, it is also checked if
149 // a subtable is used in another process.
150 virtual Bool isMultiUsed (Bool checkSubTables) const;
151
152 // Get the locking info.
153 virtual const TableLock& lockOptions() const;
154
155 // Merge the given lock info with the existing one.
156 virtual void mergeLock (const TableLock& lockOptions);
157
158 // Has this process the read or write lock, thus can the table
159 // be read or written safely?
161
162 // Try to lock the table for read or write access.
163 virtual Bool lock (FileLocker::LockType, uInt nattempts);
164
165 // Unlock the table. This will also synchronize the table data,
166 // thus force the data to be written to disk.
167 virtual void unlock();
168
169 // Do a release of an AutoLock when the inspection interval has expired.
170 // <src>always=True</src> means that the inspection is always done,
171 // thus not every 25th call or so.
172 void autoReleaseLock (Bool always = False);
173
174 // Flush the table, i.e. write it to disk.
175 // Nothing will be done if the table is not writable.
176 // A flush can be executed at any time.
177 // When a table is marked for delete, the destructor will remove
178 // files written by intermediate flushes.
179 // Note that if necessary the destructor will do an implicit flush,
180 // unless it is executed due to an exception.
181 virtual void flush (Bool fsync, Bool recursive);
182
183 // Resync the Table object with the table file.
184 virtual void resync();
185
186 // Get the modify counter.
187 virtual uInt getModifyCounter() const;
188
189 // Set the table to being changed.
190 virtual void setTableChanged();
191
192 // Convert a Table option to an AipsIO file option.
193 // This is used by storage managers.
195
196 // Test if the table is opened as writable.
197 virtual Bool isWritable() const;
198
199 // Get the actual table description.
200 virtual TableDesc actualTableDesc() const;
201
202 // Get the data manager info.
203 virtual Record dataManagerInfo() const;
204
205 // Get readonly access to the table keyword set.
207
208 // Get read/write access to the table keyword set.
209 // This requires that the table is locked (or it gets locked
210 // when using AutoLocking mode).
212
213 // Get a column object using its index.
214 virtual BaseColumn* getColumn (uInt columnIndex) const;
215
216 // Get a column object using its name.
217 virtual BaseColumn* getColumn (const String& columnName) const;
218
219 // Test if it is possible to add a row to this table.
220 virtual Bool canAddRow() const;
221
222 // Add one or more rows and possibly initialize them.
223 // This will fail for tables not supporting addition of rows.
224 virtual void addRow (rownr_t nrrow, Bool initialize);
225
226 // Test if it is possible to remove a row from this table.
227 virtual Bool canRemoveRow() const;
228
229 // Remove the given row.
230 // This will fail for tables not supporting removal of rows.
231 virtual void removeRow (rownr_t rownr);
232
233 // Add a column to the table.
234 // The last Bool argument is not used in PlainTable, but can be used in
235 // other classes derived from BaseTable.
236 // <group>
237 virtual void addColumn (const ColumnDesc& columnDesc, Bool);
238 virtual void addColumn (const ColumnDesc& columnDesc,
239 const String& dataManager, Bool byName, Bool);
240 virtual void addColumn (const ColumnDesc& columnDesc,
241 const DataManager& dataManager, Bool);
242 virtual void addColumn (const TableDesc& tableDesc,
243 const DataManager& dataManager, Bool);
244 // </group>
245
246 // Test if columns can be removed.
247 virtual Bool canRemoveColumn (const Vector<String>& columnNames) const;
248
249 // Remove columns.
250 virtual void removeColumn (const Vector<String>& columnNames);
251
252 // Test if a column can be renamed (yes).
253 virtual Bool canRenameColumn (const String& columnName) const;
254
255 // Rename a column.
256 virtual void renameColumn (const String& newName, const String& oldName);
257
258 // Rename a hypercolumn.
259 virtual void renameHypercolumn (const String& newName,
260 const String& oldName);
261
262 // Find the data manager with the given name or for the given column.
263 virtual DataManager* findDataManager (const String& name,
264 Bool byColumn) const;
265
266
267 // Get access to the TableCache.
269 { return theirTableCache; }
270
271private:
272 // Close the object which is called by the destructor.
274
275 // Rename the subtables (used by rename function).
276 virtual void renameSubTables (const String& newName,
277 const String& oldName);
278
279 // The callback function when a lock is released.
280 // This flushes the table data, writes the synchronization data
281 // into the MemoryIO object, and returns a pointer to it.
282 // <group>
283 static MemoryIO* releaseCallBack (void* plainTableObject, Bool always);
285 // </group>
286
287 // When needed, write the table control information in an AipsIO file.
288 // Tell the storage managers to flush and close their files.
289 // It returns a switch to tell if the table control information has
290 // been written.
291 Bool putFile (Bool always);
292
293 // Synchronize the table after having acquired a lock which says
294 // that main table data has changed.
295 // It check if the columns did not change.
296 // It updates the table and column keywords.
297 void syncTable();
298
299 // Determine and set the endian format (big or little).
300 void setEndian (int endianFormat);
301
302 // Throw an exception if the table is not writable.
303 void checkWritable (const char* func) const;
304
305
306 std::shared_ptr<ColumnSet> colSetPtr_p; //# pointer to set of columns
307 Bool tableChanged_p; //# Has the main data changed?
308 Bool addToCache_p; //# Is table added to cache?
309 TableLockData* lockPtr_p; //# pointer to lock object
310 TableSyncData lockSync_p; //# table synchronization
311 Bool bigEndian_p; //# True = big endian canonical
312 //# False = little endian canonical
314 //# cache of open (plain) tables
316};
317
318
319
320} //# NAMESPACE CASACORE - END
321
322#endif
const TableDesc & tableDesc() const
Get the table description.
Definition BaseTable.h:272
int tableOption() const
Get the table option.
Definition BaseTable.h:253
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:63
Abstract base class for a data manager.
LockType
Define the possible lock types.
Definition FileLocker.h:93
TableSyncData lockSync_p
Definition PlainTable.h:310
virtual const TableLock & lockOptions() const
Get the locking info.
static MemoryIO * releaseCallBack(void *plainTableObject, Bool always)
The callback function when a lock is released.
virtual void mergeLock(const TableLock &lockOptions)
Merge the given lock info with the existing one.
virtual void addColumn(const TableDesc &tableDesc, const DataManager &dataManager, Bool)
virtual Bool isMultiUsed(Bool checkSubTables) const
Is the table in use (i.e.
virtual void setTableChanged()
Set the table to being changed.
virtual DataManager * findDataManager(const String &name, Bool byColumn) const
Find the data manager with the given name or for the given column.
PlainTable(MPI_Comm mpiComm, SetupNewTable &, rownr_t nrrow, Bool initialize, const TableLock &lockOptions, int endianFormat, const TSMOption &tsmOption)
MPI version of the constructor.
void setEndian(int endianFormat)
Determine and set the endian format (big or little).
void checkWritable(const char *func) const
Throw an exception if the table is not writable.
virtual void removeColumn(const Vector< String > &columnNames)
Remove columns.
virtual Bool canRemoveColumn(const Vector< String > &columnNames) const
Test if columns can be removed.
PlainTable(const PlainTable &)=delete
Copy constructor is forbidden, because copying a table requires some more knowledge (like table name ...
void syncTable()
Synchronize the table after having acquired a lock which says that main table data has changed.
virtual Bool canRenameColumn(const String &columnName) const
Test if a column can be renamed (yes).
void PlainTableCommon(SetupNewTable &, rownr_t nrrow, Bool initialize, const TableLock &lockOptions, int endianFormat, const TSMOption &tsmOption)
Common part of the constructor shared by MPI and non-MPI.
virtual void renameColumn(const String &newName, const String &oldName)
Rename a column.
virtual uInt getModifyCounter() const
Get the modify counter.
virtual BaseColumn * getColumn(uInt columnIndex) const
Get a column object using its index.
void autoReleaseLock(Bool always=False)
Do a release of an AutoLock when the inspection interval has expired.
MemoryIO * doReleaseCallBack(Bool always)
Bool putFile(Bool always)
When needed, write the table control information in an AipsIO file.
virtual void renameSubTables(const String &newName, const String &oldName)
Rename the subtables (used by rename function).
virtual void renameHypercolumn(const String &newName, const String &oldName)
Rename a hypercolumn.
virtual void resync()
Resync the Table object with the table file.
virtual Record dataManagerInfo() const
Get the data manager info.
static TableCache theirTableCache
Definition PlainTable.h:315
PlainTable & operator=(const PlainTable &)=delete
Assignment is forbidden, because copying a table requires some more knowledge (like table name of res...
virtual Bool isWritable() const
Test if the table is opened as writable.
static ByteIO::OpenOption toAipsIOFoption(int tableOption)
Convert a Table option to an AipsIO file option.
virtual void addColumn(const ColumnDesc &columnDesc, const DataManager &dataManager, Bool)
virtual void addColumn(const ColumnDesc &columnDesc, const String &dataManager, Bool byName, Bool)
virtual Bool hasLock(FileLocker::LockType) const
Has this process the read or write lock, thus can the table be read or written safely?
PlainTable(AipsIO &, uInt version, const String &name, const String &type, rownr_t nrrow, int option, const TableLock &lockOptions, const TSMOption &tsmOption, Bool addToCache, uInt locknr)
Construct the object for an existing table.
virtual void flush(Bool fsync, Bool recursive)
Flush the table, i.e.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Try to lock the table for read or write access.
static void getLayout(TableDesc &desc, AipsIO &ios)
Return the layout of a table (i.e.
virtual TableRecord & keywordSet()
Get readonly access to the table keyword set.
virtual BaseColumn * getColumn(const String &columnName) const
Get a column object using its name.
virtual TableDesc actualTableDesc() const
Get the actual table description.
virtual void removeRow(rownr_t rownr)
Remove the given row.
virtual void reopenRW()
Try to reopen the table for read/write access.
virtual void addColumn(const ColumnDesc &columnDesc, Bool)
Add a column to the table.
virtual void unlock()
Unlock the table.
virtual TableRecord & rwKeywordSet()
Get read/write access to the table keyword set.
virtual const StorageOption & storageOption() const
Get the storage option used for the table.
virtual Bool canRemoveRow() const
Test if it is possible to remove a row from this table.
std::shared_ptr< ColumnSet > colSetPtr_p
Definition PlainTable.h:306
virtual ~PlainTable()
The destructor flushes (i.e.
virtual void addRow(rownr_t nrrow, Bool initialize)
Add one or more rows and possibly initialize them.
virtual Bool canAddRow() const
Test if it is possible to add a row to this table.
PlainTable(SetupNewTable &, rownr_t nrrow, Bool initialize, const TableLock &lockOptions, int endianFormat, const TSMOption &tsmOption)
Construct the object for a new table.
virtual Bool asBigEndian() const
Is the table stored in big or little endian format?
TableLockData * lockPtr_p
Definition PlainTable.h:309
static TableCache & tableCache()
Get access to the TableCache.
Definition PlainTable.h:268
void closeObject()
Close the object which is called by the destructor.
Create a new table - define shapes, data managers, etc.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44