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
52 namespace 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>
76 Table openTable (const String& tableName,
78 const TSMOption& = TSMOption());
79 Table openTable (const String& tableName,
80 const TableLock& lockOptions,
82 const TSMOption& = TSMOption());
83 // </group>
84
85 // Create a table with the given name and description.
86 // Datamanager information can be given in the Record.
87 // The table name can be given with the :: notation meaning that a subtable
88 // of the previous part is created. Depending on the TableOption, that subtable
89 // can or cannot exist yet.
90 // It defines the subtable keyword in the parent table.
91 // <br>An exception is thrown if one of the parts cannot be opened.
92 // <example>
93 // Create the ANT subtable of an MS with some description and create the
94 // table keyword ANT in sel.ms referring to the subtable.
95 // It is replaced if already existing (not if TableOption::NewNoReplace is given).
96 // <srcblock>
97 // Table tab(Table::createTable ("sel.ms::ANT", someDesc, TableOption::New));
98 // </srcblock>
99 // </example>
100 Table createTable (const String& tableName,
101 const TableDesc&,
104 const StorageOption& = StorageOption(),
105 const Record& dmInfo = Record(),
106 const TableLock& lockOptions = TableLock(),
107 rownr_t nrrow = 0,
108 Bool initialize = False,
110 const TSMOption& = TSMOption());
111 Table createSubTable (Table& parent, const String& subtableName,
112 const TableDesc& desc,
114 const StorageOption& = StorageOption(),
115 const Record& dmInfo = Record(),
116 const TableLock& lockOptions = TableLock(),
117 rownr_t nrrow = 0,
118 Bool initialize = False,
120 const TSMOption& = TSMOption());
121
122 // Can the table be deleted?
123 // If true, function deleteTable can safely be called.
124 // If not, message contains the reason why (e.g. 'table is not writable').
125 // It checks if the table is writable, is not open in this process
126 // and is not open in another process.
127 // If <src>splitColons=True</src> the table name can contain :: to
128 // denote subtables.
129 // <br>If <src>checkSubTables</src> is set, it also checks if
130 // a subtable is not open in another process.
131 // <br> <src>canDeleteSubTable</src> can be used to check a subtable of the
132 // given parent.
133 // <group>
134 Bool canDeleteTable (const String& tableName,
135 Bool checkSubTables=False);
136 Bool canDeleteTable (String& message, const String& tableName,
137 Bool checkSubTables=False, Bool splitColons=True);
138 Bool canDeleteSubTable (String& message, const Table& parent,
139 const String& subtableName,
140 Bool checkSubTables=False);
141 // </group>
142
143 // Delete the table.
144 // An exception is thrown if the table cannot be deleted because
145 // its is not writable or because it is still open in this or
146 // another process.
147 // <br>If <src>checkSubTables</src> is set, it is also checked if
148 // a subtable is used in another process.
149 // <br> <src>deleteSubTable</src> can be used to delete a subtable of the
150 // given parent.
151 void deleteTable (const String& tableName,
152 Bool checkSubTables=False);
153 void deleteSubTable (Table& parent, const String& subtableName,
154 Bool checkSubTables = False);
155
156 // Return the layout of a table (i.e. description and #rows).
157 // This function has the advantage that only the minimal amount of
158 // information required is read from the table, thus it is
159 // faster than a normal table open. The table name can be a subtable using ::.
160 // <br> The number of rows is returned. The description of the table
161 // is stored in desc (its contents will be overwritten).
162 // <br> An exception is thrown if the table does not exist.
163 rownr_t getLayout (TableDesc& desc, const String& tableName);
164
165 // Get the table info of the table with the given name.
166 // An empty object is returned if the table is unknown.
167 // The table name can be a subtable using ::.
168 TableInfo tableInfo (const String& tableName);
169
170 // Get the full name (absolute path) of the given table name, which can
171 // be a subtable specification using ::.
172 String getFullName (const String& tableName);
173
174 // Find the parent table of the last subtable in a table name containing
175 // :: to indicate subtables.
176 // It returns the Table object of that parent table and the name of
177 // the last subtable. An empty Table is returned if the table name does
178 // not contain subtable names.
179 // In case of an error, an exception is thrown.
180 std::pair<Table,String> findParentTable (const String& fullName,
181 const TableLock& lockOptions=TableLock(),
183 const TSMOption& tsmOption=TSMOption());
184
185 } //# NAMESPACE TableUtil - END
186} //# NAMESPACE CASACORE - END
187
188#endif
189
String: the storage and methods of handling collections of characters.
Definition String.h:223
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition Table.h:195
@ AipsrcEndian
use endian format defined in the aipsrc variable table.endianformat If undefined, it defaults to Loca...
Definition Table.h:204
TableOption
Define the possible options how a table can be opened.
Definition Table.h:171
@ Old
existing table
Definition Table.h:173
TableType
Define the possible table types.
Definition Table.h:187
@ Plain
plain table (stored on disk)
Definition Table.h:189
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? If true, function deleteTable can safely be called.
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)
this file contains all the compiler specific defines
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