casacore
Loading...
Searching...
No Matches
ConcatTable.h
Go to the documentation of this file.
1// # ConcatTable.h: Class to view a concatenation of tables as a single table
2// # Copyright (C) 2008
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_CONCATTABLE_H
27#define TABLES_CONCATTABLE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/BaseTable.h>
32#include <casacore/tables/Tables/ConcatRows.h>
33#include <casacore/tables/Tables/TableRecord.h>
34#include <casacore/tables/Tables/Table.h>
35#include <casacore/casa/BasicSL/String.h>
36#include <casacore/casa/Arrays/Vector.h>
37#include <map>
38
39namespace casacore { // # NAMESPACE CASACORE - BEGIN
40
41// # Forward Declarations
42class TSMOption;
43class ConcatColumn;
44class AipsIO;
45
46// <summary>
47// Class to view a concatenation of tables as a single table.
48// </summary>
49
50// <use visibility=local>
51
52// <reviewed reviewer="UNKNOWN" date="" tests="">
53// </reviewed>
54
55// <prerequisite>
56// # Classes you should understand before using this one.
57// <li> BaseTable
58// <li> ConcatColumn
59// </prerequisite>
60
61// <etymology>
62// ConcatTable represents the concatenation of one or more tables.
63// </etymology>
64
65// <synopsis>
66// ConcatTable is used to virtually concatenate one or more tables.
67// Those tables must have the same description.
68//
69// It acts to the user as a normal table. All gets and puts are
70// handled by ConcatColumn which directs them to the referenced columns
71// while (if needed) converting the given row number to the row number
72// in the referenced tables. For that purpose ConcatTable keeps the
73// number of rows in the referenced tables.
74// <note>Currently it cannot handle changes in the number of rows in the
75// underlying tables. </note>
76//
77// It is possible to specify the keyword names of the subtables that have
78// to be concatenated as well. The other subtables are assumed to be
79// identical for all tables, so only the subtable of the first table is used.
80//
81// The ConcatTable maintains its own keyword set, which is initially a copy
82// of the keyword set of the first table. It replaces the keywords of the
83// subtables to be concatenated.
84// The keyword set is not persistent. One can add or change keywords, but
85// these changes are not kept when the ConcatTable object is made persistent.
86// </synopsis>
87
88// <motivation>
89// Sometimes a very large MeasurementSet is split into multiple smaller ones
90// using the time axis. Using ConcatTable they can still be viewed as a
91// single MS. The SYSCAL subtable is split in time as well, thus it has
92// to be possible to concatenate that one as well.
93// <note>An MS split in subband could be concatenated as well provided that
94// at least the first part contains the full SPECTRAL_WINDOW subtable and
95// that unique SPWids are used.
96// </note>
97// </motivation>
98
99// <todo asof="$DATE:$">
100// # A List of bugs, limitations, extensions or planned refinements.
101// <li> Maybe not allocating the row number vector for a projection.
102// This saves space and time, but each rownr conversion will
103// take a bit more time because it has to test if there is a vector.
104// <li> Maybe maintain a Vector<String> telling on which columns
105// the table is ordered. This may speed up selection, but
106// it is hard to check if the order is changed by a put.
107// <li> Allow to remove a row or column from the ConcatTable
108// <li> Allow to rename a column in the ConcatTable
109// <li> Maybe implement doSort one time for a more efficient sort.
110// (now everything is handled by BaseTable).
111// </todo>
112
113class ConcatTable : public BaseTable {
114 public:
115 // Create a virtual table as the concatenation of the given tables.
116 // It checks if the table descriptions of the tables are the same.
117 // Subtables with the given names will be concatenated as well.
118 // It is assumed that the other subtables are the same for all tables,
119 // so the ones of the first table are used.
120 // <br>The option can be Table::Old or Table::Update.
121 // <br>If a non-empty subdirectory name is given, the tables will
122 // be moved to that subdirectory when the concatenated table is written
123 // (by writeConcatTable).
124 // <group>
125 ConcatTable(const Block<Table>& tables, const Block<String>& subTables, const String& subDirName);
126 ConcatTable(const Block<String>& tableNames, const Block<String>& subTables,
127 const String& subDirName, int option, const TableLock& lockOptions,
128 const TSMOption& tsmOption);
129 // </group>
130
131 // Create a concat table out of a file (written by writeConcatTable).
132 // The referenced tables will also be opened (if not stored in the cache).
133 ConcatTable(AipsIO&, const String& name, rownr_t nrrow, int option, const TableLock& lockOptions,
134 const TSMOption& tsmOption);
135
136 // The destructor flushes (i.e. writes) the table if it is opened
137 // for output and not marked for delete.
138 virtual ~ConcatTable();
139
140 // Copy constructor is forbidden, because copying a table requires
141 // some more knowledge (like table name of result).
142 ConcatTable(const ConcatTable&) = delete;
143
144 // Assignment is forbidden, because copying a table requires
145 // some more knowledge (like table name of result).
147
148 // Get the names of the tables this table consists of.
149 virtual void getPartNames(Block<String>& names, Bool recursive) const;
150
151 // Return the layout of a table (i.e. description and #rows).
152 // This function has the advantage that only the minimal amount of
153 // information required is read from the table, thus it is much
154 // faster than a normal table open.
155 // <br> The number of rows is returned. The description of the table
156 // is stored in desc (its contents will be overwritten).
157 static void getLayout(TableDesc& desc, AipsIO& ios);
158
159 // Try to reopen the table (the underlying ones) for read/write access.
160 // An exception is thrown if the table is not writable.
161 // Nothing is done if the table is already open for read/write.
162 virtual void reopenRW();
163
164 // Is the table stored in big or little endian format?
165 // It returns the endianness of the first underlying table.
166 virtual Bool asBigEndian() const;
167
168 // Get the storage option used for the table.
169 // It returns the storage option of the first underlying table.
170 virtual const StorageOption& storageOption() const;
171
172 // Is the table in use (i.e. open) in another process?
173 // It always returns False.
174 virtual Bool isMultiUsed(Bool checkSubTable) const;
175
176 // Get the locking info.
177 // All underlying tables have the same lock option.
178 virtual const TableLock& lockOptions() const;
179
180 // Merge the given lock info with the existing one.
181 virtual void mergeLock(const TableLock& lockOptions);
182
183 // Has this process the read or write lock, thus can the table
184 // be read or written safely?
186
187 // Try to lock the table for read or write access.
188 virtual Bool lock(FileLocker::LockType, uInt nattempts);
189
190 // Unlock the table. This will also synchronize the table data,
191 // thus force the data to be written to disk.
192 virtual void unlock();
193
194 // Flush the table, i.e. write it to disk.
195 // Nothing will be done if the table is not writable.
196 // A flush can be executed at any time.
197 // When a table is marked for delete, the destructor will remove
198 // files written by intermediate flushes.
199 // Note that if necessary the destructor will do an implicit flush,
200 // unless it is executed due to an exception.
201 virtual void flush(Bool fsync, Bool recursive);
202
203 // Resync the Table object with the table files.
204 virtual void resync();
205
206 // Get the modify counter.
207 virtual uInt getModifyCounter() const;
208
209 // Test if all underlying tables are opened as writable.
210 virtual Bool isWritable() const;
211
212 // Read a concat table from a file.
213 // The underlying tables will be opened (if not stored in the cache).
214 void getConcat(AipsIO&, int option, const TableLock& lockOptions, const TSMOption& tsmOption);
215
216 // This is doing a shallow copy.
217 // It gives an error if the ConcatTable has not been stored yet.
218 virtual void copy(const String& newName, int tableOption) const;
219
220 // Copy the table and all its subtables.
221 // It copies the contents of each row to get a real copy.
222 virtual void deepCopy(const String& newName, const Record& dataManagerInfo, const StorageOption&,
223 int tableOption, Bool, int endianFormat, Bool noRows) const;
224
225 // It returns the type of the parent table.
226 virtual int tableType() const;
227
228 // Get the actual table description.
229 virtual TableDesc actualTableDesc() const;
230
231 // Get the data manager info (of the first underlying table).
232 virtual Record dataManagerInfo() const;
233
234 // Get readonly access to the table keyword set.
236
237 // Get read/write access to the table keyword set.
238 // This requires that the table is locked (or it gets locked
239 // when using AutoLocking mode).
241
242 // Get a column object using its index.
243 virtual BaseColumn* getColumn(uInt columnIndex) const;
244
245 // Get a column object using its name.
246 virtual BaseColumn* getColumn(const String& columnName) const;
247
248 // Test if it is possible to remove a row from this table (no).
249 virtual Bool canRemoveRow() const;
250
251 // Remove the given row.
252 virtual void removeRow(rownr_t rownr);
253
254 // Test if columns can be removed (no).
255 virtual Bool canRemoveColumn(const Vector<String>& columnNames) const;
256
257 // Add one or more columns to the table.
258 // The column is added to the parent tables if told so and if not existing.
259 // <group>
260 virtual void addColumn(const ColumnDesc& columnDesc, Bool addToParent);
261 virtual void addColumn(const ColumnDesc& columnDesc, const String& dataManager, Bool byName,
262 Bool addToParent);
263 virtual void addColumn(const ColumnDesc& columnDesc, const DataManager& dataManager,
264 Bool addToParent);
265 virtual void addColumn(const TableDesc& tableDesc, const DataManager& dataManager,
266 Bool addToParent);
267 // </group>
268
269 // Remove a column.
270 virtual void removeColumn(const Vector<String>& columnNames);
271
272 // Test if a column can be renamed (no).
273 virtual Bool canRenameColumn(const String& columnName) const;
274
275 // Rename a column.
276 virtual void renameColumn(const String& newName, const String& oldName);
277
278 // Rename a hypercolumn.
279 virtual void renameHypercolumn(const String& newName, const String& oldName);
280
281 // Find the data manager with the given name or for the given column.
282 virtual DataManager* findDataManager(const String& name, Bool byColumn) const;
283
284 // Get the rows object.
285 const ConcatRows& rows() const { return rows_p; }
286
287 // Get the column objects in the referenced tables.
289
290 private:
291 // Show the extra table structure info (names of used tables).
292 void showStructureExtra(std::ostream&) const;
293
294 // Open all tables in the required way.
295 void openTables(const Block<String>& tableNames, int option, const TableLock& lockOptions,
296 const TSMOption& tsmOption);
297
298 // Initialize.
299 // It checks if the descriptions of all tables are equal.
300 // It creates the keyword setfor which it concatenates subtables as needed.
302
303 // Setup the main parts of the object.
304 // <br>First create the name map (mapping column name in ConcatTable to
305 // the column in the original table).
306 // If the BaseTable is a ConcatTable, use its name map.
307 // Otherwise create the initial name map from the table description.
308 // A rename might change the map.
309 // <br>Create the ConcatColumn objects.
310 // <br>Create the initial TableInfo as a copy of the original BaseTable.
311 void setup(BaseTable* btp, const Vector<String>& columnNames);
312
313 // Add lines containing the concatenated tables to the info.
314 void addInfo();
315
316 // Create the ConcatColumn objects for all columns in the description.
318
319 // Handle the subtales that have to be concatenated.
321
322 // Write a reference table.
324
325 // Check if the column can be added, thus does not exist yet.
326 void checkAddColumn(const String& name, Bool addToParent);
327
328 // Add a column, with internal bookeeping (columns map).
329 void addConcatCol(const ColumnDesc& cd);
330 // Add multiple columns, with internal bookeeping (columns map).
331 void addConcatCol(const TableDesc& tdesc);
332
333 // # Data members
336 Block<Table> tables_p; // # Tables forming the concat
337 std::map<String, ConcatColumn*> colMap_p; // # map name to column
339 Bool changed_p; // # True = changed since last write
341};
342
343} // namespace casacore
344
345#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
virtual ~ConcatTable()
The destructor flushes (i.e.
void makeConcatCol()
Create the ConcatColumn objects for all columns in the description.
virtual void addColumn(const ColumnDesc &columnDesc, const String &dataManager, Bool byName, Bool addToParent)
virtual uInt getModifyCounter() const
Get the modify counter.
virtual void renameHypercolumn(const String &newName, const String &oldName)
Rename a hypercolumn.
void initialize()
Initialize.
void setup(BaseTable *btp, const Vector< String > &columnNames)
Setup the main parts of the object.
ConcatTable(const ConcatTable &)=delete
Copy constructor is forbidden, because copying a table requires some more knowledge (like table name ...
static void getLayout(TableDesc &desc, AipsIO &ios)
Return the layout of a table (i.e.
virtual void removeColumn(const Vector< String > &columnNames)
Remove a column.
virtual void flush(Bool fsync, Bool recursive)
Flush the table, i.e.
virtual int tableType() const
It returns the type of the parent table.
virtual void renameColumn(const String &newName, const String &oldName)
Rename a column.
virtual void unlock()
Unlock the table.
ConcatTable(AipsIO &, const String &name, rownr_t nrrow, int option, const TableLock &lockOptions, const TSMOption &tsmOption)
Create a concat table out of a file (written by writeConcatTable).
virtual const TableLock & lockOptions() const
Get the locking info.
virtual void addColumn(const ColumnDesc &columnDesc, const DataManager &dataManager, Bool addToParent)
virtual const StorageOption & storageOption() const
Get the storage option used for the table.
virtual Bool isWritable() const
Test if all underlying tables are opened as writable.
void handleSubTables()
Handle the subtales that have to be concatenated.
virtual BaseColumn * getColumn(const String &columnName) const
Get a column object using its name.
ConcatTable(const Block< String > &tableNames, const Block< String > &subTables, const String &subDirName, int option, const TableLock &lockOptions, const TSMOption &tsmOption)
virtual DataManager * findDataManager(const String &name, Bool byColumn) const
Find the data manager with the given name or for the given column.
virtual Bool hasLock(FileLocker::LockType) const
Has this process the read or write lock, thus can the table be read or written safely?
std::map< String, ConcatColumn * > colMap_p
virtual void removeRow(rownr_t rownr)
Remove the given row.
virtual Bool asBigEndian() const
Is the table stored in big or little endian format?
void showStructureExtra(std::ostream &) const
Show the extra table structure info (names of used tables).
virtual void addColumn(const TableDesc &tableDesc, const DataManager &dataManager, Bool addToParent)
virtual TableRecord & keywordSet()
Get readonly access to the table keyword set.
virtual void addColumn(const ColumnDesc &columnDesc, Bool addToParent)
Add one or more columns to the table.
const ConcatRows & rows() const
Get the rows object.
virtual void deepCopy(const String &newName, const Record &dataManagerInfo, const StorageOption &, int tableOption, Bool, int endianFormat, Bool noRows) const
Copy the table and all its subtables.
virtual TableDesc actualTableDesc() const
Get the actual table description.
void addInfo()
Add lines containing the concatenated tables to the info.
virtual Bool canRemoveColumn(const Vector< String > &columnNames) const
Test if columns can be removed (no).
void writeConcatTable(Bool fsync)
Write a reference table.
virtual TableRecord & rwKeywordSet()
Get read/write access to the table keyword set.
void getConcat(AipsIO &, int option, const TableLock &lockOptions, const TSMOption &tsmOption)
Read a concat table from a file.
Block< Table > tables_p
virtual void resync()
Resync the Table object with the table files.
ConcatTable(const Block< Table > &tables, const Block< String > &subTables, const String &subDirName)
Create a virtual table as the concatenation of the given tables.
virtual Bool isMultiUsed(Bool checkSubTable) const
Is the table in use (i.e.
virtual void reopenRW()
Try to reopen the table (the underlying ones) for read/write access.
virtual Bool canRemoveRow() const
Test if it is possible to remove a row from this table (no).
virtual Bool canRenameColumn(const String &columnName) const
Test if a column can be renamed (no).
TableRecord keywordSet_p
virtual void mergeLock(const TableLock &lockOptions)
Merge the given lock info with the existing one.
void openTables(const Block< String > &tableNames, int option, const TableLock &lockOptions, const TSMOption &tsmOption)
Open all tables in the required way.
void addConcatCol(const TableDesc &tdesc)
Add multiple columns, with internal bookeeping (columns map).
virtual void copy(const String &newName, int tableOption) const
This is doing a shallow copy.
void checkAddColumn(const String &name, Bool addToParent)
Check if the column can be added, thus does not exist yet.
virtual Bool lock(FileLocker::LockType, uInt nattempts)
Try to lock the table for read or write access.
Block< String > subTableNames_p
Block< BaseColumn * > getRefColumns(const String &columnName)
Get the column objects in the referenced tables.
ConcatTable & operator=(const ConcatTable &)=delete
Assignment is forbidden, because copying a table requires some more knowledge (like table name of res...
virtual Record dataManagerInfo() const
Get the data manager info (of the first underlying table).
virtual void getPartNames(Block< String > &names, Bool recursive) const
Get the names of the tables this table consists of.
virtual BaseColumn * getColumn(uInt columnIndex) const
Get a column object using its index.
void addConcatCol(const ColumnDesc &cd)
Add a column, with internal bookeeping (columns map).
Abstract base class for a data manager.
LockType
Define the possible lock types.
Definition FileLocker.h:89
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
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