Skip to content
Snippets Groups Projects
Commit 102ab896 authored by Zhou, Wenduo's avatar Zhou, Wenduo
Browse files

More flexible in input of MaskBinsFromTable. Refs #5450.

parent 80b98689
No related branches found
No related tags found
No related merge requests found
......@@ -55,13 +55,45 @@ namespace Algorithms
// 1. Check input table workspace and column order
g_log.debug() << "Lines of parameters workspace = " << paramWS->rowCount() << std::endl;
bool colname_specx = false;
if (!paramWS)
{
throw std::invalid_argument("Input table workspace is not accepted.");
throw std::invalid_argument("Input table workspace is not accepted.");
}
else
{
std::vector<std::string> colnames = paramWS->getColumnNames();
// check colum name order
if (colnames.size() < 3)
{
g_log.error() << "Input MaskingInformation table workspace has fewer than 3 columns. " << colnames.size()
<< " columns indeed" << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
if (colnames[0].compare("XMin") == 0)
{
// 1. Style XMin, XMax, SpectraList. Check rest
if (colnames[1].compare("XMax") != 0 || colnames[2].compare("SpectraList") != 0)
{
g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
}
else if (colnames[0].compare("SpectraList") == 0)
{
// 2. Style SpectraList, XMin, XMax
colname_specx = true;
if (colnames[1].compare("XMin") != 0 || colnames[2].compare("XMax") != 0)
{
g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
}
else
{
g_log.error() << "INput MaskingInformation table workspace has wrong column order. " << std::endl;
throw std::invalid_argument("MaskingInformation (TableWorkspace) has too few columns.");
}
}
// 2. Loop over all rows
......@@ -73,7 +105,14 @@ namespace Algorithms
API::TableRow therow = paramWS->getRow(ib);
double xmin, xmax;
std::string speclist;
therow >> xmin >> xmax >> speclist;
if (colname_specx)
{
therow >> speclist >> xmin >> xmax;
}
else
{
therow >> xmin >> xmax >> speclist;
}
g_log.debug() << "Row " << ib << " XMin = " << xmin << " XMax = " << xmax << " SpectraList = " << speclist << std::endl;
......
......@@ -221,6 +221,54 @@ public:
return;
}
/*
* In-place single mask test.
* Same as the test in MaskBins()
* With TableWorkspace of column in different order
*/
void test_MaskBinWithSingleLine2()
{
// 1. Create a dummy workspace
const std::string workspaceName("raggedMask");
int nBins = 10;
MatrixWorkspace_sptr WS = WorkspaceCreationHelper::Create2DWorkspaceBinned(5, nBins, 0.0);
AnalysisDataService::Instance().add(workspaceName,WS);
// 2. Generate a TableWorskpace
DataObjects::TableWorkspace_sptr tablews = boost::shared_ptr<DataObjects::TableWorkspace>(new DataObjects::TableWorkspace());
tablews->addColumn("str", "SpectraList");
tablews->addColumn("double", "XMin");
tablews->addColumn("double", "XMax");
API::TableRow row0 = tablews->appendRow();
row0 << "1-3" << 3.0 << 6.0;
// 3. Execute
MaskBinsFromTable maskalg;
TS_ASSERT_THROWS_NOTHING(maskalg.initialize());
maskalg.setPropertyValue("InputWorkspace", workspaceName);
maskalg.setPropertyValue("OutputWorkspace",workspaceName);
maskalg.setProperty("MaskingInformation", tablews);
TS_ASSERT_THROWS_NOTHING(maskalg.execute());
TS_ASSERT(maskalg.isExecuted());
// 4. Check
WS = boost::dynamic_pointer_cast<API::MatrixWorkspace>(AnalysisDataService::Instance().retrieve(workspaceName));
TS_ASSERT(WS);
for (int wi=1; wi<=3; wi++)
{
for (int bin=3; bin<6;bin++)
{
TS_ASSERT_EQUALS( WS->dataY(wi)[bin], 0.0 );
}
}
// 5. Clean
AnalysisDataService::Instance().remove(workspaceName);
return;
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment