casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Table.h
Go to the documentation of this file.
1 //# Table.h: Main interface classes to tables
2 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,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 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_TABLE_H
29 #define TABLES_TABLE_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
42 
43 #ifdef HAVE_MPI
44 #include <mpi.h>
45 #endif
46 
47 namespace casacore { //# NAMESPACE CASACORE - BEGIN
48 
49 //# Forward Declarations
50 class SetupNewTable;
51 class TableDesc;
52 class ColumnDesc;
53 class TableRecord;
54 class Record;
55 class TableExprNode;
56 class DataManager;
57 class IPosition;
58 template<class T> class Block;
59 template<class T> class CountedPtr;
60 
61 
62 // <summary>
63 // Main interface class to a read/write table
64 // </summary>
65 
66 // <use visibility=export>
67 
68 // <reviewed reviewer="TPPR" date="08.11.94" tests="tTable.cc">
69 // </reviewed>
70 
71 // <prerequisite>
72 //# Classes you should understand before using this one.
73 // <li> <linkto class=SetupNewTable>SetupNewTable</linkto>
74 // <li> <linkto class=TableDesc>TableDesc</linkto>
75 // <li> <linkto class=TableColumn>TableColumn</linkto>
76 // <li> <linkto class=ScalarColumn>ScalarColumn</linkto>
77 // <li> <linkto class=ArrayColumn>ArrayColum</linkto>
78 // <li> <linkto class=TableLock>TableLock</linkto>
79 // </prerequisite>
80 
81 // <synopsis>
82 // Class Table can be used to create a new table or to access an existing
83 // table in read/write or readonly mode.
84 //
85 // To access the data in a Table, objects have to be created
86 // to access the columns. These objects are TableColumn,
87 // ScalarColumn<T> and ArrayColumn<T>, which can be created
88 // via their constructors.
89 // Furthermore the Table has a TableRecord object for holding keywords
90 // which can be read or written using the appropriate functions.
91 // <br> The Table class structure is shown in this
92 // <a href="Table.drawio.svg.html">UML diagram</a>.
93 //
94 // To open an existing table, a simple Table constructor can be used.
95 // The possible construct options are:
96 // <ul>
97 // <li> Old readonly table (default option)
98 // <li> Update update existing table
99 // <li> Delete delete table
100 // </ul>
101 //
102 // Creating a new table requires more work, because columns have
103 // to be bound to storage managers or virtual column engines.
104 // Class SetupNewTable is needed for this purpose. The Tables module
105 // documentation explains in more detail how to create a table.
106 // When creating a table, it can be specified which endian format to use.
107 // By default it uses the format specified in the aipsrc variable
108 // <code>table.endianformat</code> which defaults to
109 // <code>Table::LocalEndian</code> (thus the endian format of the
110 // machine being used).
111 //
112 // Note that TableUtil contains convenience function to open, create or delete a table.
113 // They make it possible to use the :: notation to denote subtables.
114 // <p>
115 // It is possible to create a Table object as the virtual concatenation of
116 // Tables having identical table descriptions. Subtables of those tables
117 // can optionally be concatenated as well.
118 // E.g. if a MeasurementSet is partioned in time, this mechanism makes it
119 // possible to view it as a single table. Furthermore, a subtable like
120 // SYSCAL can be concatenated as well, while the other subtables are identical
121 // in all partitions and are taken from the first table only.
122 //
123 // Other Table objects can be created from a Table using
124 // the select, project and sort functions. The result in so-called
125 // reference tables. In this way a subset of a table can be created and
126 // can be read/written in the same way as a normal Table. Writing has the
127 // effect that the underlying table gets written.
128 // </synopsis>
129 
130 // <example>
131 // <srcblock>
132 // // Open a table to be updated.
133 // Table myTable ("theTable", Table::Update);
134 // // Write the column containing the scalar RA.
135 // ScalarColumn<double> raColumn(myTable, "RA");
136 // rownr_t nrrow = myTable.nrow();
137 // for (rownr_t i=0; i<nrrow; i++) {
138 // raColumn.put (i, i+10); // Put value i+10 into row i
139 // }
140 // </srcblock>
141 // </example>
142 
143 // <motivation>
144 // Table is the envelope for the underlying counted referenced
145 // classes derived from BaseTable. In this way no pointers have
146 // to be used to get polymorphism.
147 // </motivation>
148 
149 // <todo asof="$DATE:$">
150 //# A List of bugs, limitations, extensions or planned refinements.
151 // <li> add, remove, rename columns.
152 // <li> virtual concatenation of tables (if still necessary).
153 // <li> maybe an isAttached function.
154 // </todo>
155 
156 
157 class Table
158 {
159 friend class TableColumn;
160 friend class BaseTable;
161 friend class PlainTable;
162 friend class MemoryTable;
163 friend class RefTable;
164 friend class ConcatTable;
165 friend class TableIterator;
166 friend class RODataManAccessor;
167 friend class TableExprNode;
168 friend class TableExprNodeRep;
169 
170 public:
171  // Define the possible options how a table can be opened.
172  enum TableOption {
173  // existing table
174  Old=1,
175  // create table
177  // create table (may not exist)
179  // new table, which gets marked for delete
181  // update existing table
183  // delete table
185  };
186 
187  // Define the possible table types.
188  enum TableType {
189  // plain table (stored on disk)
191  // table held in memory
193  };
194 
195  // Define the possible endian formats in which table data can be stored.
197  // store table data in big endian (e.g. SUN) format
199  // store table data in little endian (e.g. Intel) format
201  // store data in the endian format of the machine used
203  // use endian format defined in the aipsrc variable table.endianformat
204  // If undefined, it defaults to LocalEndian.
206  };
207 
208 
209  // Define the signature of the function being called when the state
210  // of a scratch table changes (i.e. created, closed, renamed,
211  // (un)markForDelete).
212  // <br>- <src>isScratch=True</src> indicates that a scratch table
213  // is created (<src>oldName</src> is empty) or renamed
214  // (<src>oldName</src> is not empty).
215  // <br>- <src>isScratch=False</src> indicates that a scratch table
216  // with name <src>name</src> is not scratch anymore (because it is
217  // closed or because its state is set to non-scratch).
218  typedef void ScratchCallback (const String& name, Bool isScratch,
219  const String& oldName);
220 
221  // Set the pointer to the ScratchCallback function.
222  // It returns the current value of the pointer.
223  // This function is called when changing the state of a table
224  // (i.e. create, close, rename, (un)markForDelete).
226 
227 
228  // Create a null Table object (i.e. a NullTable is attached).
229  // The sole purpose of this constructor is to allow construction
230  // of an array of Table objects.
231  // The assignment operator can be used to make a null object
232  // reference a proper table.
233  Table();
234 
235  // Create a table object for an existing table.
236  // The only options allowed are Old, Update, and Delete.
237  // If the name of a table description is given, it is checked
238  // if the table has that description.
239  // Locking options can be given (see class
240  // <linkto class=TableLock>TableLock</linkto>.
241  // If the table with this name was already opened in this process,
242  // the existing and new locking options are merged using
243  // <src>TableLock::merge</src>.
244  // The default locking mechanism is DefaultLocking. If the table
245  // is not open yet, it comes to AutoLocking with an inspection interval
246  // of 5 seconds. Otherwise DefaultLocking keeps the locking options
247  // of the already open table.
248  // <group>
249  explicit Table (const String& tableName, TableOption = Table::Old,
250  const TSMOption& = TSMOption());
251  Table (const String& tableName, const TableLock& lockOptions,
252  TableOption = Table::Old, const TSMOption& = TSMOption());
253  Table (const String& tableName, const String& tableDescName,
254  TableOption = Table::Old, const TSMOption& = TSMOption());
255  Table (const String& tableName, const String& tableDescName,
256  const TableLock& lockOptions, TableOption = Table::Old,
257  const TSMOption& = TSMOption());
258  // </group>
259 
260  // Make a new empty table (plain (scratch) or memory type).
261  // Columns should be added to make it a real one.
262  // Note that the endian format is only relevant for plain tables.
264  const TSMOption& = TSMOption());
265 
266  // Make a table object for a new table, which can thereafter be used
267  // for reading and writing.
268  // If there are unbound columns, default storage managers an/ord virtual
269  // column engines will be created and bound to those columns.
270  // Create the table with the given nr of rows. If a storage manager
271  // is used which does not allow addition of rows, the number of rows
272  // in the table must already be given here.
273  // Optionally the rows can be initialized with the default
274  // values as defined in the column descriptions.
275  // Locking options can be given (see class
276  // <linkto class=TableLock>TableLock</linkto>.
277  // The default locking mechanism is AutoLocking with a default
278  // inspection interval of 5 seconds.
279  // <br>The data will be stored in the given endian format.
280  // <group>
281  explicit Table (SetupNewTable&, rownr_t nrrow = 0, Bool initialize = False,
283  const TSMOption& = TSMOption());
285  rownr_t nrrow = 0, Bool initialize = False,
287  Table (SetupNewTable&, TableType, const TableLock& lockOptions,
288  rownr_t nrrow = 0, Bool initialize = False,
291  rownr_t nrrow = 0, Bool initialize = False,
293  Table (SetupNewTable&, const TableLock& lockOptions,
294  rownr_t nrrow = 0, Bool initialize = False,
296 #ifdef HAVE_MPI
297  explicit Table (MPI_Comm mpiComm, TableType, EndianFormat = Table::AipsrcEndian,
298  const TSMOption& = TSMOption());
299  explicit Table (MPI_Comm mpiComm, SetupNewTable&, rownr_t nrrow = 0,
300  Bool initialize = False,
302  const TSMOption& = TSMOption());
303  Table (MPI_Comm mpiComm, SetupNewTable&, TableType,
304  rownr_t nrrow = 0, Bool initialize = False,
306  Table (MPI_Comm mpiComm, SetupNewTable&, TableType, const TableLock& lockOptions,
307  rownr_t nrrow = 0, Bool initialize = False,
309  Table (MPI_Comm mpiComm, SetupNewTable&, TableLock::LockOption,
310  rownr_t nrrow = 0, Bool initialize = False,
312  Table (MPI_Comm mpiComm, SetupNewTable&, const TableLock& lockOptions,
313  rownr_t nrrow = 0, Bool initialize = False,
315 #endif
316  // </group>
317 
318  // Create a table object as the virtual concatenation of
319  // one or more of existing tables. The descriptions of all those tables
320  // must be exactly the same.
321  // <br>The keywordset of the virtual table is the set of the first table
322  // including its subtables. However, it is possible to specify the names
323  // of the subtables that have to be concantenated as well.
324  // <br>In this way a concatenation of multiple MS-s can be made, where it
325  // can be specified that, say, the SYSCAL table has to be concatenated too.
326  // <br> When a concatenated table is written and if a non-empty
327  // <src>subDirName</src> is given, the tables to be concatenated will be
328  // moved to that subdirectory in the directory of the concatenated table.
329  // This option is mainly used by the MSS structure used in CASA.
330  // <br>
331  // The only open options allowed are Old and Update.
332  // Locking options can be given (see class
333  // <linkto class=TableLock>TableLock</linkto>.
334  // They apply to all underlying tables.
335  // If a table was already opened in this process,
336  // the existing and new locking options are merged using
337  // <src>TableLock::merge</src>.
338  // The default locking mechanism is DefaultLocking. If the table
339  // is not open yet, it comes to AutoLocking with an inspection interval
340  // of 5 seconds. Otherwise DefaultLocking keeps the locking options
341  // of the already open table.
342  // <group>
343  explicit Table (const Block<Table>& tables,
344  const Block<String>& subTables = Block<String>(),
345  const String& subDirName = String());
346  explicit Table (const Block<String>& tableNames,
347  const Block<String>& subTables = Block<String>(),
349  const String& subDirName = String());
350  Table (const Block<String>& tableNames,
351  const Block<String>& subTables,
352  const TableLock& lockOptions,
353  TableOption = Table::Old, const TSMOption& = TSMOption());
354  // </group>
355 
356  // Copy constructor (reference semantics).
357  Table (const Table&);
358 
359  // The destructor flushes (i.e. writes) the table if it is opened
360  // for output and not marked for delete.
361  // It will flush if the destructor is called due to an exception,
362  // because the Table object may not be correct.
363  // Of course, in that case the flush function could be called explicitly.
364  // <br>It is virtual, so an object of a derived class like MeasurementSet
365  // is destructed correctly through a Table pointer.
366  virtual ~Table();
367 
368  // Assignment (reference semantics).
369  Table& operator= (const Table&);
370 
371  // Get the names of the tables this table consists of.
372  // For a plain table it returns its name,
373  // for a RefTable the name of the parent, and
374  // for a ConcatTable the names of all its parts.
375  // <br>Note that a part can be any type of table (e.g. a ConcatTable).
376  // The recursive switch tells how to deal with that.
377  Block<String> getPartNames (Bool recursive=False) const;
378 
379  // Is the root table of this table the same as that of the other one?
380  Bool isSameRoot (const Table& other) const;
381 
382  // Close all open subtables.
383  void closeSubTables() const;
384 
385  // Try to reopen the table for read/write access.
386  // An exception is thrown if the table is not writable.
387  // Nothing is done if the table is already open for read/write.
388  void reopenRW();
389 
390  // Get the endian format in which the table is stored.
392 
393  // Get the storage option used for the table.
394  const StorageOption& storageOption() const;
395 
396  // Is the table used (i.e. open) in this process.
397  static Bool isOpened (const String& tableName);
398 
399  // Is the table used (i.e. open) in another process.
400  // If <src>checkSubTables</src> is set, it is also checked if
401  // a subtable is used in another process.
402  Bool isMultiUsed (Bool checkSubTables=False) const;
403 
404  // Get the locking options.
405  const TableLock& lockOptions() const;
406 
407  // Has this process the read or write lock, thus can the table
408  // be read or written safely?
409  // <group>
411  Bool hasLock (Bool write) const;
412  // </group>
413 
414  // Try to lock the table for read or write access (default is write).
415  // The number of attempts (default = forever) can be specified when
416  // acquiring the lock does not succeed immediately. If nattempts>1,
417  // the system waits 1 second between each attempt, so nattempts
418  // is more or less equal to a wait period in seconds.
419  // The return value is false if acquiring the lock failed.
420  // If <src>PermanentLocking</src> is in effect, a lock is already
421  // present, so nothing will be done.
422  // <group>
424  Bool lock (Bool write, uInt nattempts = 0);
425  // </group>
426 
427  // Unlock the table. This will also synchronize the table data,
428  // thus force the data to be written to disk.
429  // If <src>PermanentLocking</src> is in effect, nothing will be done.
430  void unlock();
431 
432  // Determine the number of locked tables opened with the AutoLock option
433  // (Locked table means locked for read and/or write).
434  static uInt nAutoLocks();
435 
436  // Unlock locked tables opened with the AutoLock option.
437  // If <src>all=True</src> all such tables will be unlocked.
438  // If <src>all=False</src> only tables requested by another process
439  // will be unlocked.
440  static void relinquishAutoLocks (Bool all = False);
441 
442  // Get the names of tables locked in this process.
443  // By default all locked tables are given (note that a write lock
444  // implies a read lock), but it is possible to select on lock type
445  // FileLocker::Write and on option (TableLock::AutoLocking,
446  // TableLock::ReadLocking, or TableLock::PermanentLocking).
448  int lockOption=-1);
449 
450  // Determine if column or keyword table data have changed
451  // (or is being changed) since the last time this function was called.
453 
454  // Flush the table, i.e. write out the buffers. If <src>sync=True</src>,
455  // it is ensured that all data are physically written to disk.
456  // Nothing will be done if the table is not writable.
457  // At any time a flush can be executed, even if the table is marked
458  // for delete.
459  // If the table is marked for delete, the destructor will remove
460  // files written by intermediate flushes.
461  // Note that if necessary the destructor will do an implicit flush,
462  // unless it is executed due to an exception.
463  // <br>If <src>fsync=True</src> the file contents are fsync-ed to disk,
464  // thus ensured that the system buffers are actually written to disk.
465  // <br>If <src>recursive=True</src> all subtables are flushed too.
466  void flush (Bool fsync=False, Bool recursive=False);
467 
468  // Resynchronize the Table object with the table file.
469  // This function is only useful if no read-locking is used, ie.
470  // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
471  // In that cases the table system does not acquire a read-lock, thus
472  // does not synchronize itself automatically.
473  void resync();
474 
475  // Test if the object is null, i.e. does not reference a proper table.
476  // This is the case if the default constructor is used.
477  Bool isNull() const
478  { return (baseTabPtr_p == 0 ? True : baseTabPtr_p->isNull()); }
479 
480  // Throw an exception if the object is null, i.e.
481  // if function isNull() is True.
482  void throwIfNull() const;
483 
484  // Test if the given data type is native to the table system.
485  // If not, a virtual column engine is needed to store data with that type.
486  // With the function DataType::whatType it can be used in a templated
487  // function like:
488  // <srcblock>
489  // if (Table::isNativeDataType (whatType(static_cast<T*>(0)))) {
490  // </srcblock>
491  static Bool isNativeDataType (DataType dtype);
492 
493  // Make the table file name.
494  static String fileName (const String& tableName);
495 
496  // Test if a table with the given name exists and is readable.
497  // If not, an exception is thrown if <src>throwIf==True</src>.
498  static Bool isReadable (const String& tableName, bool throwIf=False);
499 
500  // Show the structure of the table.
501  // It shows the columns (with types), the data managers, and the subtables.
502  // Optionally the columns can be sorted alphabetically.
503  void showStructure (std::ostream&,
504  Bool showDataMans=True,
505  Bool showColumns=True,
506  Bool showSubTables=False,
507  Bool sortColumns=False,
508  Bool cOrder=False) const;
509 
510  // Show the table and/or column keywords, possibly also of all subtables.
511  // Maximum <src>maxVal</src> values of Arrays will be shown.
512  void showKeywords (std::ostream&,
513  Bool showSubTables=False,
514  Bool showTabKey=True,
515  Bool showColKey=False,
516  Int maxVal=25) const;
517 
518  // Show the table and/or column keywords of this table.
519  // Maximum <src>maxVal</src> values of Arrays will be shown.
520  void showKeywordSets (std::ostream&,
521  Bool showTabKey, Bool showColKey,
522  Int maxVal) const;
523 
524  // Test if a table with the given name exists and is writable.
525  static Bool isWritable (const String& tableName, bool throwIf=False);
526 
527  // Find the non-writable files in a table.
528  static Vector<String> nonWritableFiles (const String& tableName);
529 
530  // Test if this table is the root table (ie. if it is not the subset
531  // of another table).
532  Bool isRootTable() const;
533 
534  // Test if this table is opened as writable.
535  Bool isWritable() const;
536 
537  // Test if the given column is writable.
538  // <group>
539  Bool isColumnWritable (const String& columnName) const;
540  Bool isColumnWritable (uInt columnIndex) const;
541  // </group>
542 
543  // Test if the given column is stored (otherwise it is virtual).
544  // <group>
545  Bool isColumnStored (const String& columnName) const;
546  Bool isColumnStored (uInt columnIndex) const;
547  // </group>
548 
549  // Get readonly access to the table keyword set.
550  // If UserLocking is used, it will automatically acquire
551  // and release a read lock if the table is not locked.
552  const TableRecord& keywordSet() const;
553 
554  // Get read/write access to the table keyword set.
555  // This requires that the table is locked (or it gets locked
556  // if using AutoLocking mode).
558 
559  // Get access to the TableInfo object.
560  // <group>
561  const TableInfo& tableInfo() const;
562  TableInfo& tableInfo();
563  // </group>
564 
565  // Write the TableInfo object.
566  // Usually this is not necessary, because it is done automatically
567  // when the table gets written (by table destructor or flush function).
568  // This function is only useful if the table info has to be written
569  // before the table gets written (e.g. when another process reads
570  // the table while it gets filled).
571  void flushTableInfo() const;
572 
573  // Get the table description.
574  // This can be used to get nr of columns, etc..
575  // <src>tableDesc()</src> gives the table description used when
576  // constructing the table, while <src>actualTableDesc()</src> gives the
577  // actual description, thus with the actual data managers used.
578  // <group>
579  const TableDesc& tableDesc() const;
580  TableDesc actualTableDesc() const;
581  // </group>
582 
583  // Return all data managers used and the columns served by them.
584  // The info is returned in a record. It contains a subrecord per
585  // data manager. Each subrecord contains the following fields:
586  // <dl>
587  // <dt> TYPE
588  // <dd> a string giving the type of the data manager.
589  // <dt> NAME
590  // <dd> a string giving the name of the data manager.
591  // <dt> COLUMNS
592  // <dd> a vector of strings giving the columns served by the data manager.
593  // </dl>
594  // Data managers may return some additional fields (e.g. BUCKETSIZE).
595  Record dataManagerInfo() const;
596 
597  // Get the table name.
598  const String& tableName() const;
599 
600  // Rename the table and all its subtables.
601  // The following options can be given:
602  // <dl>
603  // <dt> Table::Update
604  // <dd> A table with this name must already exists, which will be
605  // overwritten. When succesfully renamed, the table is unmarked
606  // for delete (if necessary).
607  // <dt> Table::New
608  // <dd> If a table with this name exists, it will be overwritten.
609  // When succesfully renamed, the table is unmarked
610  // for delete (if necessary).
611  // <dt> Table::NewNoReplace
612  // <dd> If a table with this name already exists, an exception
613  // is thrown. When succesfully renamed, the table
614  // is unmarked for delete (if necessary).
615  // <dt> Table::Scratch
616  // <dd> Same as Table::New, but followed by markForDelete().
617  // </dl>
618  // The scratchCallback function is called when needed.
619  void rename (const String& newName, TableOption);
620 
621  // Copy the table and all its subtables.
622  // Especially for RefTables <src>copy</src> and <src>deepCopy</src> behave
623  // differently. <src>copy</src> makes a bitwise copy of the table, thus
624  // the result is still a RefTable. On the other hand <src>deepCopy</src>
625  // makes a physical copy of all referenced table rows and columns, thus
626  // the result is a PlainTable.
627  // <br>For PlainTables <src>deepCopy</src> is the same as <src>copy</src>
628  // unless <src>valueCopy==True</src> is given. In that case the values
629  // are copied which takes longer, but reorganizes the data files to get
630  // rid of gaps in the data. Also if specific DataManager info is given
631  // or if no rows have to be copied, a deep copy is made.
632  // <br>The following options can be given:
633  // <dl>
634  // <dt> Table::New
635  // <dd> If a table with this name exists, it will be overwritten.
636  // <dt> Table::NewNoReplace
637  // <dd> If a table with this name already exists, an exception
638  // is thrown.
639  // <dt> Table::Scratch
640  // <dd> Same as Table::New, but followed by markForDelete().
641  // </dl>
642  // <group>
643  // The new table gets the given endian format. Note that the endian option
644  // is only used if a true deep copy of a table is made.
645  // <br>When making a deep copy, it is possible to specify the data managers
646  // using the <src>dataManagerInfo</src> argument.
647  // See <src>getDataManagerInfo</src> for more info about that record.
648  // <br>If <src>noRows=True</src> no rows are copied. Also no rows are
649  // copied in all subtables. It is useful if one wants to make a copy
650  // of only the Table structure.
651  void copy (const String& newName, TableOption, Bool noRows=False) const;
652  void deepCopy (const String& newName,
653  TableOption, Bool valueCopy=False,
655  Bool noRows=False) const;
656  void deepCopy (const String& newName, const Record& dataManagerInfo,
657  TableOption, Bool valueCopy=False,
659  Bool noRows=False) const;
660  void deepCopy (const String& newName, const Record& dataManagerInfo,
661  const StorageOption&,
662  TableOption, Bool valueCopy=False,
664  Bool noRows=False) const;
665  // </group>
666 
667  // Make a copy of a table to a MemoryTable object.
668  // Use the given name for the memory table.
669  Table copyToMemoryTable (const String& name, Bool noRows=False) const;
670 
671  // Get the table type.
672  TableType tableType() const;
673 
674  // Get the table option.
675  int tableOption() const;
676 
677  // Mark the table for delete.
678  // This means that the underlying table gets deleted when it is
679  // actually destructed.
680  // The scratchCallback function is called when needed.
681  void markForDelete();
682 
683  // Unmark the table for delete.
684  // This means the underlying table does not get deleted when destructed.
685  // The scratchCallback function is called when needed.
686  void unmarkForDelete();
687 
688  // Test if the table is marked for delete.
689  Bool isMarkedForDelete() const;
690 
691  // Get the number of rows.
692  // It is unsynchronized meaning that it will not check if another
693  // process updated the table, thus possible increased the number of rows.
694  // If one wants to take that into account, he should acquire a
695  // read-lock (using the lock function) before using nrow().
696  rownr_t nrow() const;
697 
698  // Test if it is possible to add a row to this table.
699  // It is possible if all storage managers used for the table
700  // support it.
701  Bool canAddRow() const;
702 
703  // Add one or more rows at the end of the table.
704  // This will fail for tables not supporting addition of rows.
705  // Optionally the rows can be initialized with the default
706  // values as defined in the column descriptions.
707  void addRow (rownr_t nrrow = 1, Bool initialize = False);
708 
709  // Test if it is possible to remove a row from this table.
710  // It is possible if all storage managers used for the table
711  // support it.
712  Bool canRemoveRow() const;
713 
714  // Remove the given row(s).
715  // The latter form can be useful with the select and rowNumbers functions
716  // to remove some selected rows from the table.
717  // <br>It will fail for tables not supporting removal of rows.
718  // <note role=warning>
719  // The following code fragments do NOT have the same result:
720  // <srcblock>
721  // tab.removeRow (10); // remove row 10
722  // tab.removeRow (20); // remove row 20, which was 21
723  // Vector<rownr_t> vec(2);
724  // vec(0) = 10;
725  // vec(1) = 20;
726  // tab.removeRow (vec); // remove row 10 and 20
727  // </srcblock>
728  // because in the first fragment removing row 10 turns the former
729  // row 21 into row 20.
730  // </note>
731  // <group>
732  void removeRow (rownr_t rownr);
733  void removeRow (const RowNumbers& rownrs);
734  // </group>
735 
736  // Create a TableExprNode object for a column or for a keyword
737  // in the table keyword set.
738  // This can be used in selecting rows from a table using
739  // <src>operator()</src> described below.
740  // <br>The functions taking the fieldNames vector are meant for
741  // the cases where the keyword or column contains records.
742  // The fieldNames indicate which field to take from that record
743  // (which can be a record again, etc.).
744  // <group name=keycol>
745  TableExprNode key (const String& keywordName) const;
746  TableExprNode key (const Vector<String>& fieldNames) const;
747  TableExprNode col (const String& columnName) const;
748  TableExprNode col (const String& columnName,
749  const Vector<String>& fieldNames) const;
750  TableExprNode keyCol (const String& name,
751  const Vector<String>& fieldNames) const;
752  // </group>
753 
754  // Create a TableExprNode object for the rownumber function.
755  // 'origin' Indicates which rownumber is the first.
756  // C++ uses origin = 0 (default)
757  // Glish and TaQL both use origin = 1
758  TableExprNode nodeRownr (rownr_t origin=0) const;
759 
760  // Create a TableExprNode object for the rand function.
761  TableExprNode nodeRandom () const;
762 
763  // Select rows from a table using an select expression consisting
764  // of TableExprNode objects.
765  // Basic TableExprNode objects can be created with the functions
766  // <linkto file="Table.h#keycol">key</linkto> and especially
767  // <linkto file="Table.h#keycol">col</linkto>.
768  // Composite TableExprNode objects, representing an expression,
769  // can be created by applying operations (like == and +)
770  // to the basic ones. This is described in class
771  // <linkto class="TableExprNode:description">TableExprNode</linkto>.
772  // For example:
773  // <srcblock>
774  // Table result = tab(tab.col("columnName") > 10);
775  // </srcblock>
776  // All rows for which the expression is true, will be selected and
777  // "stored" in the result.
778  // You need to include ExprNode.h for this purpose.
779  // <br>The first <src>offset</src> matching rows will be skipped.
780  // <br>If <src>maxRow>0</src>, the selection process will stop
781  // when <src>maxRow</src> rows are selected.
782  // <br>The TableExprNode argument can be empty (null) meaning that only
783  // the <src>maxRow/offset</src> arguments are taken into account.
784  Table operator() (const TableExprNode&, rownr_t maxRow=0, rownr_t offset=0) const;
785 
786  // Select rows using a vector of row numbers.
787  // This can, for instance, be used to select the same rows as
788  // were selected in another table (using the rowNumbers function).
789  // <srcblock>
790  // Table result = thisTable (otherTable.rowNumbers());
791  // </srcblock>
792  Table operator() (const RowNumbers& rownrs) const;
793 
794  // Select rows using a mask block.
795  // The length of the block must match the number of rows in the table.
796  // If an element in the mask is True, the corresponding row will be
797  // selected.
798  Table operator() (const Block<Bool>& mask) const;
799 
800  // Project the given columns (i.e. select the columns).
801  Table project (const Block<String>& columnNames) const;
802 
803  //# Virtually concatenate all tables in this column.
804  //# The column cells must contain tables with the same description.
805 //#// Table concatenate (const String& columnName) const;
806 
807  // Do logical operations on a table.
808  // It can be used for row-selected or projected (i.e. column-selected)
809  // tables. The tables involved must come from the same root table or
810  // be the root table themselves.
811  // <group>
812  // Intersection with another table.
813  Table operator& (const Table&) const;
814  // Union with another table.
815  Table operator| (const Table&) const;
816  // Subtract another table.
817  Table operator- (const Table&) const;
818  // Xor with another table.
819  Table operator^ (const Table&) const;
820  // Take complement.
821  Table operator! () const;
822  // </group>
823 
824  // Sort a table on one or more columns of scalars.
825  // Per column a compare function can be provided. By default
826  // the standard compare function defined in Compare.h will be used.
827  // Default sort order is ascending.
828  // Default sorting algorithm is the parallel sort.
829  // <group>
830  // Sort on one column.
831  Table sort (const String& columnName,
832  int = Sort::Ascending,
833  int = Sort::ParSort) const;
834  // Sort on multiple columns. The principal column has to be the
835  // first element in the Block of column names.
836  Table sort (const Block<String>& columnNames,
837  int = Sort::Ascending,
838  int = Sort::ParSort) const;
839  // Sort on multiple columns. The principal column has to be the
840  // first element in the Block of column names.
841  // The order can be given per column.
842  Table sort (const Block<String>& columnNames,
843  const Block<Int>& sortOrders,
844  int = Sort::ParSort) const;
845  // Sort on multiple columns. The principal column has to be the
846  // first element in the Block of column names.
847  // The order can be given per column.
848  // Provide some special comparisons via CountedPtrs of compare objects.
849  // A null CountedPtr means using the standard compare object
850  // from class <linkto class="ObjCompare:description">ObjCompare</linkto>.
851  Table sort (const Block<String>& columnNames,
852  const Block<CountedPtr<BaseCompare> >& compareObjects,
853  const Block<Int>& sortOrders,
854  int = Sort::ParSort) const;
855  // </group>
856 
857  // Get a vector of row numbers in the root table of rows in this table.
858  // In case the table is a subset of the root table, this tells which
859  // rows of the root table are part of the subset.
860  // In case the table is the root table itself, the result is a vector
861  // containing the row numbers 0 .. #rows-1.
862  // <br>Note that in general it is better to use the next
863  // <src>rowNumbers(Table)</src> function.
864  RowNumbers rowNumbers() const;
865 
866  // Get a vector of row numbers in that table of rows in this table.
867  // In case the table is a subset of that table, this tells which
868  // rows of that table are part of the subset.
869  // In case the table is that table itself, the result is a vector
870  // containing the row numbers 0 .. #rows-1.
871  // <note role=caution>This function is in principle meant for cases
872  // where this table is a subset of that table. However, it can be used
873  // for any table. In that case the returned vector contains a very high
874  // number (max_uint) for rows in this table not part of that table.
875  // In that way they are invalid if used elsewhere.
876  // <br>In the general case creating the row number vector can be slowish,
877  // because it has to do two mappings. However, if this table is a subset
878  // of that table and if they are in the same order, the mapping can be done
879  // in a more efficient way. The argument <src>tryFast</src> can be used to
880  // tell the function to try a fast conversion first. If that cannot be done,
881  // it reverts to the slower way at the expense of an unsuccessful fast
882  // attempt.
883  // </note>
884  // <srcblock>
885  // Table tab("somename");
886  // Table subset = tab(some_select_expression);
887  // RowNumbers rownrs = subset.rowNumbers(tab);
888  // </srcblock>
889  // Note that one cannot be sure that table "somename" is the root
890  // (i.e. original) table. It may also be a subset of another table.
891  // In the latter case doing
892  // <br> <src> RowNumbers rownrs = subset.rowNumbers()</src>
893  // does not give the row numbers in <src>tab</src>, but in the root table
894  // (which is probably not what you want).
895  RowNumbers rowNumbers (const Table& that, Bool tryFast=False) const;
896 
897  // Add a column to the table.
898  // The data manager used for the column depend on the function used.
899  // Exceptions are thrown if the column already exist or if the
900  // table is not writable.
901  // <br>If this table is a reference table (result of selection) and if
902  // <src>addToParent=True</src> the column is also added to the parent
903  // table.
904  // <group>
905  // Use the first appropriate existing storage manager.
906  // If there is none, a data manager is created using the default
907  // data manager in the column description.
908  void addColumn (const ColumnDesc& columnDesc,
909  Bool addToParent = True);
910  // Use an existing data manager with the given name or type.
911  // If the flag byName is True, a name is given, otherwise a type.
912  // If a name is given, an exception is thrown if the data manager is
913  // unknown or does not allow addition of columns.
914  // If a type is given, a storage manager of the given type will be
915  // created if there is no such data manager allowing addition of rows.
916  void addColumn (const ColumnDesc& columnDesc,
917  const String& dataManager, Bool byName,
918  Bool addToParent = True);
919  // Use the given data manager (which is a new one).
920  void addColumn (const ColumnDesc& columnDesc,
921  const DataManager& dataManager,
922  Bool addToParent = True);
923  // </group>
924 
925  // Add a bunch of columns using the given new data manager.
926  // All columns and possible hypercolumn definitions in the given table
927  // description will be copied and added to the table.
928  // This can be used in case of specific data managers which need to
929  // be created with more than one column (e.g. the tiled hypercube
930  // storage managers).
931  // <br>The data manager can be given directly or by means of a record
932  // describing the data manager in the standard way with the fields
933  // TYPE, NAME, and SPEC. The record can contain those fields itself
934  // or it can contain a single subrecord with those fields.
935  // <br>If this table is a reference table (result of selection) and if
936  // <src>addToParent=True</src> the columns are also added to the parent
937  // table.
938  // <group>
939  void addColumn (const TableDesc& tableDesc,
940  const DataManager& dataManager,
941  Bool addToParent = True);
942  void addColumn (const TableDesc& tableDesc,
943  const Record& dataManagerInfo,
944  Bool addToParent = True);
945  // </group>
946 
947  // Test if columns can be removed.
948  // It can if the columns exist and if the data manager it is using
949  // supports removal of columns or if all columns from a data manager
950  // would be removed..
951  // <br>You can always remove columns from a reference table.
952  // <group>
953  Bool canRemoveColumn (const String& columnName) const;
954  Bool canRemoveColumn (const Vector<String>& columnNames) const;
955  // </group>
956 
957  // Remove columns.
958  // <br>When removing columns from a reference table, the columns
959  // are NOT removed from the underlying table.
960  // <group>
961  void removeColumn (const String& columnName);
962  void removeColumn (const Vector<String>& columnName);
963  // </group>
964 
965  // Test if a column can be renamed.
966  Bool canRenameColumn (const String& columnName) const;
967 
968  // Rename a column.
969  // An exception is thrown if the old name does not exist or
970  // if the name already exists.
971  // <note role=caution>
972  // Renaming a column should be done with care, because other
973  // columns may be referring this column. Also a hypercolumn definition
974  // might be using the old name.
975  // Finally if may also invalidate persistent selections of a table,
976  // because the reference table cannot find the column anymore.
977  // </note>
978  void renameColumn (const String& newName, const String& oldName);
979 
980  void renameHypercolumn (const String& newName, const String& oldName);
981 
982  // Write a table to AipsIO (for <src>TypedKeywords<Table></src>).
983  // This will only write the table name.
984  friend AipsIO& operator<< (AipsIO&, const Table&);
985 
986  // Read a table from AipsIO (for <src>TypedKeywords<Table></src>).
987  // This will read the table name and open the table as writable
988  // if the table file is writable, otherwise as readonly.
989  friend AipsIO& operator>> (AipsIO&, Table&);
990 
991  // Read a table from AipsIO (for <src>TableKeywords</src>).
992  // This will read the table name and open the table as writable
993  // if the switch is set and if the table file is writable.
994  // otherwise it is opened as readonly.
995  void getTableKeyword (AipsIO&, Bool openWritable);
996 
997  // Write a table to ostream (for <src>TypedKeywords<Table></src>).
998  // This only shows its name and number of columns and rows.
999  friend ostream& operator<< (ostream&, const Table&);
1000 
1001  // Find the data manager with the given name or for the given column name.
1002  DataManager* findDataManager (const String& name,
1003  Bool byColumn=False) const;
1004 
1005  // Some deprecated functions for backward compatibility, now in TableUtil.h.
1006  // Use old way of indicating deprecate to avoid -Wc++14-extensions warnings.
1007  // <group>
1008  //# [[deprecated ("Now use TableUtil::openTable")]]
1009  static Table openTable (const String& tableName,
1011  const TSMOption& = TSMOption())
1012  __attribute__ ((deprecated ("Now use TableUtil::openTable")));
1013  //# [[deprecated ("Now use TableUtil::openTable")]]
1014  static Table openTable (const String& tableName,
1015  const TableLock& lockOptions,
1016  TableOption = Table::Old,
1017  const TSMOption& = TSMOption())
1018  __attribute__ ((deprecated ("Now use TableUtil::openTable")));
1019  //# [[deprecated ("Now use TableUtil::canDeleteTable")]]
1020  static Bool canDeleteTable (const String& tableName,
1021  Bool checkSubTables=False)
1022  __attribute__ ((deprecated ("Now use TableUtil::canDeleteTable")));
1023  //# [[deprecated ("Now use TableUtil::canDeleteTable")]]
1024  static Bool canDeleteTable (String& message, const String& tableName,
1025  Bool checkSubTables=False)
1026  __attribute__ ((deprecated ("Now use TableUtil::canDeleteTable")));
1027  //# [[deprecated ("Now use TableUtil::deleteTable")]]
1028  static void deleteTable (const String& tableName,
1029  Bool checkSubTables=False)
1030  __attribute__ ((deprecated ("Now use TableUtil::deleteTable")));
1031  //# [[deprecated ("Now use TableUtil::getLayout")]]
1032  static rownr_t getLayout (TableDesc& desc, const String& tableName)
1033  __attribute__ ((deprecated ("Now use TableUtil::getLayout")));
1034  //# [[deprecated ("Now use TableUtil::tableInfo")]]
1035  static TableInfo tableInfo (const String& tableName)
1036  __attribute__ ((deprecated ("Now use TableUtil::tableInfo")));
1037  // </group>
1038 
1039 protected:
1040  BaseTable* baseTabPtr_p; //# ptr to table representation
1041  //# The isCounted_p flag is normally true.
1042  //# Only for internally used Table objects (i.e. in the DataManager)
1043  //# this flag is False, otherwise a mutual dependency would exist.
1044  //# The DataManager has a Table object, which gets deleted by the
1045  //# DataManager destructor. The DataManager gets deleted by the
1046  //# PlainTable destructor, which gets called when the last Table
1047  //# object gets destructed. That would never be the case if this
1048  //# internally used Table object was counted.
1049  Bool isCounted_p;
1050  //# Counter of last call to hasDataChanged.
1051  uInt lastModCounter_p;
1052  //# Pointer to the ScratchCallback function.
1053  static ScratchCallback* scratchCallback_p;
1054 
1055 
1056  // Construct a Table object from a BaseTable*.
1057  // By default the object gets counted.
1058  Table (BaseTable*, Bool countIt = True);
1059 
1060  // Open an existing table.
1061  void open (const String& name, const String& type, int tableOption,
1062  const TableLock& lockOptions, const TSMOption& tsmOpt);
1063 
1064 private:
1065  // Construct a BaseTable object from the table file.
1066  static BaseTable* makeBaseTable (const String& name, const String& type,
1067  int tableOption,
1068  const TableLock& lockOptions,
1069  const TSMOption& tsmOpt,
1070  Bool addToCache, uInt locknr);
1071 
1072 
1073  // Get the pointer to the underlying BaseTable.
1074  // This is needed for some friend classes.
1075  BaseTable* baseTablePtr() const;
1076 
1077  // Look in the cache if the table is already open.
1078  // If so, check if table option matches.
1079  // If needed reopen the table for read/write and merge the lock options.
1080  BaseTable* lookCache (const String& name, int tableOption,
1081  const TableLock& tableInfo);
1082 
1083  // Try if v1 is a subset of v2 and fill rows with its indices in v2.
1084  // Return False if not a proper subset.
1085  Bool fastRowNumbers (const Vector<rownr_t>& v1, const Vector<rownr_t>& v2,
1086  Vector<rownr_t>& rows) const;
1087 
1088  // Show the info of the given columns.
1089  // Sort the columns if needed.
1090  void showColumnInfo (ostream& os, const TableDesc&, uInt maxNameLength,
1091  const Array<String>& columnNames, Bool sort) const;
1092 };
1093 
1094 
1095 
1096 inline Bool Table::isSameRoot (const Table& other) const
1097  { return baseTabPtr_p->root() == other.baseTabPtr_p->root(); }
1098 
1099 inline void Table::reopenRW()
1100  { baseTabPtr_p->reopenRW(); }
1101 inline void Table::flush (Bool fsync, Bool recursive)
1102  { baseTabPtr_p->flush (fsync, recursive); }
1103 inline void Table::resync()
1104  { baseTabPtr_p->resync(); }
1105 
1107  { return baseTabPtr_p->storageOption(); }
1108 inline Bool Table::isMultiUsed(Bool checkSubTables) const
1109  { return baseTabPtr_p->isMultiUsed(checkSubTables); }
1110 inline const TableLock& Table::lockOptions() const
1111  { return baseTabPtr_p->lockOptions(); }
1112 inline Bool Table::lock (FileLocker::LockType type, uInt nattempts)
1113  { return baseTabPtr_p->lock (type, nattempts); }
1114 inline Bool Table::lock (Bool write, uInt nattempts)
1115 {
1116  return baseTabPtr_p->lock (write ? FileLocker::Write : FileLocker::Read,
1117  nattempts);
1118 }
1119 inline void Table::unlock()
1120  { baseTabPtr_p->unlock(); }
1122  { return baseTabPtr_p->hasLock (type); }
1123 inline Bool Table::hasLock (Bool write) const
1124 {
1125  return baseTabPtr_p->hasLock (write ? FileLocker::Write : FileLocker::Read);
1126 }
1127 
1128 inline Bool Table::isRootTable() const
1129  { return baseTabPtr_p == baseTabPtr_p->root(); }
1130 
1131 inline Bool Table::isWritable() const
1132  { return baseTabPtr_p->isWritable(); }
1133 inline Bool Table::isColumnWritable (const String& columnName) const
1134  { return baseTabPtr_p->isColumnWritable (columnName); }
1135 inline Bool Table::isColumnWritable (uInt columnIndex) const
1136  { return baseTabPtr_p->isColumnWritable (columnIndex); }
1137 
1138 inline Bool Table::isColumnStored (const String& columnName) const
1139  { return baseTabPtr_p->isColumnStored (columnName); }
1140 inline Bool Table::isColumnStored (uInt columnIndex) const
1141  { return baseTabPtr_p->isColumnStored (columnIndex); }
1142 
1143 inline void Table::rename (const String& newName, TableOption option)
1144  { baseTabPtr_p->rename (newName, option); }
1145 inline void Table::deepCopy (const String& newName,
1146  const Record& dataManagerInfo,
1147  TableOption option,
1148  Bool valueCopy,
1150  Bool noRows) const
1151  { baseTabPtr_p->deepCopy (newName, dataManagerInfo, StorageOption(),
1152  option, valueCopy,
1153  endianFormat, noRows); }
1154 inline void Table::deepCopy (const String& newName,
1155  const Record& dataManagerInfo,
1156  const StorageOption& stopt,
1157  TableOption option,
1158  Bool valueCopy,
1160  Bool noRows) const
1161  { baseTabPtr_p->deepCopy (newName, dataManagerInfo, stopt,
1162  option, valueCopy,
1163  endianFormat, noRows); }
1165  { baseTabPtr_p->markForDelete (True, ""); }
1167  { baseTabPtr_p->unmarkForDelete(True, ""); }
1169  { return baseTabPtr_p->isMarkedForDelete(); }
1170 
1171 inline rownr_t Table::nrow() const
1172  { return baseTabPtr_p->nrow(); }
1173 inline BaseTable* Table::baseTablePtr() const
1174  { return baseTabPtr_p; }
1175 inline const TableDesc& Table::tableDesc() const
1176  { return baseTabPtr_p->tableDesc(); }
1177 inline const TableRecord& Table::keywordSet() const
1178  { return baseTabPtr_p->keywordSet(); }
1179 
1180 inline const TableInfo& Table::tableInfo() const
1181  { return baseTabPtr_p->tableInfo(); }
1183  { return baseTabPtr_p->tableInfo(); }
1184 inline void Table::flushTableInfo() const
1185  { baseTabPtr_p->flushTableInfo(); }
1186 
1187 inline const String& Table::tableName() const
1188  { return baseTabPtr_p->tableName(); }
1190  { return TableType(baseTabPtr_p->tableType()); }
1191 inline int Table::tableOption() const
1192  { return baseTabPtr_p->tableOption(); }
1193 
1194 inline Bool Table::canAddRow() const
1195  { return baseTabPtr_p->canAddRow(); }
1197  { return baseTabPtr_p->canRemoveRow(); }
1198 inline Bool Table::canRemoveColumn (const Vector<String>& columnNames) const
1199  { return baseTabPtr_p->canRemoveColumn (columnNames); }
1200 inline Bool Table::canRenameColumn (const String& columnName) const
1201  { return baseTabPtr_p->canRenameColumn (columnName); }
1202 
1203 inline void Table::addRow (rownr_t nrrow, Bool initialize)
1204  { baseTabPtr_p->addRow (nrrow, initialize); }
1205 inline void Table::removeRow (rownr_t rownr)
1206  { baseTabPtr_p->removeRow (rownr); }
1207 inline void Table::removeRow (const RowNumbers& rownrs)
1208  { baseTabPtr_p->removeRow (rownrs); }
1209 inline void Table::addColumn (const ColumnDesc& columnDesc, Bool addToParent)
1210  { baseTabPtr_p->addColumn (columnDesc, addToParent); }
1211 inline void Table::addColumn (const ColumnDesc& columnDesc,
1212  const String& dataManager, Bool byName,
1213  Bool addToParent)
1214  { baseTabPtr_p->addColumn (columnDesc, dataManager, byName, addToParent); }
1215 inline void Table::addColumn (const ColumnDesc& columnDesc,
1216  const DataManager& dataManager, Bool addToParent)
1217  { baseTabPtr_p->addColumn (columnDesc, dataManager, addToParent); }
1219  const DataManager& dataManager, Bool addToParent)
1220  { baseTabPtr_p->addColumn (tableDesc, dataManager, addToParent); }
1222  const Record& dataManagerInfo, Bool addToParent) { baseTabPtr_p->addColumns (tableDesc, dataManagerInfo, addToParent); }
1223 inline void Table::removeColumn (const Vector<String>& columnNames)
1224  { baseTabPtr_p->removeColumn (columnNames); }
1225 inline void Table::renameColumn (const String& newName, const String& oldName)
1226  { baseTabPtr_p->renameColumn (newName, oldName); }
1227 inline void Table::renameHypercolumn (const String& newName, const String& oldName)
1228  { baseTabPtr_p->renameHypercolumn (newName, oldName); }
1229 
1231  Bool byColumn) const
1232 {
1233  return baseTabPtr_p->findDataManager (name, byColumn);
1234 }
1235 
1236 inline void Table::showStructure (std::ostream& os,
1237  Bool showDataMans,
1238  Bool showColumns,
1239  Bool showSubTables,
1240  Bool sortColumns,
1241  Bool cOrder) const
1242  { baseTabPtr_p->showStructure (os, showDataMans, showColumns,
1243  showSubTables, sortColumns, cOrder); }
1244 
1245 
1246 
1247 } //# NAMESPACE CASACORE - END
1248 
1249 #endif
void markForDelete()
Mark the table for delete.
Definition: Table.h:1164
Table & operator=(const Table &)
Assignment (reference semantics).
DataManager * findDataManager(const String &name, Bool byColumn=False) const
Find the data manager with the given name or for the given column name.
Definition: Table.h:1230
A 1-D Specialization of the Array class.
Definition: ArrayFwd.h:9
int Int
Definition: aipstype.h:50
void removeColumn(const String &columnName)
Remove columns.
void renameColumn(const String &newName, const String &oldName)
Rename a column.
Definition: Table.h:1225
LockOption
Define the possible table locking options.
Definition: TableLock.h:81
Create a new table - define shapes, data managers, etc.
Definition: SetupNewTab.h:340
friend AipsIO & operator>>(AipsIO &, Table &)
Read a table from AipsIO (for TypedKeywords&lt;Table&gt;).
EndianFormat
Define the possible endian formats in which table data can be stored.
Definition: Table.h:196
Table()
Create a null Table object (i.e.
Class defining a plain regular table.
Definition: PlainTable.h:87
static Vector< String > getLockedTables(FileLocker::LockType=FileLocker::Read, int lockOption=-1)
Get the names of tables locked in this process.
Main interface class to a read/write table.
Definition: Table.h:157
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
new table, which gets marked for delete
Definition: Table.h:180
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
int tableOption() const
Get the table option.
Definition: Table.h:1191
rownr_t nrow() const
Get the number of rows.
Definition: Table.h:1171
Bool canAddRow() const
Test if it is possible to add a row to this table.
Definition: Table.h:1194
Handle class for a table column expression tree.
Definition: ExprNode.h:156
Class for a table held in memory.
Definition: MemoryTable.h:82
Table project(const Block< String > &columnNames) const
Project the given columns (i.e.
Bool isMarkedForDelete() const
Test if the table is marked for delete.
Definition: Table.h:1168
void showKeywords(std::ostream &, Bool showSubTables=False, Bool showTabKey=True, Bool showColKey=False, Int maxVal=25) const
Show the table and/or column keywords, possibly also of all subtables.
Envelope class for the description of a table column.
Definition: ColumnDesc.h:132
Table::EndianFormat endianFormat() const
Get the endian format in which the table is stored.
Iterate through a Table.
Definition: TableIter.h:117
static Vector< String > nonWritableFiles(const String &tableName)
Find the non-writable files in a table.
Bool isColumnWritable(const String &columnName) const
Test if the given column is writable.
Definition: Table.h:1133
store table data in big endian (e.g.
Definition: Table.h:198
void throwIfNull() const
Throw an exception if the object is null, i.e.
TableType tableType() const
Get the table type.
Definition: Table.h:1189
Abstract base class for a node in a table column expression tree.
Definition: ExprNodeRep.h:157
void ScratchCallback(const String &name, Bool isScratch, const String &oldName)
Define the signature of the function being called when the state of a scratch table changes (i...
Definition: Table.h:218
Bool isWritable() const
Test if this table is opened as writable.
Definition: Table.h:1131
Table operator-(const Table &) const
Subtract another table.
void removeRow(rownr_t rownr)
Remove the given row(s).
Definition: Table.h:1205
const String & tableName() const
Get the table name.
Definition: Table.h:1187
virtual ~Table()
The destructor flushes (i.e.
void addRow(rownr_t nrrow=1, Bool initialize=False)
Add one or more rows at the end of the table.
Definition: Table.h:1203
rownr_t getLayout(TableDesc &desc, const String &tableName)
Return the layout of a table (i.e.
void showStructure(std::ostream &, Bool showDataMans=True, Bool showColumns=True, Bool showSubTables=False, Bool sortColumns=False, Bool cOrder=False) const
Show the structure of the table.
Definition: Table.h:1236
void rename(const String &newName, TableOption)
Rename the table and all its subtables.
Definition: Table.h:1143
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
void getTableKeyword(AipsIO &, Bool openWritable)
Read a table from AipsIO (for TableKeywords).
create table (may not exist)
Definition: Table.h:178
void renameHypercolumn(const String &newName, const String &oldName)
Definition: Table.h:1227
Table operator()(const TableExprNode &, rownr_t maxRow=0, rownr_t offset=0) const
Select rows from a table using an select expression consisting of TableExprNode objects.
update existing table
Definition: Table.h:182
TableDesc actualTableDesc() const
Bool isMultiUsed(Bool checkSubTables=False) const
Is the table used (i.e.
Definition: Table.h:1108
Memory related information and utilities. use visibility=export&gt;
Definition: Memory.h:110
Table operator^(const Table &) const
Xor with another table.
Referenced counted pointer for constant data.
Definition: CountedPtr.h:80
Abstract base class for tables.
Definition: BaseTable.h:103
Class for a table as a view of another table.
Definition: RefTable.h:104
Acquire a read lock.
Definition: FileLocker.h:97
TableExprNode nodeRownr(rownr_t origin=0) const
Create a TableExprNode object for the rownumber function.
Table openTable(const String &tableName, Table::TableOption=Table::Old, const TSMOption &=TSMOption())
Try to open a table.
void resync()
Resynchronize the Table object with the table file.
Definition: Table.h:1103
existing table
Definition: Table.h:174
Acquire a write lock.
Definition: FileLocker.h:99
plain table (stored on disk)
Definition: Table.h:190
RowNumbers rowNumbers() const
Get a vector of row numbers in the root table of rows in this table.
friend AipsIO & operator<<(AipsIO &, const Table &)
Write a table to AipsIO (for TypedKeywords&lt;Table&gt;).
Record dataManagerInfo() const
Return all data managers used and the columns served by them.
void unmarkForDelete()
Unmark the table for delete.
Definition: Table.h:1166
Options for the Tiled Storage Manager Access.
Definition: TSMOption.h:116
void showKeywordSets(std::ostream &, Bool showTabKey, Bool showColKey, Int maxVal) const
Show the table and/or column keywords of this table.
const TableLock & lockOptions() const
Get the locking options.
Definition: Table.h:1110
TableExprNode keyCol(const String &name, const Vector< String > &fieldNames) const
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
Table sort(const String &columnName, int=Sort::Ascending, int=Sort::ParSort) const
Sort a table on one or more columns of scalars.
TableExprNode key(const String &keywordName) const
Create a TableExprNode object for a column or for a keyword in the table keyword set...
Bool lock(FileLocker::LockType=FileLocker::Write, uInt nattempts=0)
Try to lock the table for read or write access (default is write).
Definition: Table.h:1112
TableRecord & rwKeywordSet()
Get read/write access to the table keyword set.
Read/write access to a table column.
Definition: TableColumn.h:98
Table type, subtype and further info.
Definition: TableInfo.h:130
static Bool isOpened(const String &tableName)
Is the table used (i.e.
const Bool False
Definition: aipstype.h:44
Class to hold table lock options.
Definition: TableLock.h:68
TableExprNode col(const String &columnName) const
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:185
A templated N-D Array class with zero origin. Array&lt;T, Alloc&gt; is a templated, N-dimensional, Array class. The origin is zero, but by default indices are zero-based. This Array class is the base class for the Vector, Matrix, and Cube subclasses.
Definition: Array.h:156
static uInt nAutoLocks()
Determine the number of locked tables opened with the AutoLock option (Locked table means locked for ...
Bool canRemoveRow() const
Test if it is possible to remove a row from this table.
Definition: Table.h:1196
delete table
Definition: Table.h:184
static String fileName(const String &tableName)
Make the table file name.
simple 1-D array
Definition: Allocator.h:210
void copy(const String &newName, TableOption, Bool noRows=False) const
Copy the table and all its subtables.
const TableDesc & tableDesc() const
Get the table description.
Definition: Table.h:1175
Bool hasLock(FileLocker::LockType=FileLocker::Write) const
Has this process the read or write lock, thus can the table be read or written safely?
Definition: Table.h:1121
uInt64 rownr_t
Define the type of a row number in a table.
Definition: aipsxtype.h:46
Table operator!() const
Take complement.
static Bool isNativeDataType(DataType dtype)
Test if the given data type is native to the table system.
Bool isNull() const
Test if the object is null, i.e.
Definition: Table.h:477
Bool isSameRoot(const Table &other) const
Is the root table of this table the same as that of the other one?
Definition: Table.h:1096
TableExprNode nodeRandom() const
Create a TableExprNode object for the rand function.
Table operator&(const Table &) const
Do logical operations on a table.
Base class for the Data Manager Accessor classes.
Abstract base class for a data manager.
Definition: DataManager.h:220
const TableRecord & keywordSet() const
Get readonly access to the table keyword set.
Definition: Table.h:1177
Bool canRemoveColumn(const String &columnName) const
Test if columns can be removed.
const StorageOption & storageOption() const
Get the storage option used for the table.
Definition: Table.h:1106
static ScratchCallback * setScratchCallback(ScratchCallback *)
Set the pointer to the ScratchCallback function.
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
Block< String > getPartNames(Bool recursive=False) const
Get the names of the tables this table consists of.
static void relinquishAutoLocks(Bool all=False)
Unlock locked tables opened with the AutoLock option.
Define the structure of a Casacore table.
Definition: TableDesc.h:190
Bool isRootTable() const
Test if this table is the root table (ie.
Definition: Table.h:1128
const TableInfo & tableInfo() const
Get access to the TableInfo object.
Definition: Table.h:1180
Bool canDeleteTable(const String &tableName, Bool checkSubTables=False)
Can the table be deleted? If true, function deleteTable can safely be called.
LockType
Define the possible lock types.
Definition: FileLocker.h:95
TableType
Define the possible table types.
Definition: Table.h:188
create table
Definition: Table.h:176
Class to view a concatenation of tables as a single table.
Definition: ConcatTable.h:118
void reopenRW()
Try to reopen the table for read/write access.
Definition: Table.h:1099
void closeSubTables() const
Close all open subtables.
Table copyToMemoryTable(const String &name, Bool noRows=False) const
Make a copy of a table to a MemoryTable object.
store data in the endian format of the machine used
Definition: Table.h:202
Bool isColumnStored(const String &columnName) const
Test if the given column is stored (otherwise it is virtual).
Definition: Table.h:1138
LatticeExprNode all(const LatticeExprNode &expr)
Table operator|(const Table &) const
Union with another table.
void addColumn(const ColumnDesc &columnDesc, Bool addToParent=True)
Add a column to the table.
Definition: Table.h:1209
Bool hasDataChanged()
Determine if column or keyword table data have changed (or is being changed) since the last time this...
const Bool True
Definition: aipstype.h:43
Bool canRenameColumn(const String &columnName) const
Test if a column can be renamed.
Definition: Table.h:1200
void deepCopy(const String &newName, TableOption, Bool valueCopy=False, EndianFormat=AipsrcEndian, Bool noRows=False) const
void flush(Bool fsync=False, Bool recursive=False)
Flush the table, i.e.
Definition: Table.h:1101
void flushTableInfo() const
Write the TableInfo object.
Definition: Table.h:1184
unsigned int uInt
Definition: aipstype.h:51
store table data in little endian (e.g.
Definition: Table.h:200
TableOption
Define the possible options how a table can be opened.
Definition: Table.h:172
void unlock()
Unlock the table.
Definition: Table.h:1119
static Bool isReadable(const String &tableName, bool throwIf=False)
Test if a table with the given name exists and is readable.