casacore
Loading...
Searching...
No Matches
SetupNewTab.h
Go to the documentation of this file.
1// # SetupNewTab.h: Create a new table - define shapes, data managers, etc.
2// # Copyright (C) 1994,1995,1996,1999,2001,2002,2003
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_SETUPNEWTAB_H
27#define TABLES_SETUPNEWTAB_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/tables/Tables/Table.h>
32#include <casacore/tables/Tables/StorageOption.h>
33#include <casacore/casa/BasicSL/String.h>
34#include <map>
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38// # Forward Declarations
39class TableDesc;
40class ColumnSet;
42class DataManager;
43class IPosition;
44
45// <summary>
46// Representation for handle class SetupNewTable
47// </summary>
48
49// <use visibility=local>
50
51// <reviewed reviewer="bglenden" date="12AUG94" tests="None">
52// </reviewed>
53
54// <prerequisite>
55// <li> TableDesc and related classes like ArrayColumnDesc
56// <li> DataManager
57// <li> Table
58// </prerequisite>
59
60// <etymology>
61// SetupNewTableRep is the representation of class SetupNewTable.
62// </etymology>
63
64// <synopsis>
65// SetupNewTableRep is the representation of class
66// <linkto class="SetupNewTable:description">SetupNewTable</linkto>.
67// Its functionality is described there.
68// </synopsis>
69
70// <motivation>
71// Copying a SetupNewTable object as such is very difficult, if not
72// impossible. However, being able to use a SetupNewTable copy constructor
73// was required to be able to have (static) functions constructing a
74// SetupNewTable object and return it by value (as done for example
75// by <src>ForwardColumn::setupNewTable</src>).
76// Therefore SetupNewTable is implemented using the handle idiom.
77// SetupNewTable is the interface (i.e. the handle) for the user,
78// while underneath SetupNewTableRep is doing all the work.
79// The SetupNewTable copy constructor can simply copy yhe pointer
80// to the underlying SetupNewTableRep object.
81// </motivation>
82
83// <todo asof="$DATE:$">
84// # A List of bugs, limitations, extensions or planned refinements.
85// <li> full implementation of tiling
86// </todo>
87
89 public:
90 // Create a new table using the table description with the given name.
91 // The description will be read from a file.
92 SetupNewTableRep(const String& tableName, const String& tableDescName, Table::TableOption,
93 const StorageOption&);
94
95 // Create a new table using the given table description.
97 const StorageOption&);
98
100
101 // Copy constructor is forbidden, because copying a table requires
102 // some more knowledge (like table name of result).
104
105 // Assignment is forbidden, because copying a table requires
106 // some more knowledge (like table name of result).
108
109 // Get the name of the table.
110 const String& name() const { return tabName_p; }
111
112 // Get the table create option.
113 int option() const { return option_p; }
114
115 // Get the storage option.
116 const StorageOption& storageOption() const { return storageOpt_p; }
117
118 // Test if the table is marked for delete.
119 Bool isMarkedForDelete() const { return delete_p; }
120
121 // Get the table description.
122 const TableDesc& tableDesc() const { return *tdescPtr_p; }
123
124 // Bind a column to the given data manager.
125 // If already bound, the binding will be overwritten.
126 // It cannot be used anymore once the SetupNewTableRep object is used to
127 // construct a Table object.
128 void bindColumn(const String& columnName, const DataManager&);
129
130 // Bind a column to the given data manager of the other column.
131 // If the other column is not bound, nothing will be done.
132 // If columnName is already bound, the binding will be overwritten.
133 // It cannot be used anymore once the SetupNewTableRep object is used to
134 // construct a Table object.
135 void bindColumn(const String& columnName, const String& otherColumn);
136
137 // Bind a group of columns to the given data manager.
138 // The flag rebind tells if the binding of an already bound column
139 // will be overwritten.
140 // It cannot be used anymore once the SetupNewTableRep object is used to
141 // construct a Table object.
142 void bindGroup(const String& columnGroup, const DataManager&, Bool rebind = False);
143
144 // Bind all columns to the given data manager.
145 // The flag rebind tells if the binding of an already bound column
146 // will be overwritten.
147 // It cannot be used anymore once the SetupNewTableRep object is used to
148 // construct a Table object.
149 void bindAll(const DataManager&, Bool rebind = False);
150
151 // Create data managers and bind the columns using the specifications
152 // in the given record (which is obtained using Table::dataManagerInfo()).
153 void bindCreate(const Record& spec);
154
155 // Define the shape of fixed shaped arrays in a column.
156 // The shape of those arrays has to be known before the table
157 // can be constructed. It has to be defined via this function,
158 // if it was not already defined in the column description.
159 // If only the dimensionality was defined in the column
160 // description, the shape's dimensionality must match it.
161 // Calling this function for an non-fixed shaped array results in
162 // an exception.
163 // It cannot be used anymore once the SetupNewTableRep object is used to
164 // construct a Table object.
165 void setShapeColumn(const String& columnName, const IPosition& shape);
166
167 // Test if object is already in use.
168 Bool isUsed() const { return !colSetPtr_p; }
169
170 // Get pointer to column set.
171 // This function is used by PlainTable.
172 const std::shared_ptr<ColumnSet>& columnSetPtr() const { return colSetPtr_p; }
173
174 // Get pointer to table description.
175 // This function is used by PlainTable.
176 const std::shared_ptr<TableDesc>& tableDescPtr() const { return tdescPtr_p; }
177
178 // Set object to in use by a (Plain)Table object.
179 // This function is used by PlainTable.
180 void setInUse() { colSetPtr_p.reset(); }
181
182 // Make a data manager for all unbound columns.
184
185 private:
186 // Table name.
188 // Constructor options.
191 // Marked for delete?
193 std::shared_ptr<TableDesc> tdescPtr_p;
194 std::shared_ptr<ColumnSet> colSetPtr_p; // # null = object is already used by a Table
195 std::map<void*, void*> dataManMap_p;
196
197 // Setup the new table.
198 // This checks various things and creates the set of columns.
199 void setup();
200
201 // Get the internal data manager object for the given data manager.
202 // If it does not exist yet, it will be cloned and stored internally.
204};
205
206// <summary>
207// Create a new table - define shapes, data managers, etc.
208// </summary>
209
210// <use visibility=export>
211
212// <reviewed reviewer="bglenden" date="12AUG94" tests="None">
213// </reviewed>
214
215// <prerequisite>
216// <li> TableDesc and related classes like ArrayColumnDesc
217// <li> DataManager
218// <li> Table
219// </prerequisite>
220
221// <etymology>
222// SetupNewTable is a class to setup a new table.
223// </etymology>
224
225// <synopsis>
226// Constructing a new table is a two stage process.
227// First a SetupNewTable object has to be created. Thereafter its columns
228// have to be bound defining how they have to be stored or calculated.
229// Columns have to be bound to a data manager (e.g. a storage manager
230// or a virtual column engine)..
231// Once the required columns are bound, the actual Table object can
232// be created. At this stage, still unbound columns will be bound
233// to the default data managers.
234// The Table object can be used to write data, etc.
235//
236// The construct options for SetupNewTable are defined in class Table.
237// The possible options are:
238// <ul>
239// <li> New
240// creates a new table file.
241// The Table destructor will write the table into the file.
242// <li> NewNoReplace
243// as option New, but an exception will be thrown if the table
244// file already exists.
245// <li> Scratch
246// creates a temporary table.
247// It will be lost when the Table object gets destructed.
248// </ul>
249// More information is provided in the Tables module documentation.
250// </synopsis>
251//
252// <example>
253// <srcblock>
254// Table makeIt(const TableDesc &td) { // 1
255// SetupNewTable maker("test.table", td, Table::New); // 2
256// maker.setShapeColumn("SomeArray", IPosition(2,10,10)); // 3
257// maker.setShapeColumn("AnotherArray", IPosition(1,100)); // 4
258// StManAipsIO sm1; // 5
259// StManKarma sm2; // 6
260// maker.bindAll(sm1); // 7
261// maker.bindColumn("SomeCol", sm2); // 8
262// maker.bindColumn("AnotherCol", sm2); // 9
263// return Table(maker, 1000); // 1000 row table // 10
264// } // 11
265// </srcblock>
266// This code illustrates a simple function that creates a Table starting
267// from a Table descriptor. I
268// <ol>
269// <li> Declare the function makeIt which, given a TableDesc, returns
270// a table.
271// <li> Create the SetupNewTable object "maker". We want the new table
272// to be named "test.table", its rows columns and keywords come
273// from the TableDesc "td", and this table is to be created
274// unconditionally, that is, it will overwrite an existing table
275// of the same name. Alternative options are given in the synopsis.
276// <li>
277// <li> Give direct arrays declared in the table descriptor (but not
278// necessarily given a shape) a defined shape; 10x10 for the first
279// array, 100 long vector for the second. If all direct arrays
280// do not have a shape, an error will occur when the table is
281// actually constructed.
282// <li>
283// <li> Declare two data (storage) managers. AipsIO keeps a whole column
284// in memory, Karma does I/O to keep a subsection in memory at once.
285// A powerful feature of Casacore tables is that different columns
286// may be bound to different data managers, which have different
287// properties.
288// <li> Define the default data manager. AipsIO in this case.
289// Note that this statement and statement 5 are actually not
290// needed. When the Table constructor finds some unbound columns,
291// it will construct the default data manager for them and
292// bind them. A default data manager can be defined in the
293// column description and defaults to AipsIO.
294// <li>
295// <li> Override the default for some particular columns.
296// <li> Create and return a 1000 row table. With the Karma storage manager
297// the table size must be defined at construction since new rows
298// can't be added or deleted. If AipsIO was the only storage manager,
299// the size wouldn't need to be defined since rows can be added with
300// AipsIO.
301// </ol>
302// </example>
303
304// <motivation>
305// In principle, SetupNewTab isn't necessary as what we are doing is logically
306// just constructing a Table, so it could be done in the Table constructor.
307// However such a process can be an involved one - binding multiple data
308// managers and filling in the shapes of direct arrays - so separating
309// the process makes it much clearer what is going on.
310// </motivation>
311
312// <todo asof="$DATE:$">
313// # A List of bugs, limitations, extensions or planned refinements.
314// <li> full implementation of tiling
315// </todo>
316
318 friend class PlainTable;
319 friend class MemoryTable;
320
321 public:
322 // Create a new table using the table description with the given name.
323 // The description will be read from a file.
324 SetupNewTable(const String& tableName, const String& tableDescName, Table::TableOption,
325 const StorageOption& = StorageOption());
326
327 // Create a new table using the given table description.
329 const StorageOption& = StorageOption());
330
331 // Copy constructor (reference semantics).
333
335
336 // Assignment (reference semantics).
338
339 // Get the name of the table.
340 const String& name() const { return newTable_p->name(); }
341
342 // Get the table create option.
343 int option() const { return newTable_p->option(); }
344
345 // Get the storage option.
346 const StorageOption& storageOption() const { return newTable_p->storageOption(); }
347
348 // Test if the table is marked for delete.
349 Bool isMarkedForDelete() const { return newTable_p->isMarkedForDelete(); }
350
351 // Get the table description.
352 const TableDesc& tableDesc() const { return newTable_p->tableDesc(); }
353
354 // Adjust the hypercolumn definitions.
355 // It renames and/or removes columns as necessary.
356 void adjustHypercolumns(const std::map<String, String>& old2new, Bool keepUnknown) {
357 newTable_p->tableDescPtr()->adjustHypercolumns(old2new, keepUnknown);
358 }
359
360 // Bind a column to the given data manager.
361 // If already bound, the binding will be overwritten.
362 // It cannot be used anymore once the SetupNewTable object is used to
363 // construct a Table object.
364 void bindColumn(const String& columnName, const DataManager& dm) {
365 newTable_p->bindColumn(columnName, dm);
366 }
367
368 // Bind a column to the given data manager of the other column.
369 // If the other column is not bound, nothing will be done.
370 // If columnName is already bound, the binding will be overwritten.
371 // It cannot be used anymore once the SetupNewTableRep object is used to
372 // construct a Table object.
373 void bindColumn(const String& columnName, const String& otherColumn) {
374 newTable_p->bindColumn(columnName, otherColumn);
375 }
376
377 // Bind a group of columns to the given data manager.
378 // The flag rebind tells if the binding of an already bound column
379 // will be overwritten.
380 // It cannot be used anymore once the SetupNewTable object is used to
381 // construct a Table object.
382 void bindGroup(const String& columnGroup, const DataManager& dm, Bool rebind = False) {
383 newTable_p->bindGroup(columnGroup, dm, rebind);
384 }
385
386 // Bind all columns to the given data manager.
387 // The flag rebind tells if the binding of an already bound column
388 // will be overwritten.
389 // It cannot be used anymore once the SetupNewTable object is used to
390 // construct a Table object.
391 void bindAll(const DataManager& dm, Bool rebind = False) { newTable_p->bindAll(dm, rebind); }
392
393 // Create data managers and bind the columns using the specifications
394 // in the given record (which is obtained using Table::dataManagerInfo()).
395 void bindCreate(const Record& spec) { newTable_p->bindCreate(spec); }
396
397 // Define the shape of fixed shaped arrays in a column.
398 // The shape of those arrays has to be known before the table
399 // can be constructed. It has to be defined via this function,
400 // if it was not already defined in the column description.
401 // If only the dimensionality was defined in the column
402 // description, the shape's dimensionality must match it.
403 // Calling this function for an non-fixed shaped array results in
404 // an exception.
405 // It cannot be used anymore once the SetupNewTable object is used to
406 // construct a Table object.
407 void setShapeColumn(const String& columnName, const IPosition& shape) {
408 newTable_p->setShapeColumn(columnName, shape);
409 }
410
411 // Test if object is already in use.
412 Bool isUsed() const { return newTable_p->isUsed(); }
413
414 private:
415 // Actual object.
416 std::shared_ptr<SetupNewTableRep> newTable_p;
417
418 // Get pointer to column set.
419 // This function is used by PlainTable.
420 const std::shared_ptr<ColumnSet>& columnSetPtr() const { return newTable_p->columnSetPtr(); }
421
422 // Get pointer to table description.
423 // This function is used by PlainTable.
424 const std::shared_ptr<TableDesc>& tableDescPtr() const { return newTable_p->tableDescPtr(); }
425
426 // Set object to in use by a (Plain)Table object.
427 // This function is used by PlainTable.
428 void setInUse() { newTable_p->setInUse(); }
429
430 // Make a data manager for all unbound columns.
431 void handleUnbound() { newTable_p->handleUnbound(); }
432};
433
434} // namespace casacore
435
436#endif
Abstract base class for a data manager.
int option() const
Get the table create option.
const String & name() const
Get the name of the table.
void bindColumn(const String &columnName, const String &otherColumn)
Bind a column to the given data manager of the other column.
const StorageOption & storageOption() const
Get the storage option.
Bool delete_p
Marked for delete?
void bindGroup(const String &columnGroup, const DataManager &, Bool rebind=False)
Bind a group of columns to the given data manager.
std::shared_ptr< TableDesc > tdescPtr_p
const std::shared_ptr< ColumnSet > & columnSetPtr() const
Get pointer to column set.
void bindCreate(const Record &spec)
Create data managers and bind the columns using the specifications in the given record (which is obta...
void setup()
Setup the new table.
const TableDesc & tableDesc() const
Get the table description.
SetupNewTableRep(const String &tableName, const TableDesc &, Table::TableOption, const StorageOption &)
Create a new table using the given table description.
void setInUse()
Set object to in use by a (Plain)Table object.
std::shared_ptr< ColumnSet > colSetPtr_p
void bindAll(const DataManager &, Bool rebind=False)
Bind all columns to the given data manager.
SetupNewTableRep(const String &tableName, const String &tableDescName, Table::TableOption, const StorageOption &)
Create a new table using the table description with the given name.
void bindColumn(const String &columnName, const DataManager &)
Bind a column to the given data manager.
SetupNewTableRep(const SetupNewTableRep &)=delete
Copy constructor is forbidden, because copying a table requires some more knowledge (like table name ...
String tabName_p
Table name.
Bool isMarkedForDelete() const
Test if the table is marked for delete.
const std::shared_ptr< TableDesc > & tableDescPtr() const
Get pointer to table description.
SetupNewTableRep & operator=(const SetupNewTableRep &)=delete
Assignment is forbidden, because copying a table requires some more knowledge (like table name of res...
void handleUnbound()
Make a data manager for all unbound columns.
Bool isUsed() const
Test if object is already in use.
void setShapeColumn(const String &columnName, const IPosition &shape)
Define the shape of fixed shaped arrays in a column.
DataManager * getDataManager(const DataManager &dataMan)
Get the internal data manager object for the given data manager.
std::map< void *, void * > dataManMap_p
int option_p
Constructor options.
void bindAll(const DataManager &dm, Bool rebind=False)
Bind all columns to the given data manager.
SetupNewTable & operator=(const SetupNewTable &)
Assignment (reference semantics).
std::shared_ptr< SetupNewTableRep > newTable_p
Actual object.
void bindCreate(const Record &spec)
Create data managers and bind the columns using the specifications in the given record (which is obta...
const StorageOption & storageOption() const
Get the storage option.
const std::shared_ptr< ColumnSet > & columnSetPtr() const
Get pointer to column set.
SetupNewTable(const String &tableName, const TableDesc &, Table::TableOption, const StorageOption &=StorageOption())
Create a new table using the given table description.
Bool isMarkedForDelete() const
Test if the table is marked for delete.
void setShapeColumn(const String &columnName, const IPosition &shape)
Define the shape of fixed shaped arrays in a column.
void setInUse()
Set object to in use by a (Plain)Table object.
const std::shared_ptr< TableDesc > & tableDescPtr() const
Get pointer to table description.
SetupNewTable(const String &tableName, const String &tableDescName, Table::TableOption, const StorageOption &=StorageOption())
Create a new table using the table description with the given name.
SetupNewTable(const SetupNewTable &)
Copy constructor (reference semantics).
Bool isUsed() const
Test if object is already in use.
const String & name() const
Get the name of the table.
int option() const
Get the table create option.
void bindColumn(const String &columnName, const DataManager &dm)
Bind a column to the given data manager.
void bindColumn(const String &columnName, const String &otherColumn)
Bind a column to the given data manager of the other column.
const TableDesc & tableDesc() const
Get the table description.
void bindGroup(const String &columnGroup, const DataManager &dm, Bool rebind=False)
Bind a group of columns to the given data manager.
void handleUnbound()
Make a data manager for all unbound columns.
void adjustHypercolumns(const std::map< String, String > &old2new, Bool keepUnknown)
Adjust the hypercolumn definitions.
String: the storage and methods of handling collections of characters.
Definition String.h:355
TableOption
Define the possible options how a table can be opened.
Definition Table.h:168
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40