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// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/BaseTable.h>
32#include <casacore/tables/Tables/TableCache.h>
33#include <casacore/tables/Tables/TableRecord.h>
34#include <casacore/tables/Tables/TableSyncData.h>
35#include <casacore/tables/DataMan/TSMOption.h>
36#include <casacore/casa/IO/AipsIO.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
41class SetupNewTable;
42class TableLock;
43class TableLockData;
44class ColumnSet;
45class IPosition;
46class AipsIO;
47class MemoryIO;
48
49// <summary>
50// Class defining a plain regular table
51// </summary>
52
53// <use visibility=local>
54
55// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
56// </reviewed>
57
58// <prerequisite>
59// # Classes you should understand before using this one.
60// <li> BaseTable
61// <li> BaseColumn
62// </prerequisite>
63
64// <etymology>
65// PlainTable represents a plain regular table. This is opposed to a
66// RefTable, which is a view on a PlainTable.
67// </etymology>
68
69// <synopsis>
70// PlainTable is a table consisting of a keyword set and a number of
71// filled and virtual columns. The table control information and the
72// keyword set is stored in an AipsIO file. The data in the filled columns
73// are stored separately by storage managers.
74// <br> The PlainTable class structure is shown in this
75// <a href="PlainTable.drawio.svg.html">UML diagram</a>.
76// </synopsis>
77
78// <todo asof="$DATE:$">
79// # A List of bugs, limitations, extensions or planned refinements.
80// <li> notify RefTable's when deleting rows
81// </todo>
82
83class PlainTable : public BaseTable {
84 public:
85 // Construct the object for a new table.
86 // It creates storage manager(s) for unbound columns and initializes
87 // all storage managers. The given number of rows is stored in
88 // the table and initialized if the flag is set.
90 int endianFormat, const TSMOption& tsmOption);
91
92#ifdef HAVE_MPI
93 // MPI version of the constructor
94 PlainTable(MPI_Comm mpiComm, SetupNewTable&, rownr_t nrrow, Bool initialize,
95 const TableLock& lockOptions, int endianFormat, const TSMOption& tsmOption);
96#endif
97
98 // Common part of the constructor shared by MPI and non-MPI
99 void PlainTableCommon(SetupNewTable&, rownr_t nrrow, Bool initialize,
100 const TableLock& lockOptions, int endianFormat, const TSMOption& tsmOption);
101
102 // Construct the object for an existing table.
103 // It opens the table file, reads the table control information
104 // and creates and initializes the required storage managers.
105 PlainTable(AipsIO&, uInt version, const String& name, const String& type, rownr_t nrrow,
106 int option, const TableLock& lockOptions, const TSMOption& tsmOption, Bool addToCache,
107 uInt locknr);
108
109 // The destructor flushes (i.e. writes) the table if it is opened
110 // for output and not marked for delete.
111 virtual ~PlainTable();
112
113 // Copy constructor is forbidden, because copying a table requires
114 // some more knowledge (like table name of result).
115 PlainTable(const PlainTable&) = delete;
116
117 // Assignment is forbidden, because copying a table requires
118 // some more knowledge (like table name of result).
119 PlainTable& operator=(const PlainTable&) = delete;
120
121 // Return the layout of a table (i.e. description and #rows).
122 // This function has the advantage that only the minimal amount of
123 // information required is read from the table, thus it is much
124 // faster than a normal table open.
125 // <br> The number of rows is returned. The description of the table
126 // is stored in desc (its contents will be overwritten).
127 static void getLayout(TableDesc& desc, AipsIO& ios);
128
129 // Try to reopen the table for read/write access.
130 // An exception is thrown if the table is not writable.
131 // Nothing is done if the table is already open for read/write.
132 virtual void reopenRW();
133
134 // Indicate we will only modify data values in existing tiled columns
135 virtual void changeTiledDataOnly();
136
137 // Is the table stored in big or little endian format?
138 virtual Bool asBigEndian() const;
139
140 // Get the storage option used for the table.
141 virtual const StorageOption& storageOption() const;
142
143 // Is the table in use (i.e. open) in another process?
144 // If <src>checkSubTables</src> is set, it is also checked if
145 // a subtable is used in another process.
146 virtual Bool isMultiUsed(Bool checkSubTables) const;
147
148 // Get the locking info.
149 virtual const TableLock& lockOptions() const;
150
151 // Merge the given lock info with the existing one.
152 virtual void mergeLock(const TableLock& lockOptions);
153
154 // Has this process the read or write lock, thus can the table
155 // be read or written safely?
157
158 // Try to lock the table for read or write access.
159 virtual Bool lock(FileLocker::LockType, uInt nattempts);
160
161 // Unlock the table. This will also synchronize the table data,
162 // thus force the data to be written to disk.
163 virtual void unlock();
164
165 // Do a release of an AutoLock when the inspection interval has expired.
166 // <src>always=True</src> means that the inspection is always done,
167 // thus not every 25th call or so.
168 void autoReleaseLock(Bool always = False);
169
170 // Flush the table, i.e. write it to disk.
171 // Nothing will be done if the table is not writable.
172 // A flush can be executed at any time.
173 // When a table is marked for delete, the destructor will remove
174 // files written by intermediate flushes.
175 // Note that if necessary the destructor will do an implicit flush,
176 // unless it is executed due to an exception.
177 virtual void flush(Bool fsync, Bool recursive);
178
179 // Resync the Table object with the table file.
180 virtual void resync();
181
182 // Get the modify counter.
183 virtual uInt getModifyCounter() const;
184
185 // Set the table to being changed.
186 virtual void setTableChanged();
187
188 // Convert a Table option to an AipsIO file option.
189 // This is used by storage managers.
191
192 // Test if the table is opened as writable.
193 virtual Bool isWritable() const;
194
195 // Get the actual table description.
196 virtual TableDesc actualTableDesc() const;
197
198 // Get the data manager info.
199 virtual Record dataManagerInfo() const;
200
201 // Get readonly access to the table keyword set.
203
204 // Get read/write access to the table keyword set.
205 // This requires that the table is locked (or it gets locked
206 // when using AutoLocking mode).
208
209 // Get a column object using its index.
210 virtual BaseColumn* getColumn(uInt columnIndex) const;
211
212 // Get a column object using its name.
213 virtual BaseColumn* getColumn(const String& columnName) const;
214
215 // Test if it is possible to add a row to this table.
216 virtual Bool canAddRow() const;
217
218 // Add one or more rows and possibly initialize them.
219 // This will fail for tables not supporting addition of rows.
220 virtual void addRow(rownr_t nrrow, Bool initialize);
221
222 // Test if it is possible to remove a row from this table.
223 virtual Bool canRemoveRow() const;
224
225 // Remove the given row.
226 // This will fail for tables not supporting removal of rows.
227 virtual void removeRow(rownr_t rownr);
228
229 // Add a column to the table.
230 // The last Bool argument is not used in PlainTable, but can be used in
231 // other classes derived from BaseTable.
232 // <group>
233 virtual void addColumn(const ColumnDesc& columnDesc, Bool);
234 virtual void addColumn(const ColumnDesc& columnDesc, const String& dataManager, Bool byName,
235 Bool);
236 virtual void addColumn(const ColumnDesc& columnDesc, const DataManager& dataManager, Bool);
237 virtual void addColumn(const TableDesc& tableDesc, const DataManager& dataManager, Bool);
238 // </group>
239
240 // Test if columns can be removed.
241 virtual Bool canRemoveColumn(const Vector<String>& columnNames) const;
242
243 // Remove columns.
244 virtual void removeColumn(const Vector<String>& columnNames);
245
246 // Test if a column can be renamed (yes).
247 virtual Bool canRenameColumn(const String& columnName) const;
248
249 // Rename a column.
250 virtual void renameColumn(const String& newName, const String& oldName);
251
252 // Rename a hypercolumn.
253 virtual void renameHypercolumn(const String& newName, const String& oldName);
254
255 // Find the data manager with the given name or for the given column.
256 virtual DataManager* findDataManager(const String& name, Bool byColumn) const;
257
258 // Get access to the TableCache.
260
261 private:
262 // Close the object which is called by the destructor.
264
265 // Rename the subtables (used by rename function).
266 virtual void renameSubTables(const String& newName, const String& oldName);
267
268 // The callback function when a lock is released.
269 // This flushes the table data, writes the synchronization data
270 // into the MemoryIO object, and returns a pointer to it.
271 // <group>
272 static MemoryIO* releaseCallBack(void* plainTableObject, Bool always);
274 // </group>
275
276 // When needed, write the table control information in an AipsIO file.
277 // Tell the storage managers to flush and close their files.
278 // It returns a switch to tell if the table control information has
279 // been written.
281
282 // Synchronize the table after having acquired a lock which says
283 // that main table data has changed.
284 // It check if the columns did not change.
285 // It updates the table and column keywords.
286 void syncTable();
287
288 // Determine and set the endian format (big or little).
289 void setEndian(int endianFormat);
290
291 // Throw an exception if the table is not writable.
292 void checkWritable(const char* func) const;
293
294 std::shared_ptr<ColumnSet> colSetPtr_p; // # pointer to set of columns
295 Bool tableChanged_p; // # Has the main data changed?
296 Bool addToCache_p; // # Is table added to cache?
297 TableLockData* lockPtr_p; // # pointer to lock object
298 TableSyncData lockSync_p; // # table synchronization
299 Bool bigEndian_p; // # True = big endian canonical
300 // # False = little endian canonical
302 Bool changeTiledDataOnly_; // # Allow updates to data in existing tiled columns
303 // # cache of open (plain) tables
305};
306
307} // namespace casacore
308
309#endif
const TableDesc & tableDesc() const
Get the table description.
Definition BaseTable.h:261
BaseTable(const String &tableName, int tableOption, rownr_t nrrow)
Initialize the object.
int tableOption() const
Get the table option.
Definition BaseTable.h:244
OpenOption
Define the possible ByteIO open options.
Definition ByteIO.h:60
Abstract base class for a data manager.
LockType
Define the possible lock types.
Definition FileLocker.h:89
TableSyncData lockSync_p
Definition PlainTable.h:298
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:304
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:294
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.
virtual void changeTiledDataOnly()
Indicate we will only modify data values in existing tiled columns.
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:297
static TableCache & tableCache()
Get access to the TableCache.
Definition PlainTable.h:259
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
String name() const
Return the name of the field.
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