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