Skip to content

Commit

Permalink
refs #9455. Add signal value checking.
Browse files Browse the repository at this point in the history
Add tests for this too.
  • Loading branch information
OwenArnold committed May 14, 2014
1 parent 6248634 commit 49a6491
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Code/Mantid/Framework/Crystal/src/FindClusterFaces.cpp
Expand Up @@ -193,18 +193,28 @@ namespace Mantid
PARALLEL_FOR_NO_WSP_CHECK()
for(int it = 0; it < nIterators; ++it)
{
PARALLEL_START_INTERUPT_REGION
ClusterFaces& localClusterFaces = clusterFaces[it];
auto mdIterator = mdIterators[it];

double intpart = 0;
do
{
const int id = static_cast<int>(mdIterator->getSignal());
/*
* Only if the label has been allowed by the filtering, should it be used.
*/
const signal_t signalValue = mdIterator->getSignal();
const int id = static_cast<int>(signalValue);

if (!optionalAllowedLabels.is_initialized()
|| (optionalAllowedLabels->find(id) != optionalAllowedLabels->end()))
{
// Check that the signal value looks like a label id.
if(std::modf(signalValue, &intpart) != 0.0)
{
std::stringstream buffer;
buffer << "Problem at linear index: " << mdIterator->getLinearIndex()
<< " SignalValue is not an integer: " << signalValue << " Suggests wrong input IMDHistoWorkspace passed to FindClusterFaces.";

throw std::runtime_error(buffer.str());
}

if (id > emptyLabelId)
{
progress.report();
Expand All @@ -218,6 +228,7 @@ namespace Mantid
{
size_t neighbourLinearIndex = neighbours[i];
const int neighbourId = static_cast<int>(clusterImage->getSignalAt(neighbourLinearIndex));

if (neighbourId <= emptyLabelId)
{
// We have an edge!
Expand Down Expand Up @@ -247,7 +258,9 @@ namespace Mantid
}

} while (mdIterator->next());
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION

auto out = WorkspaceFactory::Instance().createTable("TableWorkspace");
out->addColumn("int", "ClusterId");
Expand Down
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/Crystal/test/FindClusterFacesTest.h
Expand Up @@ -130,6 +130,13 @@ class FindClusterFacesTest: public CxxTest::TestSuite
Mantid::API::FrameworkManager::Instance();
}

void test_throws_with_non_cluster_mdhistoworkspace()
{
const double nonIntegerSignalValue = 1.2;
IMDHistoWorkspace_sptr inWS = MDEventsTestHelper::makeFakeMDHistoWorkspace(nonIntegerSignalValue, 1, 1);
TS_ASSERT_THROWS(doExecute(inWS), std::runtime_error&);
}

void test_find_no_edges_1D()
{
IMDHistoWorkspace_sptr inWS = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1, 3); // Makes a 1 by 3 md ws with identical signal values.
Expand Down

0 comments on commit 49a6491

Please sign in to comment.