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 // Indicate we will only modify data values in existing tiled columns
142 virtual void changeTiledDataOnly();
143
144 // Is the table stored in big or little endian format?
145 virtual Bool asBigEndian() const;
146
147 // Get the storage option used for the table.
148 virtual const StorageOption& storageOption() const;
149
150 // Is the table in use (i.e. open) in another process?
151 // If <src>checkSubTables</src> is set, it is also checked if
152 // a subtable is used in another process.
153 virtual Bool isMultiUsed (Bool checkSubTables) const;
154
155 // Get the locking info.
156 virtual const TableLock& lockOptions() const;
157
158 // Merge the given lock info with the existing one.
159 virtual void mergeLock (const TableLock& lockOptions);
160
161 // Has this process the read or write lock, thus can the table
162 // be read or written safely?
164
165 // Try to lock the table for read or write access.
166 virtual Bool lock (FileLocker::LockType, uInt nattempts);
167
168 // Unlock the table. This will also synchronize the table data,
169 // thus force the data to be written to disk.
170 virtual void unlock();
171
172 // Do a release of an AutoLock when the inspection interval has expired.
173 // <src>always=True</src> means that the inspection is always done,
174 // thus not every 25th call or so.
175 void autoReleaseLock (Bool always = False);
176
177 // Flush the table, i.e. write it to disk.
178 // Nothing will be done if the table is not writable.
179 // A flush can be executed at any time.
180 // When a table is marked for delete, the destructor will remove
181 // files written by intermediate flushes.
182 // Note that if necessary the destructor will do an implicit flush,
183 // unless it is executed due to an exception.
184 virtual void flush (Bool fsync, Bool recursive);
185
186 // Resync the Table object with the table file.
187 virtual void resync();
188
189 // Get the modify counter.
190 virtual uInt getModifyCounter() const;
191
192 // Set the table to being changed.
193 virtual void setTableChanged();
194
195 // Convert a Table option to an AipsIO file option.
196 // This is used by storage managers.
198
199 // Test if the table is opened as writable.
200 virtual Bool isWritable() const;
201
202 // Get the actual table description.
203 virtual TableDesc actualTableDesc() const;
204
205 // Get the data manager info.
206 virtual Record dataManagerInfo() const;
207
208 // Get readonly access to the table keyword set.
210
211 // Get read/write access to the table keyword set.
212 // This requires that the table is locked (or it gets locked
213 // when using AutoLocking mode).
215
216 // Get a column object using its index.
217 virtual BaseColumn* getColumn (uInt columnIndex) const;
218
219 // Get a column object using its name.
220 virtual BaseColumn* getColumn (const String& columnName) const;
221
222 // Test if it is possible to add a row to this table.
223 virtual Bool canAddRow() const;
224
225 // Add one or more rows and possibly initialize them.
226 // This will fail for tables not supporting addition of rows.
227 virtual void addRow (rownr_t nrrow, Bool initialize);
228
229 // Test if it is possible to remove a row from this table.
230 virtual Bool canRemoveRow() const;
231
232 // Remove the given row.
233 // This will fail for tables not supporting removal of rows.
234 virtual void removeRow (rownr_t rownr);
235
236 // Add a column to the table.
237 // The last Bool argument is not used in PlainTable, but can be used in
238 // other classes derived from BaseTable.
239 // <group>
240 virtual void addColumn (const ColumnDesc& columnDesc, Bool);
241 virtual void addColumn (const ColumnDesc& columnDesc,
242 const String& dataManager, Bool byName, Bool);
243 virtual void addColumn (const ColumnDesc& columnDesc,
244 const DataManager& dataManager, Bool);
245 virtual void addColumn (const TableDesc& tableDesc,
246 const DataManager& dataManager, Bool);
247 // </group>
248
249 // Test if columns can be removed.
250 virtual Bool canRemoveColumn (const Vector<String>& columnNames) const;
251
252 // Remove columns.
253 virtual void removeColumn (const Vector<String>& columnNames);
254
255 // Test if a column can be renamed (yes).
256 virtual Bool canRenameColumn (const String& columnName) const;
257
258 // Rename a column.
259 virtual void renameColumn (const String& newName, const String& oldName);
260
261 // Rename a hypercolumn.
262 virtual void renameHypercolumn (const String& newName,
263 const String& oldName);
264
265 // Find the data manager with the given name or for the given column.
267 Bool byColumn) const;
268
269
270 // Get access to the TableCache.
272 { return theirTableCache; }
273
274private:
275 // Close the object which is called by the destructor.
277
278 // Rename the subtables (used by rename function).
279 virtual void renameSubTables (const String& newName,
280 const String& oldName);
281
282 // The callback function when a lock is released.
283 // This flushes the table data, writes the synchronization data
284 // into the MemoryIO object, and returns a pointer to it.
285 // <group>
286 static MemoryIO* releaseCallBack (void* plainTableObject, Bool always);
288 // </group>
289
290 // When needed, write the table control information in an AipsIO file.
291 // Tell the storage managers to flush and close their files.
292 // It returns a switch to tell if the table control information has
293 // been written.
294 Bool putFile (Bool always);
295
296 // Synchronize the table after having acquired a lock which says
297 // that main table data has changed.
298 // It check if the columns did not change.
299 // It updates the table and column keywords.
300 void syncTable();
301
302 // Determine and set the endian format (big or little).
303 void setEndian (int endianFormat);
304
305 // Throw an exception if the table is not writable.
306 void checkWritable (const char* func) const;
307
308
309 std::shared_ptr<ColumnSet> colSetPtr_p; //# pointer to set of columns
310 Bool tableChanged_p; //# Has the main data changed?
311 Bool addToCache_p; //# Is table added to cache?
312 TableLockData* lockPtr_p; //# pointer to lock object
313 TableSyncData lockSync_p; //# table synchronization
314 Bool bigEndian_p; //# True = big endian canonical
315 //# False = little endian canonical
317 Bool changeTiledDataOnly_; //# Allow updates to data in existing tiled columns
318 //# cache of open (plain) tables
320};
321
322
323
324} //# NAMESPACE CASACORE - END
325
326#endif
const TableDesc & tableDesc() const
Get the table description.
Definition BaseTable.h:275
BaseTable(const String &tableName, int tableOption, rownr_t nrrow)
Initialize the object.
int tableOption() const
Get the table option.
Definition BaseTable.h:256
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:313
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:319
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:309
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:312
static TableCache & tableCache()
Get access to the TableCache.
Definition PlainTable.h:271
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
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