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
183 Delete
184 };
185
186 // Define the possible table types.
188 // plain table (stored on disk)
190 // table held in memory
191 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 // Get the endian format in which the table is stored.
395
396 // Get the storage option used for the table.
397 const StorageOption& storageOption() const;
398
399 // Is the table used (i.e. open) in this process.
400 static Bool isOpened (const String& tableName);
401
402 // Is the table used (i.e. open) in another process.
403 // If <src>checkSubTables</src> is set, it is also checked if
404 // a subtable is used in another process.
405 Bool isMultiUsed (Bool checkSubTables=False) const;
406
407 // Get the locking options.
408 const TableLock& lockOptions() const;
409
410 // Has this process the read or write lock, thus can the table
411 // be read or written safely?
412 // <group>
414 Bool hasLock (Bool write) const;
415 // </group>
416
417 // Try to lock the table for read or write access (default is write).
418 // The number of attempts (default = forever) can be specified when
419 // acquiring the lock does not succeed immediately. If nattempts>1,
420 // the system waits 1 second between each attempt, so nattempts
421 // is more or less equal to a wait period in seconds.
422 // The return value is false if acquiring the lock failed.
423 // If <src>PermanentLocking</src> is in effect, a lock is already
424 // present, so nothing will be done.
425 // <group>
427 Bool lock (Bool write, uInt nattempts = 0);
428 // </group>
429
430 // Unlock the table. This will also synchronize the table data,
431 // thus force the data to be written to disk.
432 // If <src>PermanentLocking</src> is in effect, nothing will be done.
433 void unlock();
434
435 // Determine the number of locked tables opened with the AutoLock option
436 // (Locked table means locked for read and/or write).
437 static uInt nAutoLocks();
438
439 // Unlock locked tables opened with the AutoLock option.
440 // If <src>all=True</src> all such tables will be unlocked.
441 // If <src>all=False</src> only tables requested by another process
442 // will be unlocked.
444
445 // Get the names of tables locked in this process.
446 // By default all locked tables are given (note that a write lock
447 // implies a read lock), but it is possible to select on lock type
448 // FileLocker::Write and on option (TableLock::AutoLocking,
449 // TableLock::ReadLocking, or TableLock::PermanentLocking).
451 int lockOption=-1);
452
453 // Determine if column or keyword table data have changed
454 // (or is being changed) since the last time this function was called.
456
457 // Flush the table, i.e. write out the buffers. If <src>sync=True</src>,
458 // it is ensured that all data are physically written to disk.
459 // Nothing will be done if the table is not writable.
460 // At any time a flush can be executed, even if the table is marked
461 // for delete.
462 // If the table is marked for delete, the destructor will remove
463 // files written by intermediate flushes.
464 // Note that if necessary the destructor will do an implicit flush,
465 // unless it is executed due to an exception.
466 // <br>If <src>fsync=True</src> the file contents are fsync-ed to disk,
467 // thus ensured that the system buffers are actually written to disk.
468 // <br>If <src>recursive=True</src> all subtables are flushed too.
469 void flush (Bool fsync=False, Bool recursive=False);
470
471 // Resynchronize the Table object with the table file.
472 // This function is only useful if no read-locking is used, ie.
473 // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
474 // In that cases the table system does not acquire a read-lock, thus
475 // does not synchronize itself automatically.
476 void resync();
477
478 // Test if the object is null, i.e. does not reference a proper table.
479 // This is the case if the default constructor is used.
480 Bool isNull() const
481 { return (baseTabPtr_p == 0 ? True : baseTabPtr_p->isNull()); }
482
483 // Throw an exception if the object is null, i.e.
484 // if function isNull() is True.
485 void throwIfNull() const;
486
487 // Test if the given data type is native to the table system.
488 // If not, a virtual column engine is needed to store data with that type.
489 // With the function DataType::whatType it can be used in a templated
490 // function like:
491 // <srcblock>
492 // if (Table::isNativeDataType (whatType(static_cast<T*>(0)))) {
493 // </srcblock>
494 static Bool isNativeDataType (DataType dtype);
495
496 // Make the table file name.
498
499 // Test if a table with the given name exists and is readable.
500 // If not, an exception is thrown if <src>throwIf==True</src>.
501 static Bool isReadable (const String& tableName, bool throwIf=False);
502
503 // Show the structure of the table.
504 // It shows the columns (with types), the data managers, and the subtables.
505 // Optionally the columns can be sorted alphabetically.
506 void showStructure (std::ostream&,
507 Bool showDataMans=True,
508 Bool showColumns=True,
509 Bool showSubTables=False,
510 Bool sortColumns=False,
511 Bool cOrder=False) const;
512
513 // Show the table and/or column keywords, possibly also of all subtables.
514 // Maximum <src>maxVal</src> values of Arrays will be shown.
515 void showKeywords (std::ostream&,
516 Bool showSubTables=False,
517 Bool showTabKey=True,
518 Bool showColKey=False,
519 Int maxVal=25) const;
520
521 // Show the table and/or column keywords of this table.
522 // Maximum <src>maxVal</src> values of Arrays will be shown.
523 void showKeywordSets (std::ostream&,
524 Bool showTabKey, Bool showColKey,
525 Int maxVal) const;
526
527 // Test if a table with the given name exists and is writable.
528 static Bool isWritable (const String& tableName, bool throwIf=False);
529
530 // Find the non-writable files in a table.
532
533 // Test if this table is the root table (ie. if it is not the subset
534 // of another table).
535 Bool isRootTable() const;
536
537 // Test if this table is opened as writable.
538 Bool isWritable() const;
539
540 // Test if the given column is writable.
541 // <group>
542 Bool isColumnWritable (const String& columnName) const;
543 Bool isColumnWritable (uInt columnIndex) const;
544 // </group>
545
546 // Test if the given column is stored (otherwise it is virtual).
547 // <group>
548 Bool isColumnStored (const String& columnName) const;
549 Bool isColumnStored (uInt columnIndex) const;
550 // </group>
551
552 // Get readonly access to the table keyword set.
553 // If UserLocking is used, it will automatically acquire
554 // and release a read lock if the table is not locked.
555 const TableRecord& keywordSet() const;
556
557 // Get read/write access to the table keyword set.
558 // This requires that the table is locked (or it gets locked
559 // if using AutoLocking mode).
561
562 // Get access to the TableInfo object.
563 // <group>
564 const TableInfo& tableInfo() const;
566 // </group>
567
568 // Write the TableInfo object.
569 // Usually this is not necessary, because it is done automatically
570 // when the table gets written (by table destructor or flush function).
571 // This function is only useful if the table info has to be written
572 // before the table gets written (e.g. when another process reads
573 // the table while it gets filled).
574 void flushTableInfo() const;
575
576 // Get the table description.
577 // This can be used to get nr of columns, etc..
578 // <src>tableDesc()</src> gives the table description used when
579 // constructing the table, while <src>actualTableDesc()</src> gives the
580 // actual description, thus with the actual data managers used.
581 // <group>
582 const TableDesc& tableDesc() const;
584 // </group>
585
586 // Return all data managers used and the columns served by them.
587 // The info is returned in a record. It contains a subrecord per
588 // data manager. Each subrecord contains the following fields:
589 // <dl>
590 // <dt> TYPE
591 // <dd> a string giving the type of the data manager.
592 // <dt> NAME
593 // <dd> a string giving the name of the data manager.
594 // <dt> COLUMNS
595 // <dd> a vector of strings giving the columns served by the data manager.
596 // </dl>
597 // Data managers may return some additional fields (e.g. BUCKETSIZE).
599
600 // Get the table name.
601 const String& tableName() const;
602
603 // Rename the table and all its subtables.
604 // The following options can be given:
605 // <dl>
606 // <dt> Table::Update
607 // <dd> A table with this name must already exists, which will be
608 // overwritten. When succesfully renamed, the table is unmarked
609 // for delete (if necessary).
610 // <dt> Table::New
611 // <dd> If a table with this name exists, it will be overwritten.
612 // When succesfully renamed, the table is unmarked
613 // for delete (if necessary).
614 // <dt> Table::NewNoReplace
615 // <dd> If a table with this name already exists, an exception
616 // is thrown. When succesfully renamed, the table
617 // is unmarked for delete (if necessary).
618 // <dt> Table::Scratch
619 // <dd> Same as Table::New, but followed by markForDelete().
620 // </dl>
621 // The scratchCallback function is called when needed.
622 void rename (const String& newName, TableOption);
623
624 // Copy the table and all its subtables.
625 // Especially for RefTables <src>copy</src> and <src>deepCopy</src> behave
626 // differently. <src>copy</src> makes a bitwise copy of the table, thus
627 // the result is still a RefTable. On the other hand <src>deepCopy</src>
628 // makes a physical copy of all referenced table rows and columns, thus
629 // the result is a PlainTable.
630 // <br>For PlainTables <src>deepCopy</src> is the same as <src>copy</src>
631 // unless <src>valueCopy==True</src> is given. In that case the values
632 // are copied which takes longer, but reorganizes the data files to get
633 // rid of gaps in the data. Also if specific DataManager info is given
634 // or if no rows have to be copied, a deep copy is made.
635 // <br>The following options can be given:
636 // <dl>
637 // <dt> Table::New
638 // <dd> If a table with this name exists, it will be overwritten.
639 // <dt> Table::NewNoReplace
640 // <dd> If a table with this name already exists, an exception
641 // is thrown.
642 // <dt> Table::Scratch
643 // <dd> Same as Table::New, but followed by markForDelete().
644 // </dl>
645 // <group>
646 // The new table gets the given endian format. Note that the endian option
647 // is only used if a true deep copy of a table is made.
648 // <br>When making a deep copy, it is possible to specify the data managers
649 // using the <src>dataManagerInfo</src> argument.
650 // See <src>getDataManagerInfo</src> for more info about that record.
651 // <br>If <src>noRows=True</src> no rows are copied. Also no rows are
652 // copied in all subtables. It is useful if one wants to make a copy
653 // of only the Table structure.
654 void copy (const String& newName, TableOption, Bool noRows=False) const;
655 void deepCopy (const String& newName,
656 TableOption, Bool valueCopy=False,
658 Bool noRows=False) const;
659 void deepCopy (const String& newName, const Record& dataManagerInfo,
660 TableOption, Bool valueCopy=False,
662 Bool noRows=False) const;
663 void deepCopy (const String& newName, const Record& dataManagerInfo,
664 const StorageOption&,
665 TableOption, Bool valueCopy=False,
667 Bool noRows=False) const;
668 // </group>
669
670 // Make a copy of a table to a MemoryTable object.
671 // Use the given name for the memory table.
672 Table copyToMemoryTable (const String& name, Bool noRows=False) const;
673
674 // Get the table type.
675 TableType tableType() const;
676
677 // Get the table option.
678 int tableOption() const;
679
680 // Mark the table for delete.
681 // This means that the underlying table gets deleted when it is
682 // actually destructed.
683 // The scratchCallback function is called when needed.
684 void markForDelete();
685
686 // Unmark the table for delete.
687 // This means the underlying table does not get deleted when destructed.
688 // The scratchCallback function is called when needed.
689 void unmarkForDelete();
690
691 // Test if the table is marked for delete.
692 Bool isMarkedForDelete() const;
693
694 // Get the number of rows.
695 // It is unsynchronized meaning that it will not check if another
696 // process updated the table, thus possible increased the number of rows.
697 // If one wants to take that into account, he should acquire a
698 // read-lock (using the lock function) before using nrow().
699 rownr_t nrow() const;
700
701 // Test if it is possible to add a row to this table.
702 // It is possible if all storage managers used for the table
703 // support it.
704 Bool canAddRow() const;
705
706 // Add one or more rows at the end of the table.
707 // This will fail for tables not supporting addition of rows.
708 // Optionally the rows can be initialized with the default
709 // values as defined in the column descriptions.
710 void addRow (rownr_t nrrow = 1, Bool initialize = False);
711
712 // Test if it is possible to remove a row from this table.
713 // It is possible if all storage managers used for the table
714 // support it.
715 Bool canRemoveRow() const;
716
717 // Remove the given row(s).
718 // The latter form can be useful with the select and rowNumbers functions
719 // to remove some selected rows from the table.
720 // <br>It will fail for tables not supporting removal of rows.
721 // <note role=warning>
722 // The following code fragments do NOT have the same result:
723 // <srcblock>
724 // tab.removeRow (10); // remove row 10
725 // tab.removeRow (20); // remove row 20, which was 21
726 // Vector<rownr_t> vec(2);
727 // vec(0) = 10;
728 // vec(1) = 20;
729 // tab.removeRow (vec); // remove row 10 and 20
730 // </srcblock>
731 // because in the first fragment removing row 10 turns the former
732 // row 21 into row 20.
733 // </note>
734 // <group>
735 void removeRow (rownr_t rownr);
736 void removeRow (const RowNumbers& rownrs);
737 // </group>
738
739 // Create a TableExprNode object for a column or for a keyword
740 // in the table keyword set.
741 // This can be used in selecting rows from a table using
742 // <src>operator()</src> described below.
743 // <br>The functions taking the fieldNames vector are meant for
744 // the cases where the keyword or column contains records.
745 // The fieldNames indicate which field to take from that record
746 // (which can be a record again, etc.).
747 // <group name=keycol>
748 TableExprNode key (const String& keywordName) const;
749 TableExprNode key (const Vector<String>& fieldNames) const;
750 TableExprNode col (const String& columnName) const;
751 TableExprNode col (const String& columnName,
752 const Vector<String>& fieldNames) const;
753 // </group>
754
755 // Create a TableExprNode object for the rownumber function.
756 // 'origin' Indicates which rownumber is the first.
757 // C++ uses origin = 0 (default)
758 // Glish and TaQL both use origin = 1
760
761 // Create a TableExprNode object for the rand function.
763
764 // Select rows from a table using an select expression consisting
765 // of TableExprNode objects.
766 // Basic TableExprNode objects can be created with the functions
767 // <linkto file="Table.h#keycol">key</linkto> and especially
768 // <linkto file="Table.h#keycol">col</linkto>.
769 // Composite TableExprNode objects, representing an expression,
770 // can be created by applying operations (like == and +)
771 // to the basic ones. This is described in class
772 // <linkto class="TableExprNode:description">TableExprNode</linkto>.
773 // For example:
774 // <srcblock>
775 // Table result = tab(tab.col("columnName") > 10);
776 // </srcblock>
777 // All rows for which the expression is true, will be selected and
778 // "stored" in the result.
779 // You need to include ExprNode.h for this purpose.
780 // <br>The first <src>offset</src> matching rows will be skipped.
781 // <br>If <src>maxRow>0</src>, the selection process will stop
782 // when <src>maxRow</src> rows are selected.
783 // <br>The TableExprNode argument can be empty (null) meaning that only
784 // the <src>maxRow/offset</src> arguments are taken into account.
785 Table operator() (const TableExprNode&, rownr_t maxRow=0, rownr_t offset=0) const;
786
787 // Select rows using a vector of row numbers.
788 // This can, for instance, be used to select the same rows as
789 // were selected in another table (using the rowNumbers function).
790 // <srcblock>
791 // Table result = thisTable (otherTable.rowNumbers());
792 // </srcblock>
793 Table operator() (const RowNumbers& rownrs) const;
794
795 // Select rows using a mask block.
796 // The length of the block must match the number of rows in the table.
797 // If an element in the mask is True, the corresponding row will be
798 // selected.
800
801 // Project the given columns (i.e. select the columns).
802 Table project (const Block<String>& columnNames) const;
803
804 //# Virtually concatenate all tables in this column.
805 //# The column cells must contain tables with the same description.
806//#// Table concatenate (const String& columnName) const;
807
808 // Do logical operations on a table.
809 // It can be used for row-selected or projected (i.e. column-selected)
810 // tables. The tables involved must come from the same root table or
811 // be the root table themselves.
812 // <group>
813 // Intersection with another table.
814 Table operator& (const Table&) const;
815 // Union with another table.
816 Table operator| (const Table&) const;
817 // Subtract another table.
818 Table operator- (const Table&) const;
819 // Xor with another table.
820 Table operator^ (const Table&) const;
821 // Take complement.
823 // </group>
824
825 // Sort a table on one or more columns of scalars.
826 // Per column a compare function can be provided. By default
827 // the standard compare function defined in Compare.h will be used.
828 // Default sort order is ascending.
829 // Default sorting algorithm is the parallel sort.
830 // <group>
831 // Sort on one column.
832 Table sort (const String& columnName,
833 int = Sort::Ascending,
834 int = Sort::ParSort) const;
835 // Sort on multiple columns. The principal column has to be the
836 // first element in the Block of column names.
837 Table sort (const Block<String>& columnNames,
838 int = Sort::Ascending,
839 int = Sort::ParSort) const;
840 // Sort on multiple columns. The principal column has to be the
841 // first element in the Block of column names.
842 // The order can be given per column.
843 Table sort (const Block<String>& columnNames,
844 const Block<Int>& sortOrders,
845 int = Sort::ParSort) const;
846 // Sort on multiple columns. The principal column has to be the
847 // first element in the Block of column names.
848 // The order can be given per column.
849 // Provide some special comparisons via std::shared_ptrs of compare objects.
850 // A null std::shared_ptr means using the standard compare object
851 // from class <linkto class="ObjCompare:description">ObjCompare</linkto>.
852 Table sort (const Block<String>& columnNames,
853 const Block<std::shared_ptr<BaseCompare>>& compareObjects,
854 const Block<Int>& sortOrders,
855 int = Sort::ParSort) const;
856 // </group>
857
858 // Get a vector of row numbers in the root table of rows in this table.
859 // In case the table is a subset of the root table, this tells which
860 // rows of the root table are part of the subset.
861 // In case the table is the root table itself, the result is a vector
862 // containing the row numbers 0 .. #rows-1.
863 // <br>Note that in general it is better to use the next
864 // <src>rowNumbers(Table)</src> function.
866
867 // Get a vector of row numbers in that table of rows in this table.
868 // In case the table is a subset of that table, this tells which
869 // rows of that table are part of the subset.
870 // In case the table is that table itself, the result is a vector
871 // containing the row numbers 0 .. #rows-1.
872 // <note role=caution>This function is in principle meant for cases
873 // where this table is a subset of that table. However, it can be used
874 // for any table. In that case the returned vector contains a very high
875 // number (max_uint) for rows in this table not part of that table.
876 // In that way they are invalid if used elsewhere.
877 // <br>In the general case creating the row number vector can be slowish,
878 // because it has to do two mappings. However, if this table is a subset
879 // of that table and if they are in the same order, the mapping can be done
880 // in a more efficient way. The argument <src>tryFast</src> can be used to
881 // tell the function to try a fast conversion first. If that cannot be done,
882 // it reverts to the slower way at the expense of an unsuccessful fast
883 // attempt.
884 // </note>
885 // <srcblock>
886 // Table tab("somename");
887 // Table subset = tab(some_select_expression);
888 // RowNumbers rownrs = subset.rowNumbers(tab);
889 // </srcblock>
890 // Note that one cannot be sure that table "somename" is the root
891 // (i.e. original) table. It may also be a subset of another table.
892 // In the latter case doing
893 // <br> <src> RowNumbers rownrs = subset.rowNumbers()</src>
894 // does not give the row numbers in <src>tab</src>, but in the root table
895 // (which is probably not what you want).
896 RowNumbers rowNumbers (const Table& that, Bool tryFast=False) const;
897
898 // Add a column to the table.
899 // The data manager used for the column depend on the function used.
900 // Exceptions are thrown if the column already exist or if the
901 // table is not writable.
902 // <br>If this table is a reference table (result of selection) and if
903 // <src>addToParent=True</src> the column is also added to the parent
904 // table.
905 // <group>
906 // Use the first appropriate existing storage manager.
907 // If there is none, a data manager is created using the default
908 // data manager in the column description.
909 void addColumn (const ColumnDesc& columnDesc,
910 Bool addToParent = True);
911 // Use an existing data manager with the given name or type.
912 // If the flag byName is True, a name is given, otherwise a type.
913 // If a name is given, an exception is thrown if the data manager is
914 // unknown or does not allow addition of columns.
915 // If a type is given, a storage manager of the given type will be
916 // created if there is no such data manager allowing addition of rows.
917 void addColumn (const ColumnDesc& columnDesc,
918 const String& dataManager, Bool byName,
919 Bool addToParent = True);
920 // Use the given data manager (which is a new one).
921 void addColumn (const ColumnDesc& columnDesc,
922 const DataManager& dataManager,
923 Bool addToParent = True);
924 // </group>
925
926 // Add a bunch of columns using the given new data manager.
927 // All columns and possible hypercolumn definitions in the given table
928 // description will be copied and added to the table.
929 // This can be used in case of specific data managers which need to
930 // be created with more than one column (e.g. the tiled hypercube
931 // storage managers).
932 // <br>The data manager can be given directly or by means of a record
933 // describing the data manager in the standard way with the fields
934 // TYPE, NAME, and SPEC. The record can contain those fields itself
935 // or it can contain a single subrecord with those fields.
936 // <br>If this table is a reference table (result of selection) and if
937 // <src>addToParent=True</src> the columns are also added to the parent
938 // table.
939 // <group>
940 void addColumn (const TableDesc& tableDesc,
941 const DataManager& dataManager,
942 Bool addToParent = True);
943 void addColumn (const TableDesc& tableDesc,
944 const Record& dataManagerInfo,
945 Bool addToParent = True);
946 // </group>
947
948 // Test if columns can be removed.
949 // It can if the columns exist and if the data manager it is using
950 // supports removal of columns or if all columns from a data manager
951 // would be removed..
952 // <br>You can always remove columns from a reference table.
953 // <group>
954 Bool canRemoveColumn (const String& columnName) const;
955 Bool canRemoveColumn (const Vector<String>& columnNames) const;
956 // </group>
957
958 // Remove columns.
959 // <br>When removing columns from a reference table, the columns
960 // are NOT removed from the underlying table.
961 // <group>
962 void removeColumn (const String& columnName);
963 void removeColumn (const Vector<String>& columnName);
964 // </group>
965
966 // Test if a column can be renamed.
967 Bool canRenameColumn (const String& columnName) const;
968
969 // Rename a column.
970 // An exception is thrown if the old name does not exist or
971 // if the name already exists.
972 // <note role=caution>
973 // Renaming a column should be done with care, because other
974 // columns may be referring this column. Also a hypercolumn definition
975 // might be using the old name.
976 // Finally if may also invalidate persistent selections of a table,
977 // because the reference table cannot find the column anymore.
978 // </note>
979 void renameColumn (const String& newName, const String& oldName);
980
981 void renameHypercolumn (const String& newName, const String& oldName);
982
983 // Write a table to AipsIO (for <src>TypedKeywords<Table></src>).
984 // This will only write the table name.
985 friend AipsIO& operator<< (AipsIO&, const Table&);
986
987 // Read a table from AipsIO (for <src>TypedKeywords<Table></src>).
988 // This will read the table name and open the table as writable
989 // if the table file is writable, otherwise as readonly.
991
992 // Read a table from AipsIO (for <src>TableKeywords</src>).
993 // This will read the table name and open the table as writable
994 // if the switch is set and if the table file is writable.
995 // otherwise it is opened as readonly.
996 void getTableKeyword (AipsIO&, Bool openWritable);
997
998 // Write a table to ostream (for <src>TypedKeywords<Table></src>).
999 // This only shows its name and number of columns and rows.
1000 friend ostream& operator<< (ostream&, const Table&);
1001
1002 // Find the data manager with the given name or for the given column name.
1003 DataManager* findDataManager (const String& name,
1004 Bool byColumn=False) const;
1005
1006 // Some deprecated functions for backward compatibility, now in TableUtil.h.
1007 // Use old way of indicating deprecate to avoid -Wc++14-extensions warnings.
1008 // <group>
1009 //# [[deprecated ("Now use TableUtil::openTable")]]
1010 static Table openTable (const String& tableName,
1012 const TSMOption& = TSMOption())
1013 __attribute__ ((deprecated ("Now use TableUtil::openTable")));
1014 //# [[deprecated ("Now use TableUtil::openTable")]]
1015 static Table openTable (const String& tableName,
1016 const TableLock& lockOptions,
1018 const TSMOption& = TSMOption())
1019 __attribute__ ((deprecated ("Now use TableUtil::openTable")));
1020 //# [[deprecated ("Now use TableUtil::canDeleteTable")]]
1021 static Bool canDeleteTable (const String& tableName,
1022 Bool checkSubTables=False)
1023 __attribute__ ((deprecated ("Now use TableUtil::canDeleteTable")));
1024 //# [[deprecated ("Now use TableUtil::canDeleteTable")]]
1025 static Bool canDeleteTable (String& message, const String& tableName,
1026 Bool checkSubTables=False)
1027 __attribute__ ((deprecated ("Now use TableUtil::canDeleteTable")));
1028 //# [[deprecated ("Now use TableUtil::deleteTable")]]
1029 static void deleteTable (const String& tableName,
1030 Bool checkSubTables=False)
1031 __attribute__ ((deprecated ("Now use TableUtil::deleteTable")));
1032 //# [[deprecated ("Now use TableUtil::getLayout")]]
1033 static rownr_t getLayout (TableDesc& desc, const String& tableName)
1034 __attribute__ ((deprecated ("Now use TableUtil::getLayout")));
1035 //# [[deprecated ("Now use TableUtil::tableInfo")]]
1036 static TableInfo tableInfo (const String& tableName)
1037 __attribute__ ((deprecated ("Now use TableUtil::tableInfo")));
1038 // </group>
1039
1040protected:
1041 // Shared pointer to count the references to the BaseTable object.
1042 // The shared pointer can be null, so it is not counted which is necessary for
1043 // the Table object in the DataManager. Otherwise mutual referencing would occur.
1044 // Note that the BaseTable object contains a weak_ptr to itself which is the
1045 // basis for all shared pointer counting.
1046 std::shared_ptr<BaseTable> countedTabPtr_p;
1047 // Pointer to BaseTable object which is always filled and always used.
1048 // The shared_ptr above is only for reference counting.
1049 BaseTable* baseTabPtr_p;
1050 // Counter of last call to hasDataChanged.
1051 uInt lastModCounter_p;
1052 // Pointer to the ScratchCallback function.
1053 static ScratchCallback* scratchCallback_p;
1054
1055
1056 // Construct a Table object from a pointer to BaseTable.
1057 // It is meant for internal Table objects, so the BaseTable is not counted.
1058 // Thus the internal shared_ptr is null.
1059 Table (BaseTable*);
1060
1061 // Construct a Table object from a shared pointer to BaseTable.
1062 Table (const std::shared_ptr<BaseTable>&);
1063
1064 // Open an existing table.
1065 void open (const String& name, const String& type, int tableOption,
1066 const TableLock& lockOptions, const TSMOption& tsmOpt);
1067
1068private:
1069 // Construct a BaseTable object from the table file.
1070 static std::shared_ptr<BaseTable> makeBaseTable
1071 (const String& name, const String& type, int tableOption,
1072 const TableLock& lockOptions, const TSMOption& tsmOpt,
1073 Bool addToCache, uInt locknr);
1074
1075 // Get the pointer to the underlying BaseTable.
1076 // This is needed for some friend classes.
1077 BaseTable* baseTablePtr() const;
1078
1079 // Initialize the BaseTable pointers in this Table object.
1080 void initBasePtr (BaseTable* ptr);
1081
1082 // Look in the cache if the table is already open.
1083 // If so, check if the table option matches.
1084 // If needed reopen the table for read/write and merge the lock options.
1085 BaseTable* lookCache (const String& name, int tableOption,
1086 const TableLock& tableInfo);
1087
1088 // Try if v1 is a subset of v2 and fill rows with its indices in v2.
1089 // Return False if not a proper subset.
1090 Bool fastRowNumbers (const Vector<rownr_t>& v1, const Vector<rownr_t>& v2,
1091 Vector<rownr_t>& rows) const;
1092
1093 // Show the info of the given columns.
1094 // Sort the columns if needed.
1095 void showColumnInfo (ostream& os, const TableDesc&, uInt maxNameLength,
1096 const Array<String>& columnNames, Bool sort) const;
1097};
1098
1099
1100
1101inline Bool Table::isSameRoot (const Table& other) const
1102 { return baseTabPtr_p->root() == other.baseTabPtr_p->root(); }
1103
1104inline void Table::reopenRW()
1105 { baseTabPtr_p->reopenRW(); }
1106inline void Table::flush (Bool fsync, Bool recursive)
1107 { baseTabPtr_p->flush (fsync, recursive); }
1108inline void Table::resync()
1109 { baseTabPtr_p->resync(); }
1110
1112 { return baseTabPtr_p->storageOption(); }
1113inline Bool Table::isMultiUsed(Bool checkSubTables) const
1114 { return baseTabPtr_p->isMultiUsed(checkSubTables); }
1115inline const TableLock& Table::lockOptions() const
1116 { return baseTabPtr_p->lockOptions(); }
1118 { return baseTabPtr_p->lock (type, nattempts); }
1119inline Bool Table::lock (Bool write, uInt nattempts)
1120{
1121 return baseTabPtr_p->lock (write ? FileLocker::Write : FileLocker::Read,
1122 nattempts);
1123}
1124inline void Table::unlock()
1125 { baseTabPtr_p->unlock(); }
1127 { return baseTabPtr_p->hasLock (type); }
1128inline Bool Table::hasLock (Bool write) const
1129{
1130 return baseTabPtr_p->hasLock (write ? FileLocker::Write : FileLocker::Read);
1131}
1132
1134 { return baseTabPtr_p == baseTabPtr_p->root(); }
1135
1137 { return baseTabPtr_p->isWritable(); }
1138inline Bool Table::isColumnWritable (const String& columnName) const
1139 { return baseTabPtr_p->isColumnWritable (columnName); }
1140inline Bool Table::isColumnWritable (uInt columnIndex) const
1141 { return baseTabPtr_p->isColumnWritable (columnIndex); }
1142
1143inline Bool Table::isColumnStored (const String& columnName) const
1144 { return baseTabPtr_p->isColumnStored (columnName); }
1145inline Bool Table::isColumnStored (uInt columnIndex) const
1146 { return baseTabPtr_p->isColumnStored (columnIndex); }
1147
1148inline void Table::rename (const String& newName, TableOption option)
1149 { baseTabPtr_p->rename (newName, option); }
1150inline void Table::deepCopy (const String& newName,
1151 const Record& dataManagerInfo,
1152 TableOption option,
1153 Bool valueCopy,
1155 Bool noRows) const
1156 { baseTabPtr_p->deepCopy (newName, dataManagerInfo, StorageOption(),
1157 option, valueCopy,
1158 endianFormat, noRows); }
1159inline void Table::deepCopy (const String& newName,
1160 const Record& dataManagerInfo,
1161 const StorageOption& stopt,
1162 TableOption option,
1163 Bool valueCopy,
1165 Bool noRows) const
1166 { baseTabPtr_p->deepCopy (newName, dataManagerInfo, stopt,
1167 option, valueCopy,
1168 endianFormat, noRows); }
1170 { baseTabPtr_p->markForDelete (True, ""); }
1172 { baseTabPtr_p->unmarkForDelete(True, ""); }
1174 { return baseTabPtr_p->isMarkedForDelete(); }
1175
1176inline rownr_t Table::nrow() const
1177 { return baseTabPtr_p->nrow(); }
1178inline BaseTable* Table::baseTablePtr() const
1179 { return baseTabPtr_p; }
1180inline const TableDesc& Table::tableDesc() const
1181 { return baseTabPtr_p->tableDesc(); }
1182inline const TableRecord& Table::keywordSet() const
1183 { return baseTabPtr_p->keywordSet(); }
1184
1185inline const TableInfo& Table::tableInfo() const
1186 { return baseTabPtr_p->tableInfo(); }
1188 { return baseTabPtr_p->tableInfo(); }
1189inline void Table::flushTableInfo() const
1190 { baseTabPtr_p->flushTableInfo(); }
1191
1192inline const String& Table::tableName() const
1193 { return baseTabPtr_p->tableName(); }
1195 { return TableType(baseTabPtr_p->tableType()); }
1196inline int Table::tableOption() const
1197 { return baseTabPtr_p->tableOption(); }
1198
1200 { return baseTabPtr_p->canAddRow(); }
1202 { return baseTabPtr_p->canRemoveRow(); }
1203inline Bool Table::canRemoveColumn (const Vector<String>& columnNames) const
1204 { return baseTabPtr_p->canRemoveColumn (columnNames); }
1205inline Bool Table::canRenameColumn (const String& columnName) const
1206 { return baseTabPtr_p->canRenameColumn (columnName); }
1207
1208inline void Table::addRow (rownr_t nrrow, Bool initialize)
1209 { baseTabPtr_p->addRow (nrrow, initialize); }
1210inline void Table::removeRow (rownr_t rownr)
1211 { baseTabPtr_p->removeRow (rownr); }
1212inline void Table::removeRow (const RowNumbers& rownrs)
1213 { baseTabPtr_p->removeRow (rownrs); }
1214inline void Table::addColumn (const ColumnDesc& columnDesc, Bool addToParent)
1215 { baseTabPtr_p->addColumn (columnDesc, addToParent); }
1216inline void Table::addColumn (const ColumnDesc& columnDesc,
1217 const String& dataManager, Bool byName,
1218 Bool addToParent)
1219 { baseTabPtr_p->addColumn (columnDesc, dataManager, byName, addToParent); }
1220inline void Table::addColumn (const ColumnDesc& columnDesc,
1221 const DataManager& dataManager, Bool addToParent)
1222 { baseTabPtr_p->addColumn (columnDesc, dataManager, addToParent); }
1224 const DataManager& dataManager, Bool addToParent)
1225 { baseTabPtr_p->addColumn (tableDesc, dataManager, addToParent); }
1227 const Record& dataManagerInfo, Bool addToParent) { baseTabPtr_p->addColumns (tableDesc, dataManagerInfo, addToParent); }
1228inline void Table::removeColumn (const Vector<String>& columnNames)
1229 { baseTabPtr_p->removeColumn (columnNames); }
1230inline void Table::renameColumn (const String& newName, const String& oldName)
1231 { baseTabPtr_p->renameColumn (newName, oldName); }
1232inline void Table::renameHypercolumn (const String& newName, const String& oldName)
1233 { baseTabPtr_p->renameHypercolumn (newName, oldName); }
1234
1236 Bool byColumn) const
1237{
1238 return baseTabPtr_p->findDataManager (name, byColumn);
1239}
1240
1241inline void Table::showStructure (std::ostream& os,
1242 Bool showDataMans,
1243 Bool showColumns,
1244 Bool showSubTables,
1245 Bool sortColumns,
1246 Bool cOrder) const
1247 { baseTabPtr_p->showStructure (os, showDataMans, showColumns,
1248 showSubTables, sortColumns, cOrder); }
1249
1250
1251
1252} //# NAMESPACE CASACORE - END
1253
1254#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
Abstract base class for a node in a table column expression tree.
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:1126
const TableLock & lockOptions() const
Get the locking options.
Definition Table.h:1115
void unlock()
Unlock the table.
Definition Table.h:1124
void renameHypercolumn(const String &newName, const String &oldName)
Definition Table.h:1232
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.
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:1173
TableType tableType() const
Get the table type.
Definition Table.h:1194
Table(const String &tableName, const String &tableDescName, const TableLock &lockOptions, TableOption=Table::Old, const TSMOption &=TSMOption())
friend AipsIO & operator>>(AipsIO &, Table &)
Read a table from AipsIO (for TypedKeywords<Table>).
int tableOption() const
Get the table option.
Definition Table.h:1196
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
Bool isNull() const
Test if the object is null, i.e.
Definition Table.h:480
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:1138
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:1171
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:1180
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:1101
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:1235
void renameColumn(const String &newName, const String &oldName)
Rename a column.
Definition Table.h:1230
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:1192
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:1201
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:1176
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:1189
Bool canAddRow() const
Test if it is possible to add a row to this table.
Definition Table.h:1199
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:1117
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:1148
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:1106
Bool canRemoveColumn(const String &columnName) const
Test if columns can be removed.
void markForDelete()
Mark the table for delete.
Definition Table.h:1169
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:1143
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:1111
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.
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:1241
const TableRecord & keywordSet() const
Get readonly access to the table keyword set.
Definition Table.h:1182
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).
void removeRow(rownr_t rownr)
Remove the given row(s).
Definition Table.h:1210
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:1113
Bool isWritable() const
Test if this table is opened as writable.
Definition Table.h:1136
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:1108
Bool canRenameColumn(const String &columnName) const
Test if a column can be renamed.
Definition Table.h:1205
void reopenRW()
Try to reopen the table for read/write access.
Definition Table.h:1104
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
@ Plain
plain table (stored on disk)
Definition Table.h:189
const TableInfo & tableInfo() const
Get access to the TableInfo object.
Definition Table.h:1185
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:1208
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:1133
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.
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.
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:1214
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
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
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