diff --git a/Framework/DataHandling/src/LoadTBL.cpp b/Framework/DataHandling/src/LoadTBL.cpp index 86816931b59416a202c44339c0a40abf9613445f..1f6a548df850fac7bc449e189406d94e07c65ed7 100644 --- a/Framework/DataHandling/src/LoadTBL.cpp +++ b/Framework/DataHandling/src/LoadTBL.cpp @@ -317,16 +317,16 @@ void LoadTBL::exec() { if (isOld) { /**THIS IS ESSENTIALLY THE OLD LoadReflTBL CODE**/ // create the column headings - auto colStitch = ws->addColumn("str", "StitchGroup"); - auto colRuns = ws->addColumn("str", "Run(s)"); - auto colTheta = ws->addColumn("str", "ThetaIn"); - auto colTrans = ws->addColumn("str", "TransRun(s)"); - auto colQmin = ws->addColumn("str", "Qmin"); - auto colQmax = ws->addColumn("str", "Qmax"); - auto colDqq = ws->addColumn("str", "dq/q"); - auto colScale = ws->addColumn("str", "Scale"); - auto colOptions = ws->addColumn("str", "Options"); - auto colHiddenOptions = ws->addColumn("str", "HiddenOptions"); + ws->addColumn("str", "StitchGroup"); + ws->addColumn("str", "Run(s)"); + ws->addColumn("str", "ThetaIn"); + ws->addColumn("str", "TransRun(s)"); + ws->addColumn("str", "Qmin"); + ws->addColumn("str", "Qmax"); + ws->addColumn("str", "dq/q"); + ws->addColumn("str", "Scale"); + ws->addColumn("str", "Options"); + ws->addColumn("str", "HiddenOptions"); for (size_t i = 0; i < ws->columnCount(); i++) { auto col = ws->getColumn(i); diff --git a/Framework/DataObjects/inc/MantidDataObjects/TableWorkspace.h b/Framework/DataObjects/inc/MantidDataObjects/TableWorkspace.h index d893a30fab61e52111de44545f46beb7441a1167..6b42618f8fd3f1934bb61dc460c27f4f4c028da0 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/TableWorkspace.h +++ b/Framework/DataObjects/inc/MantidDataObjects/TableWorkspace.h @@ -337,7 +337,7 @@ private: } } - bool addColumn(boost::shared_ptr<API::Column> column); + void addColumn(boost::shared_ptr<API::Column> column); /** This method finds the row and column index of an integer cell value in a * table workspace diff --git a/Framework/DataObjects/src/TableWorkspace.cpp b/Framework/DataObjects/src/TableWorkspace.cpp index e2288dcbbe7f29abb744f81dddd53bf52633616e..50f81d44f5572bb9afbc4d0d74bb3c0cd35d1ea7 100644 --- a/Framework/DataObjects/src/TableWorkspace.cpp +++ b/Framework/DataObjects/src/TableWorkspace.cpp @@ -59,18 +59,18 @@ API::Column_sptr TableWorkspace::addColumn(const std::string &type, const std::string &name) { API::Column_sptr c; if (type.empty()) { - g_log.error("Empty string passed as type argument of createColumn."); - return c; + throw std::invalid_argument("Empty string passed as type argument of addColumn."); } if (name.empty()) { - g_log.error("Empty string passed as name argument of createColumn."); + throw std::invalid_argument("Empty string passed as name argument of addColumn."); return c; } // Check that there is no column with the same name. auto ci = std::find_if(m_columns.begin(), m_columns.end(), FindName(name)); if (ci != m_columns.end()) { - g_log.error() << "Column with name " << name << " already exists.\n"; - return c; + std::stringstream ss; + ss << "Column with name " << name << " already exists.\n"; + throw std::invalid_argument(ss.str()); } try { c = API::ColumnFactory::Instance().create(type); @@ -78,10 +78,11 @@ API::Column_sptr TableWorkspace::addColumn(const std::string &type, c->setName(name); resizeColumn(c.get(), rowCount()); } catch (Kernel::Exception::NotFoundError &e) { - g_log.error() << "Column of type " << type << " and name " << name - << " has not been created.\n"; - g_log.error() << e.what() << '\n'; - return c; + std::stringstream ss; + ss << "Column of type " << type << " and name " << name + << " has not been added.\n"; + ss << e.what() << '\n'; + throw std::invalid_argument(ss.str()); } return c; } @@ -104,7 +105,6 @@ API::Column_sptr TableWorkspace::getColumn(const std::string &name) { auto ci = std::find_if(m_columns.begin(), m_columns.end(), FindName(name)); if (ci == m_columns.end()) { std::string str = "Column " + name + " does not exist.\n"; - g_log.error(str); throw std::runtime_error(str); } return *ci; @@ -118,16 +118,15 @@ TableWorkspace::getColumn(const std::string &name) const { } } std::string str = "Column " + name + " does not exist.\n"; - g_log.error(str); throw std::runtime_error(str); } /// Gets the shared pointer to a column. API::Column_sptr TableWorkspace::getColumn(size_t index) { if (index >= columnCount()) { - std::string str = "Column index is out of range"; - g_log.error() << str << ": " << index << "(" << columnCount() << ")\n"; - throw std::range_error(str); + std::stringstream ss; + ss << "Column index is out of range: " << index << "(" << columnCount() << ")\n"; + throw std::range_error(ss.str()); } return m_columns[index]; } @@ -135,9 +134,9 @@ API::Column_sptr TableWorkspace::getColumn(size_t index) { /// Gets the shared pointer to a column. API::Column_const_sptr TableWorkspace::getColumn(size_t index) const { if (index >= columnCount()) { - std::string str = "Column index is out of range"; - g_log.error() << str << ": " << index << "(" << columnCount() << ")\n"; - throw std::range_error(str); + std::stringstream ss; + ss << "Column index is out of range: " << index << "(" << columnCount() << ")\n"; + throw std::range_error(ss.str()); } return m_columns[index]; } @@ -168,8 +167,9 @@ size_t TableWorkspace::insertRow(size_t index) { */ void TableWorkspace::removeRow(size_t index) { if (index >= rowCount()) { - g_log.error() << "Attempt to delete a non-existing row (" << index << ")\n"; - return; + std::stringstream ss; + ss << "Attempt to delete a non-existing row (" << index << ")\n"; + throw std::range_error(ss.str()); } for (auto &column : m_columns) removeFromColumn(column.get(), index); @@ -184,17 +184,17 @@ std::vector<std::string> TableWorkspace::getColumnNames() const { return nameList; } -bool TableWorkspace::addColumn(boost::shared_ptr<API::Column> column) { +void TableWorkspace::addColumn(boost::shared_ptr<API::Column> column) { auto ci = std::find_if(m_columns.begin(), m_columns.end(), FindName(column->name())); if (ci != m_columns.end()) { - g_log.error() << "Column with name " << column->name() - << " already exists.\n"; - return false; + std::stringstream ss; + ss << "Column with name " << column->name() + << " already exists.\n"; + throw std::invalid_argument(ss.str()); } else { m_columns.push_back(column); } - return true; } /** diff --git a/Framework/DataObjects/test/TableWorkspaceTest.h b/Framework/DataObjects/test/TableWorkspaceTest.h index 88b8933b0b68272e2c08a051a8bf68ba9c1c01e2..8148df45c49041bb2763adb081acda58a0d9339e 100644 --- a/Framework/DataObjects/test/TableWorkspaceTest.h +++ b/Framework/DataObjects/test/TableWorkspaceTest.h @@ -112,7 +112,7 @@ public: TS_ASSERT_EQUALS(tw.getColumn("Name"), strCol); TS_ASSERT_EQUALS(tw.getColumn("Position"), v3dCol); // Test trying to add existing column returns null pointer - TS_ASSERT(!tw.addColumn("int", "Number")) + TS_ASSERT_THROWS(tw.addColumn("int", "Number"), std::invalid_argument); tw.getRef<int>("Number", 1) = 17; tw.cell<std::string>(2, 1) = "STRiNG"; diff --git a/Framework/MDAlgorithms/src/PreprocessDetectorsToMD.cpp b/Framework/MDAlgorithms/src/PreprocessDetectorsToMD.cpp index fd9a657540b50c7c1bdbef92fd5bba92e6a1019c..39c38c3c3553692a73332903d186fb4d98cc9de8 100644 --- a/Framework/MDAlgorithms/src/PreprocessDetectorsToMD.cpp +++ b/Framework/MDAlgorithms/src/PreprocessDetectorsToMD.cpp @@ -133,38 +133,28 @@ PreprocessDetectorsToMD::createTableWorkspace( // set the target workspace auto targWS = boost::make_shared<TableWorkspace>(nHist); // detectors positions - if (!targWS->addColumn("V3D", "DetDirections")) - throw(std::runtime_error("Can not add column DetDirectrions")); + targWS->addColumn("V3D", "DetDirections"); // sample-detector distance; - if (!targWS->addColumn("double", "L2")) - throw(std::runtime_error("Can not add column L2")); + targWS->addColumn("double", "L2"); // Diffraction angle - if (!targWS->addColumn("double", "TwoTheta")) - throw(std::runtime_error("Can not add column TwoTheta")); - if (!targWS->addColumn("double", "Azimuthal")) - throw(std::runtime_error("Can not add column Azimuthal")); + targWS->addColumn("double", "TwoTheta"); + targWS->addColumn("double", "Azimuthal"); // the detector ID; - if (!targWS->addColumn("int", "DetectorID")) - throw(std::runtime_error("Can not add column DetectorID")); + targWS->addColumn("int", "DetectorID"); // stores spectra index which corresponds to a valid detector index; - if (!targWS->addColumn("size_t", "detIDMap")) - throw(std::runtime_error("Can not add column detIDMap")); + targWS->addColumn("size_t", "detIDMap"); // stores detector index which corresponds to the workspace index; - if (!targWS->addColumn("size_t", "spec2detMap")) - throw(std::runtime_error("Can not add column spec2detMap")); + targWS->addColumn("size_t", "spec2detMap"); m_getIsMasked = this->getProperty("GetMaskState"); if (m_getIsMasked) // as bool is presented in vectors as a class, we are using // int instead of bool - if (!targWS->addColumn("int", "detMask")) - throw(std::runtime_error( - "Can not add column containing for detector masks")); + targWS->addColumn("int", "detMask"); // check if one wants to obtain detector's efixed" m_getEFixed = this->getProperty("GetEFixed"); if (m_getEFixed) - if (!targWS->addColumn("float", "eFixed")) - throw(std::runtime_error("Can not add column containing efixed")); + targWS->addColumn("float", "eFixed"); // will see about that // sin^2(Theta) diff --git a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp index 01a099f6f56a9e087c301af698fe77229b71d2e6..1195a0d287ff0c95cfff5abb3f16156cec4cf975 100644 --- a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp +++ b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp @@ -1365,25 +1365,18 @@ createTableWorkspace(const API::MatrixWorkspace_const_sptr &inputWS) { // set the target workspace auto targWS = boost::make_shared<TableWorkspace>(nHist); // detectors positions - if (!targWS->addColumn("V3D", "DetDirections")) - throw(std::runtime_error("Can not add column DetDirectrions")); + targWS->addColumn("V3D", "DetDirections"); // sample-detector distance; - if (!targWS->addColumn("double", "L2")) - throw(std::runtime_error("Can not add column L2")); + targWS->addColumn("double", "L2"); // Diffraction angle - if (!targWS->addColumn("double", "TwoTheta")) - throw(std::runtime_error("Can not add column TwoTheta")); - if (!targWS->addColumn("double", "Azimuthal")) - throw(std::runtime_error("Can not add column Azimuthal")); + targWS->addColumn("double", "TwoTheta"); + targWS->addColumn("double", "Azimuthal"); // the detector ID; - if (!targWS->addColumn("int", "DetectorID")) - throw(std::runtime_error("Can not add column DetectorID")); + targWS->addColumn("int", "DetectorID"); // stores spectra index which corresponds to a valid detector index; - if (!targWS->addColumn("size_t", "detIDMap")) - throw(std::runtime_error("Can not add column detIDMap")); + targWS->addColumn("size_t", "detIDMap"); // stores detector index which corresponds to the workspace index; - if (!targWS->addColumn("size_t", "spec2detMap")) - throw(std::runtime_error("Can not add column spec2detMap")); + targWS->addColumn("size_t", "spec2detMap"); // will see about that // sin^2(Theta) @@ -1396,7 +1389,7 @@ createTableWorkspace(const API::MatrixWorkspace_const_sptr &inputWS) { /** method does preliminary calculations of the detectors positions to convert results into k-dE space ; - and places the resutls into static cash to be used in subsequent calls to this + and places the results into static cash to be used in subsequent calls to this algorithm */ void processDetectorsPositions(const API::MatrixWorkspace_const_sptr &inputWS, DataObjects::TableWorkspace_sptr &targWS, @@ -1408,7 +1401,7 @@ void processDetectorsPositions(const API::MatrixWorkspace_const_sptr &inputWS, if ((!source) || (!sample)) { throw Kernel::Exception::InstrumentDefinitionError( - "Instrubment not sufficiently defined: failed to get source and/or " + "Instrument not sufficiently defined: failed to get source and/or " "sample"); } diff --git a/qt/scientific_interfaces/test/MuonAnalysisResultTableCreatorTest.h b/qt/scientific_interfaces/test/MuonAnalysisResultTableCreatorTest.h index 49dce256f3218ef9bbaf4effb009b9bae7d77211..0e8d93b35b5f7b18f4bac21840016a4e1f3ede77 100644 --- a/qt/scientific_interfaces/test/MuonAnalysisResultTableCreatorTest.h +++ b/qt/scientific_interfaces/test/MuonAnalysisResultTableCreatorTest.h @@ -340,13 +340,13 @@ public: // of its columns when they are deleted const auto table = []() { auto tab = WorkspaceFactory::Instance().createTable(); - /*auto col = */ tab->addColumn("str", "Run"); - /*auto col = */ tab->addColumn("double", "A0"); - /*auto col = */ tab->addColumn("double", "A0Error"); - /*auto col = */ tab->addColumn("double", "A1"); - /*auto col = */ tab->addColumn("double", "A1Error"); - /*auto col = */ tab->addColumn("double", "Cost function"); - /*auto col = */ tab->addColumn("double", "Cost function Error"); + tab->addColumn("str", "Run"); + tab->addColumn("double", "A0"); + tab->addColumn("double", "A0Error"); + tab->addColumn("double", "A1"); + tab->addColumn("double", "A1Error"); + tab->addColumn("double", "Cost function"); + tab->addColumn("double", "Cost function Error"); TableRow row1 = tab->appendRow(); TableRow row2 = tab->appendRow();