Table workspaces are general purpose workspaces for storing data of mixed types. A table workspace is organized in columns. Each column has a name and a type - the type of the data in that column. Table wokspaces can be created using the workspace factory:
ITableWorkspace_sptr table = WorkspaceFactory::Instance().createTable("TableWorkspace");
Columns are added using the addColumn method:
Here the first argument is a symbolic name of the column’s data type and the second argument is the name of the column. The predefined types are:
Symbolic name | C++ type |
---|---|
int | int |
float | float |
double | double |
bool | bool |
str | std::string |
V3D | Mantid::Geometry::V3D |
long64 | int64_t |
The data in the table can be accessed in a number of ways. The most simple way is to call templated method T& cell(row,col), where col is the index of the column in the workspace and row is the index of the cell in the comlumn. Colunms are indexed in the order they are created with addColumn. There are also specialized methods for four predefined data types: int& Int(row,col), double& Double(row,col), std::string& String(row,col), bool& Bool(row,col). Columns use std::vector to store the data. To get access to the vector use getVector(name). To get the column object use getColumn(name).
Only columns of type int, double and str can currently be saved to Nexus by SaveNexus or SaveNexusProcessed. Columns of other types will simply be ommitted from the Nexus file without any error message.
Cells with the same index form a row. TableRow class represents a row. Use getRow(int) or getFirstRow() to access existing rows. For example:
TableRow can also be use for writing into a table:
Users can define new data types to be used in TableWorkspace. TableColumn.h defines macro DECLARE_TABLECOLUMN(c_plus_plus_type,symbolic_name). c_plus_plus_type must be a copyable type and operators << and >> must be defined. There is also DECLARE_TABLEPOINTERCOLUMN macro for declaring non-copyable types, but it has never been used.
Category: Concepts