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