Skip to content

Commit

Permalink
refs #4895. MatrixWorkspaceIterator masking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Feb 28, 2012
1 parent fa59b63 commit e119f55
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
14 changes: 13 additions & 1 deletion Code/Mantid/Framework/API/src/MatrixWorkspaceMDIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,21 @@ namespace API
return this->getError();
}

/**
Getter for the masked state of the workspace.
@Return TRUE if the detector/detector-group at the workspace index is masked, or if there is no detector at that index.
*/
bool MatrixWorkspaceMDIterator::getIsMasked() const
{
throw std::runtime_error("Mask determination not implemented on the MatrixWorkspaceMDIteraor yet");
Mantid::Geometry::IDetector_const_sptr det = m_ws->getDetector(m_workspaceIndex);
if(det != NULL)
{
return det->isMasked();
}
else
{
return true; //TODO. Check whether it's better to return true or false under these circumstances.
}
}


Expand Down
28 changes: 23 additions & 5 deletions Code/Mantid/Framework/API/test/MatrixWorkspaceMDIteratorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidAPI/MatrixWorkspaceMDIterator.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidGeometry/Instrument.h"
#include "MantidTestHelpers/FakeObjects.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
Expand All @@ -12,6 +13,7 @@
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;

class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite
{
Expand All @@ -32,7 +34,20 @@ class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite
ws->dataE(wi)[x] = double((wi*10 + x)*2);
}
}
return ws;

Instrument_sptr inst(new Instrument("TestInstrument"));
ws->setInstrument(inst);
// We get a 1:1 map by default so the detector ID should match the spectrum number
for( size_t i = 0; i < ws->getNumberHistograms(); ++i )
{
// Create a detector for each spectra
Detector * det = new Detector("pixel", static_cast<detid_t>(i), inst.get());
inst->add(det);
inst->markAsDetector(det);
ws->getSpectrum(i)->addDetectorID(static_cast<detid_t>(i));
}

return ws;
}

void test_iterating()
Expand Down Expand Up @@ -94,10 +109,13 @@ class MatrixWorkspaceMDIteratorTest : public CxxTest::TestSuite
void test_get_is_masked()
{
boost::shared_ptr<MatrixWorkspace> ws = makeFakeWS();
std::vector<IMDIterator*> iterators = ws->createIterators(1, NULL);

//Characterisation test. Lock-down current behaviour.
TS_ASSERT_THROWS(iterators[0]->getIsMasked(), std::runtime_error);
IMDIterator* it = ws->createIterator(NULL);
for(size_t i = 0; i < ws->getNumberHistograms() ; ++i)
{
Mantid::Geometry::IDetector_const_sptr det = ws->getDetector(i);
TS_ASSERT_EQUALS(det->isMasked(), it->getIsMasked());
it->next();
}
}


Expand Down

0 comments on commit e119f55

Please sign in to comment.