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