casacore
Loading...
Searching...
No Matches
TableUtil.h
Go to the documentation of this file.
1// # TableUtil.h: Utility functions for tables
2// # Copyright (C) 2022
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 receied 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_TABLEUTIL_H
27#define TABLES_TABLEUTIL_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/tables/Tables/Table.h>
31#include <casacore/tables/Tables/TableLock.h>
32#include <casacore/tables/DataMan/TSMOption.h>
33#include <casacore/casa/Containers/Record.h>
34#include <casacore/casa/Utilities/DataType.h>
35
36namespace casacore {
37
38// The TableUtil namespace contains several convenience functions operating
39// on Table objects. They make it very convenient to open, close or delete
40// main tables and subtables.
41// <p>
42// The function <src>openTable</src> makes it possible to open a subtable
43// of a table in a convenient way, even if the table is only a reference
44// to another table (e.g., a selection). The name can be given with colons as
45// 'maintab::subtab1::subtab2' meaning that subtab2 is opened and returned.
46// Of course, it can also be used to open a main table such as 'my.tab'.
47//
48// Similar to <src>openTable</src>, the function <src>createTable</src>
49// can be used to create a (sub)table, possibly using the :: notation.
50// <br><src>deleteTable</src> is similar to delete a (sub)table.
51
52namespace TableUtil {
53
54// Try to open a table. The name of the table can contain subtable names
55// using :: as separator. In this way it is possible to directly open a
56// subtable of a RefTable or ConcatTable, which is not possible if the
57// table name is specified with slashes.
58// <br>The open process is as follows:
59// <ul>
60// <li> It is tried to open the table with the given name.
61// <li> If unsuccessful, the name is split into its parts using ::
62// The first part is the main table which will be opened temporarily.
63// The other parts are the successive subtable names (usually one).
64// Each subtable is opened by looking it up in the keywords of the
65// table above. The final subtable is returned.
66// </ul>
67// <br>An exception is thrown if the table cannot be opened.
68// <example>
69// Open the ANTENNA subtable of an MS which might be a selection of
70// a real MS.
71// <srcblock>
72// Table tab(Table::openTable ("sel.ms::ANTENNA");
73// </srcblock>
74// </example>
75// <group>
77 const TSMOption& = TSMOption());
78Table openTable(const String& tableName, const TableLock& lockOptions,
80// </group>
81
82// Create a table with the given name and description.
83// Datamanager information can be given in the Record.
84// The table name can be given with the :: notation meaning that a subtable
85// of the previous part is created. Depending on the TableOption, that subtable
86// can or cannot exist yet.
87// It defines the subtable keyword in the parent table.
88// <br>An exception is thrown if one of the parts cannot be opened.
89// <example>
90// Create the ANT subtable of an MS with some description and create the
91// table keyword ANT in sel.ms referring to the subtable.
92// It is replaced if already existing (not if TableOption::NewNoReplace is given).
93// <srcblock>
94// Table tab(Table::createTable ("sel.ms::ANT", someDesc, TableOption::New));
95// </srcblock>
96// </example>
99 const Record& dmInfo = Record(), const TableLock& lockOptions = TableLock(),
100 rownr_t nrrow = 0, Bool initialize = False,
102Table createSubTable(Table& parent, const String& subtableName, const TableDesc& desc,
104 const Record& dmInfo = Record(), const TableLock& lockOptions = TableLock(),
105 rownr_t nrrow = 0, Bool initialize = False,
107
108// Can the table be deleted?
109// If true, function deleteTable can safely be called.
110// If not, message contains the reason why (e.g. 'table is not writable').
111// It checks if the table is writable, is not open in this process
112// and is not open in another process.
113// If <src>splitColons=True</src> the table name can contain :: to
114// denote subtables.
115// <br>If <src>checkSubTables</src> is set, it also checks if
116// a subtable is not open in another process.
117// <br> <src>canDeleteSubTable</src> can be used to check a subtable of the
118// given parent.
119// <group>
120Bool canDeleteTable(const String& tableName, Bool checkSubTables = False);
121Bool canDeleteTable(String& message, const String& tableName, Bool checkSubTables = False,
122 Bool splitColons = True);
123Bool canDeleteSubTable(String& message, const Table& parent, const String& subtableName,
124 Bool checkSubTables = False);
125// </group>
126
127// Delete the table.
128// An exception is thrown if the table cannot be deleted because
129// its is not writable or because it is still open in this or
130// another process.
131// <br>If <src>checkSubTables</src> is set, it is also checked if
132// a subtable is used in another process.
133// <br> <src>deleteSubTable</src> can be used to delete a subtable of the
134// given parent.
135void deleteTable(const String& tableName, Bool checkSubTables = False);
136void deleteSubTable(Table& parent, const String& subtableName, Bool checkSubTables = False);
137
138// Return the layout of a table (i.e. description and #rows).
139// This function has the advantage that only the minimal amount of
140// information required is read from the table, thus it is
141// faster than a normal table open. The table name can be a subtable using ::.
142// <br> The number of rows is returned. The description of the table
143// is stored in desc (its contents will be overwritten).
144// <br> An exception is thrown if the table does not exist.
145rownr_t getLayout(TableDesc& desc, const String& tableName);
146
147// Get the table info of the table with the given name.
148// An empty object is returned if the table is unknown.
149// The table name can be a subtable using ::.
150TableInfo tableInfo(const String& tableName);
151
152// Get the full name (absolute path) of the given table name, which can
153// be a subtable specification using ::.
154String getFullName(const String& tableName);
155
156// Find the parent table of the last subtable in a table name containing
157// :: to indicate subtables.
158// It returns the Table object of that parent table and the name of
159// the last subtable. An empty Table is returned if the table name does
160// not contain subtable names.
161// In case of an error, an exception is thrown.
162std::pair<Table, String> findParentTable(const String& fullName,
163 const TableLock& lockOptions = TableLock(),
165 const TSMOption& tsmOption = TSMOption());
166
167} // namespace TableUtil
168} // namespace casacore
169
170#endif
String: the storage and methods of handling collections of characters.
Definition String.h:355
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition Table.h:192
@ AipsrcEndian
use endian format defined in the aipsrc variable table.endianformat If undefined, it defaults to Loca...
Definition Table.h:201
TableOption
Define the possible options how a table can be opened.
Definition Table.h:168
@ Old
existing table
Definition Table.h:170
TableType
Define the possible table types.
Definition Table.h:184
@ Plain
plain table (stored on disk)
Definition Table.h:186
The TableUtil namespace contains several convenience functions operating on Table objects.
Definition TableUtil.h:52
Table openTable(const String &tableName, Table::TableOption=Table::Old, const TSMOption &=TSMOption())
Try to open a table.
Table createTable(const String &tableName, const TableDesc &, Table::TableOption, Table::TableType=Table::Plain, const StorageOption &=StorageOption(), const Record &dmInfo=Record(), const TableLock &lockOptions=TableLock(), rownr_t nrrow=0, Bool initialize=False, Table::EndianFormat=Table::AipsrcEndian, const TSMOption &=TSMOption())
Create a table with the given name and description.
Bool canDeleteTable(const String &tableName, Bool checkSubTables=False)
Can the table be deleted?
rownr_t getLayout(TableDesc &desc, const String &tableName)
Return the layout of a table (i.e.
void deleteTable(const String &tableName, Bool checkSubTables=False)
Delete the table.
TableInfo tableInfo(const String &tableName)
Get the table info of the table with the given name.
std::pair< Table, String > findParentTable(const String &fullName, const TableLock &lockOptions=TableLock(), Table::TableOption option=Table::Old, const TSMOption &tsmOption=TSMOption())
Find the parent table of the last subtable in a table name containing :: to indicate subtables.
Table createSubTable(Table &parent, const String &subtableName, const TableDesc &desc, Table::TableOption, const StorageOption &=StorageOption(), const Record &dmInfo=Record(), const TableLock &lockOptions=TableLock(), rownr_t nrrow=0, Bool initialize=False, Table::EndianFormat=Table::AipsrcEndian, const TSMOption &=TSMOption())
void deleteSubTable(Table &parent, const String &subtableName, Bool checkSubTables=False)
String getFullName(const String &tableName)
Get the full name (absolute path) of the given table name, which can be a subtable specification usin...
Bool canDeleteSubTable(String &message, const Table &parent, const String &subtableName, Bool checkSubTables=False)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44