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