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