casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
27 
28 #ifndef TABLES_TABLEUTIL_H
29 #define TABLES_TABLEUTIL_H
30 
31 #include <casacore/casa/aips.h>
37 
38 namespace casacore {
39 
40  // The TableUtil namespace contains several convenience functions operating
41  // on Table objects. They make it very convenient to open, close or delete
42  // main tables and subtables.
43  // <p>
44  // The function <src>openTable</src> makes it possible to open a subtable
45  // of a table in a convenient way, even if the table is only a reference
46  // to another table (e.g., a selection). The name can be given with colons as
47  // 'maintab::subtab1::subtab2' meaning that subtab2 is opened and returned.
48  // Of course, it can also be used to open a main table such as 'my.tab'.
49  //
50  // Similar to <src>openTable</src>, the function <src>createTable</src>
51  // can be used to create a (sub)table, possibly using the :: notation.
52  // <br><src>deleteTable</src> is similar to delete a (sub)table.
53 
54  namespace TableUtil {
55 
56  // Try to open a table. The name of the table can contain subtable names
57  // using :: as separator. In this way it is possible to directly open a
58  // subtable of a RefTable or ConcatTable, which is not possible if the
59  // table name is specified with slashes.
60  // <br>The open process is as follows:
61  // <ul>
62  // <li> It is tried to open the table with the given name.
63  // <li> If unsuccessful, the name is split into its parts using ::
64  // The first part is the main table which will be opened temporarily.
65  // The other parts are the successive subtable names (usually one).
66  // Each subtable is opened by looking it up in the keywords of the
67  // table above. The final subtable is returned.
68  // </ul>
69  // <br>An exception is thrown if the table cannot be opened.
70  // <example>
71  // Open the ANTENNA subtable of an MS which might be a selection of
72  // a real MS.
73  // <srcblock>
74  // Table tab(Table::openTable ("sel.ms::ANTENNA");
75  // </srcblock>
76  // </example>
77  // <group>
78  Table openTable (const String& tableName,
80  const TSMOption& = TSMOption());
81  Table openTable (const String& tableName,
82  const TableLock& lockOptions,
84  const TSMOption& = TSMOption());
85  // </group>
86 
87  // Create a table with the given name and description.
88  // Datamanager information can be given in the Record.
89  // The table name can be given with the :: notation meaning that a subtable
90  // of the previous part is created. Depending on the TableOption, that subtable
91  // can or cannot exist yet.
92  // It defines the subtable keyword in the parent table.
93  // <br>An exception is thrown if one of the parts cannot be opened.
94  // <example>
95  // Create the ANT subtable of an MS with some description and create the
96  // table keyword ANT in sel.ms referring to the subtable.
97  // It is replaced if already existing (not if TableOption::NewNoReplace is given).
98  // <srcblock>
99  // Table tab(Table::createTable ("sel.ms::ANT", someDesc, TableOption::New));
100  // </srcblock>
101  // </example>
102  Table createTable (const String& tableName,
103  const TableDesc&,
106  const StorageOption& = StorageOption(),
107  const Record& dmInfo = Record(),
108  const TableLock& lockOptions = TableLock(),
109  rownr_t nrrow = 0,
110  Bool initialize = False,
112  const TSMOption& = TSMOption());
113  Table createSubTable (Table& parent, const String& subtableName,
114  const TableDesc& desc,
116  const StorageOption& = StorageOption(),
117  const Record& dmInfo = Record(),
118  const TableLock& lockOptions = TableLock(),
119  rownr_t nrrow = 0,
120  Bool initialize = False,
122  const TSMOption& = TSMOption());
123 
124  // Can the table be deleted?
125  // If true, function deleteTable can safely be called.
126  // If not, message contains the reason why (e.g. 'table is not writable').
127  // It checks if the table is writable, is not open in this process
128  // and is not open in another process.
129  // If <src>splitColons=True</src> the table name can contain :: to
130  // denote subtables.
131  // <br>If <src>checkSubTables</src> is set, it also checks if
132  // a subtable is not open in another process.
133  // <br> <src>canDeleteSubTable</src> can be used to check a subtable of the
134  // given parent.
135  // <group>
136  Bool canDeleteTable (const String& tableName,
137  Bool checkSubTables=False);
138  Bool canDeleteTable (String& message, const String& tableName,
139  Bool checkSubTables=False, Bool splitColons=True);
140  Bool canDeleteSubTable (String& message, const Table& parent,
141  const String& subtableName,
142  Bool checkSubTables=False);
143  // </group>
144 
145  // Delete the table.
146  // An exception is thrown if the table cannot be deleted because
147  // its is not writable or because it is still open in this or
148  // another process.
149  // <br>If <src>checkSubTables</src> is set, it is also checked if
150  // a subtable is used in another process.
151  // <br> <src>deleteSubTable</src> can be used to delete a subtable of the
152  // given parent.
153  void deleteTable (const String& tableName,
154  Bool checkSubTables=False);
155  void deleteSubTable (Table& parent, const String& subtableName,
156  Bool checkSubTables = False);
157 
158  // Return the layout of a table (i.e. description and #rows).
159  // This function has the advantage that only the minimal amount of
160  // information required is read from the table, thus it is
161  // faster than a normal table open. The table name can be a subtable using ::.
162  // <br> The number of rows is returned. The description of the table
163  // is stored in desc (its contents will be overwritten).
164  // <br> An exception is thrown if the table does not exist.
165  rownr_t getLayout (TableDesc& desc, const String& tableName);
166 
167  // Get the table info of the table with the given name.
168  // An empty object is returned if the table is unknown.
169  // The table name can be a subtable using ::.
170  TableInfo tableInfo (const String& tableName);
171 
172  // Get the full name (absolute path) of the given table name, which can
173  // be a subtable specification using ::.
174  String getFullName (const String& tableName);
175 
176  // Find the parent table of the last subtable in a table name containing
177  // :: to indicate subtables.
178  // It returns the Table object of that parent table and the name of
179  // the last subtable. An empty Table is returned if the table name does
180  // not contain subtable names.
181  // In case of an error, an exception is thrown.
182  std::pair<Table,String> findParentTable (const String& fullName,
183  const TableLock& lockOptions=TableLock(),
185  const TSMOption& tsmOption=TSMOption());
186 
187  } //# NAMESPACE TableUtil - END
188 } //# NAMESPACE CASACORE - END
189 
190 #endif
191 
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:196
Main interface class to a read/write table.
Definition: Table.h:157
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.
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...
TableInfo tableInfo(const String &tableName)
Get the table info of the table with the given name.
rownr_t getLayout(TableDesc &desc, const String &tableName)
Return the layout of a table (i.e.
Options defining how table files are organized.
Definition: StorageOption.h:76
use endian format defined in the aipsrc variable table.endianformat If undefined, it defaults to Loca...
Definition: Table.h:205
Table openTable(const String &tableName, Table::TableOption=Table::Old, const TSMOption &=TSMOption())
Try to open a table.
existing table
Definition: Table.h:174
plain table (stored on disk)
Definition: Table.h:190
Options for the Tiled Storage Manager Access.
Definition: TSMOption.h:116
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
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...
Table type, subtype and further info.
Definition: TableInfo.h:130
const Bool False
Definition: aipstype.h:44
Class to hold table lock options.
Definition: TableLock.h:68
Bool canDeleteSubTable(String &message, const Table &parent, const String &subtableName, Bool checkSubTables=False)
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
void deleteTable(const String &tableName, Bool checkSubTables=False)
Delete the table.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
Define the structure of a Casacore table.
Definition: TableDesc.h:190
Bool canDeleteTable(const String &tableName, Bool checkSubTables=False)
Can the table be deleted? If true, function deleteTable can safely be called.
TableType
Define the possible table types.
Definition: Table.h:188
const Bool True
Definition: aipstype.h:43
TableOption
Define the possible options how a table can be opened.
Definition: Table.h:172
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())