35 return "Algorithm takes two table workspaces and, if they have the same column titles and data types, combines them "
36 "into a single table. Currently supports data types of double, int, float, string, bool, size_t and V3D.";
45 "The first table workspace.");
48 "The second table workspace.");
51 "The combined table workspace.");
55 static const std::map<std::string, int> types = {{
"double", 0}, {
"int", 1}, {
"str", 2}, {
"bool", 3},
56 {
"size_t", 4}, {
"float", 5}, {
"V3D", 6}};
61 std::map<std::string, std::string> results;
66 const std::size_t expectedCols = LHSWorkspace->columnCount();
69 if (RHSWorkspace->columnCount() != expectedCols) {
70 results.emplace(
"LHSWorkspace",
"Both Table Workspaces must have the same number of columns");
71 results.emplace(
"RHSWorkspace",
"Both Table Workspaces must have the same number of columns");
76 const auto lColNames = LHSWorkspace->getColumnNames();
77 const auto rColNames = RHSWorkspace->getColumnNames();
79 const std::map<std::string, int> &allowedColumnTypes =
allowedTypes();
81 bool matchingColumnNames =
true;
82 bool matchingColumnTypes =
true;
83 bool allColumnTypesAllowed =
true;
85 for (std::size_t i = 0; i < expectedCols; i++) {
86 if (lColNames[i] != rColNames[i]) {
87 matchingColumnNames =
false;
90 auto LHType = LHSWorkspace->getColumn(i)->type();
91 if (LHType != RHSWorkspace->getColumn(i)->type()) {
92 matchingColumnTypes =
false;
95 auto it = allowedColumnTypes.find(LHType);
96 if (it == allowedColumnTypes.end()) {
97 allColumnTypesAllowed =
false;
102 if (!matchingColumnNames) {
103 results.emplace(
"LHSWorkspace",
"Both Table Workspaces must have the same column titles");
104 results.emplace(
"RHSWorkspace",
"Both Table Workspaces must have the same column titles");
107 if (!matchingColumnTypes) {
108 results.emplace(
"LHSWorkspace",
"Both Table Workspaces must have the same data types for corresponding columns");
109 results.emplace(
"RHSWorkspace",
"Both Table Workspaces must have the same data types for corresponding columns");
112 if (!allColumnTypesAllowed) {
113 results.emplace(
"LHSWorkspace",
"Only supported data types are: double, int, string, bool, size_t, float, and V3D");
114 results.emplace(
"RHSWorkspace",
"Only supported data types are: double, int, string, bool, size_t, float, and V3D");
127 const std::map<std::string, int> &allowedColumnTypes =
allowedTypes();
132 const auto nRows = RHSWorkspace->rowCount();
133 const auto nCols = RHSWorkspace->columnCount();
135 std::vector<std::string> colTypes = {};
136 for (std::size_t i = 0; i < nCols; i++) {
137 colTypes.emplace_back(RHSWorkspace->getColumn(i)->type());
142 for (std::size_t r = 0; r < nRows; r++) {
143 TableRow newRow = outputWS->appendRow();
144 TableRow currentRow = RHSWorkspace->getRow(r);
145 for (std::size_t c = 0; c < nCols; c++) {
146 const auto dType = colTypes[c];
147 const int dTypeVal = allowedColumnTypes.at(dType);
150 newRow << currentRow.
Double(c);
153 newRow << currentRow.
Int(c);
156 newRow << currentRow.
cell<std::string>(c);
162 newRow << currentRow.
cell<std::size_t>(c);
165 newRow << currentRow.
cell<
float>(c);
168 newRow << currentRow.
cell<
V3D>(c);
172 throw std::runtime_error(
"Unsupported Data Type");
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Helper class for reporting progress from algorithms.
TableRow represents a row in a TableWorkspace.
double & Double(size_t col)
Returns a reference to the element in position col if its type is double.
int & Int(size_t col)
Returns a reference to the element in position col if its type is int.
T & cell(size_t col)
Templated method to access the element col in the row.
A property class for workspaces.
CombineTableWorkspaces : Take a pair of table workspaces and combine them into a single table by appe...
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
static const std::map< std::string, int > & allowedTypes()
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
void exec() override
Execute the algorithm.
const std::string category() const override
Algorithm's category for identification.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
As TableColumn stores its data in a std::vector bool type cannot be used in the same way as the other...
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.