Skip to content

Commit

Permalink
refs #4895. masking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Feb 28, 2012
1 parent 4548b10 commit 2ae3c2d
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ class IMDWorkspace;
/// Returns the error of a given event
virtual signal_t getInnerError(size_t index) const = 0;

/// Returns true if masking is used.
virtual bool getIsMasked() const = 0;

protected:
/// Normalization method for getNormalizedSignal()
Mantid::API::MDNormalization m_normalization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ namespace API

virtual signal_t getInnerError(size_t index) const;

virtual bool getIsMasked() const;

private:
void calcWorkspacePos(size_t newWI);

Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/API/src/MatrixWorkspaceMDIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ namespace API
return this->getError();
}

bool MatrixWorkspaceMDIterator::getIsMasked() const
{
throw std::runtime_error("Mask determination not implemented on the MatrixWorkspaceMDIteraor yet");
}


} // namespace Mantid
} // namespace API
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ 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);
}


};

Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/IMDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace MDEvents
/// Get number of dimensions
virtual size_t getNumDims() const = 0;


/// Getter for the masking
virtual bool getIsMasked() const = 0;

// ----------------------------- ISaveable Methods ------------------------------------------------------

Expand Down
10 changes: 10 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ namespace MDEvents
void setDataBusy(const bool value)
{ m_dataBusy = value; }

/* Getter to determine if masking is applied.
@return true if masking is applied.
*/
virtual bool getIsMasked() const
{
return m_bIsMasked;
}

std::vector< MDE > & getEvents();

Expand Down Expand Up @@ -226,6 +233,9 @@ namespace MDEvents
/// True when the events were loaded up from disk. Irrelevant if m_onDisk is false.
mutable bool m_inMemory;

/// Flag indicating that masking has been applied.
bool m_bIsMasked;

public:
/// Typedef for a shared pointer to a MDBox
typedef boost::shared_ptr< MDBox<MDE, nd> > sptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ namespace MDEvents

signal_t getInnerError(size_t index) const;

bool getIsMasked() const;


private:
void getEvents() const;
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDGridBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ namespace MDEvents
coord_t getBoxSize(size_t d)
{ return boxSize[d]; }

virtual bool getIsMasked() const;

public:
/// Typedef for a shared pointer to a MDGridBox
typedef boost::shared_ptr< MDGridBox<MDE, nd> > sptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ namespace MDEvents

virtual signal_t getInnerError(size_t index) const;

virtual bool getIsMasked() const{ throw std::runtime_error("MDHistoWorkspaceIterator::getIsMasked no implemented yet.");}

protected:
/// The MDHistoWorkspace being iterated.
const MDHistoWorkspace * m_ws;
Expand Down
9 changes: 4 additions & 5 deletions Code/Mantid/Framework/MDEvents/src/MDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace MDEvents
: IMDBox<MDE, nd>(),
m_dataBusy(false), m_dataModified(false), m_dataAdded(false),
m_fileIndexStart(0), m_fileNumEvents(0),
m_onDisk(false), m_inMemory(true)
m_onDisk(false), m_inMemory(true), m_bIsMasked(false)
{
}

Expand All @@ -30,8 +30,7 @@ namespace MDEvents
: IMDBox<MDE, nd>(),
m_dataBusy(false), m_dataModified(false), m_dataAdded(false),
m_fileIndexStart(0), m_fileNumEvents(0),
m_onDisk(false), m_inMemory(true)

m_onDisk(false), m_inMemory(true), m_bIsMasked(false)
{
if (splitter->getNDims() != nd)
throw std::invalid_argument("MDBox::ctor(): controller passed has the wrong number of dimensions.");
Expand All @@ -51,7 +50,7 @@ namespace MDEvents
: IMDBox<MDE, nd>(extentsVector),
m_dataBusy(false), m_dataModified(false), m_dataAdded(false),
m_fileIndexStart(0), m_fileNumEvents(0),
m_onDisk(false), m_inMemory(true)
m_onDisk(false), m_inMemory(true), m_bIsMasked(false)
{
if (splitter->getNDims() != nd)
throw std::invalid_argument("MDBox::ctor(): controller passed has the wrong number of dimensions.");
Expand All @@ -69,7 +68,7 @@ namespace MDEvents
data(other.data),
m_dataBusy(other.m_dataBusy), m_dataModified(other.m_dataModified), m_dataAdded(other.m_dataAdded),
m_fileIndexStart(other.m_fileIndexStart), m_fileNumEvents(other.m_fileNumEvents),
m_onDisk(other.m_onDisk), m_inMemory(other.m_inMemory)
m_onDisk(other.m_onDisk), m_inMemory(other.m_inMemory), m_bIsMasked(other.m_bIsMasked)
{
}

Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDBoxIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ namespace MDEvents
return (*m_events)[index].getError();
}

/// Returns the error of a given event
TMDE(bool MDBoxIterator)::getIsMasked() const
{
return m_current->getIsMasked();
}


} // namespace Mantid
} // namespace MDEvents
Expand Down
21 changes: 21 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDGridBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,27 @@ namespace MDEvents
} // (for each box)
}

/**
Getter for the masking status of the gridded box.
@return TRUE if ANY ONE of its referenced boxes is masked.
*/
TMDE(
bool MDGridBox)::getIsMasked() const
{
bool isMasked = false;
for (size_t i=0; i < numBoxes; ++i)
{
// Go through each contained box
IMDBox<MDE, nd> * box = boxes[i];
if(box->getIsMasked())
{
isMasked = true;
break;
}
}
return isMasked;
}


}//namespace MDEvents

Expand Down
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/IMDBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class IMDBoxTester : public IMDBox<MDE,nd>
virtual void getBoxes(std::vector<IMDBox<MDE,nd> *>& /*boxes*/, size_t /*maxDepth*/, bool, Mantid::Geometry::MDImplicitFunction *) {};
virtual void generalBin(MDBin<MDE,nd> & /*bin*/, Mantid::Geometry::MDImplicitFunction & /*function*/) const {}

virtual bool getIsMasked() const
{
throw std::runtime_error("IMDBoxTester does not implement getIsMasked");
}

uint64_t getFilePosition() const
{ return m_filePos; }
uint64_t m_filePos;
Expand Down
27 changes: 22 additions & 5 deletions Code/Mantid/Framework/MDEvents/test/MDBoxIteratorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
#include "MantidMDEvents/MDBoxIterator.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDEvents/MDGridBox.h"
#include "MantidMDEvents/MDBox.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include <gmock/gmock.h>

using namespace Mantid::MDEvents;
using namespace Mantid::API;
Expand Down Expand Up @@ -461,6 +463,26 @@ class MDBoxIteratorTest : public CxxTest::TestSuite
TS_ASSERT( !it->next() );
}

void test_getIsMasked()
{
//Mock MDBox. Only one method of interest to the mocking.
class MockMDBox : public MDBox<MDLeanEvent<2>, 2>
{
public:
MOCK_CONST_METHOD0(getIsMasked, bool());
};

MockMDBox mockBox;

MDBoxIterator<MDLeanEvent<2>, 2> it(&mockBox, 1, true);

//All that we want to test is that iterator::getIsMasked calls IMDBox::getIsMasked
EXPECT_CALL(mockBox, getIsMasked()).Times(1);
it.getIsMasked();

TSM_ASSERT("Iterator does not use boxes as expected", testing::Mock::VerifyAndClearExpectations(&mockBox));
}


};

Expand Down Expand Up @@ -563,8 +585,6 @@ class MDBoxIteratorTestPerformance : public CxxTest::TestSuite
do_test_iterator_that_fills_a_vector(true);
}



// ---------------------------------------------------------------
/** For comparison, let's use getBoxes() that fills a vector directly.
* After that, we iterate through them to compare how long the whole operation takes.
Expand Down Expand Up @@ -650,9 +670,6 @@ class MDBoxIteratorTestPerformance : public CxxTest::TestSuite
do_test_getBoxes(true, 3, 125*125*125);
}




};


Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,12 @@ class MDBoxTest : public CxxTest::TestSuite
{
do_test_fileBackEnd_binningOperations(true);
}

void test_getIsMasked_Default()
{
MDBox<MDLeanEvent<1>, 1> box;
TSM_ASSERT("Default should be for a MDBox not to be masked!", !box.getIsMasked());
}
};


Expand Down
72 changes: 72 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDGridBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@
#include <memory>
#include <Poco/File.h>
#include <vector>
#include <gmock/gmock.h>

using namespace Mantid;
using namespace Mantid::Kernel;
using namespace Mantid::MDEvents;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace testing;

class MDGridBoxTest : public CxxTest::TestSuite
{
private:

///Mock type to help determine if masking is being determined correctly
class MockMDBox : public MDBox<MDLeanEvent<1>, 1>
{
public:
MOCK_CONST_METHOD0(getIsMasked, bool());
};

public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
Expand Down Expand Up @@ -1334,7 +1345,68 @@ class MDGridBoxTest : public CxxTest::TestSuite
do_check_integrateSphere(box, 0.0,0.5, 0.01, 1.0, "Tiny, but just barely enough to get an event");
}

void test_getIsMasked_WhenNoMasking()
{
std::vector<IMDBox<MDLeanEvent<1>, 1> *> boxes;

MockMDBox* a = new MockMDBox;
MockMDBox* b = new MockMDBox;

EXPECT_CALL(*a, getIsMasked()).Times(1).WillOnce(Return(false)); //Not masked
EXPECT_CALL(*b, getIsMasked()).Times(1).WillOnce(Return(false)); //Not masked

boxes.push_back(a);
boxes.push_back(b);

MDGridBox<MDLeanEvent<1>,1> g;
g.setChildren(boxes, 0, 2);

TSM_ASSERT("No inner boxes were masked so the MDGridBox should not report that it is masked", !g.getIsMasked());
TS_ASSERT(Mock::VerifyAndClearExpectations(a));
TS_ASSERT(Mock::VerifyAndClearExpectations(b));
}

void test_getIsMasked_WhenFirstMasked()
{
std::vector<IMDBox<MDLeanEvent<1>, 1> *> boxes;

MockMDBox* a = new MockMDBox;
MockMDBox* b = new MockMDBox;

EXPECT_CALL(*a, getIsMasked()).Times(1).WillOnce(Return(true)); //MASKED
EXPECT_CALL(*b, getIsMasked()).Times(0); //Not masked, but will never be called.

boxes.push_back(a);
boxes.push_back(b);

MDGridBox<MDLeanEvent<1>,1> g;
g.setChildren(boxes, 0, 2);

TSM_ASSERT("First inner box masked, so should return masked", g.getIsMasked());
TS_ASSERT(Mock::VerifyAndClearExpectations(a));
TS_ASSERT(Mock::VerifyAndClearExpectations(b));
}

void test_getIsMasked_WhenLastMasked()
{
std::vector<IMDBox<MDLeanEvent<1>, 1> *> boxes;

MockMDBox* a = new MockMDBox;
MockMDBox* b = new MockMDBox;

EXPECT_CALL(*a, getIsMasked()).Times(1).WillOnce(Return(false)); //NOT MASKED
EXPECT_CALL(*b, getIsMasked()).Times(1).WillOnce(Return(true)); //MASKED

boxes.push_back(a);
boxes.push_back(b);

MDGridBox<MDLeanEvent<1>,1> g;
g.setChildren(boxes, 0, 2);

TSM_ASSERT("Second inner box masked, so should return masked", g.getIsMasked());
TS_ASSERT(Mock::VerifyAndClearExpectations(a));
TS_ASSERT(Mock::VerifyAndClearExpectations(b));
}

private:
std::string message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ class MDHistoWorkspaceIteratorTestPerformance : public CxxTest::TestSuite
TSM_ASSERT_THROWS("Not implemented yet, should throw", it->getVertexesArray(numVertexes, outDimensions, maskDim), std::runtime_error);
}

void test_getIsMasked()
{
//Characterisation test
MDHistoWorkspaceIterator iterator(ws);
TSM_ASSERT_THROWS("Not implemented yet, should throw.", iterator.getIsMasked(), std::runtime_error);
}

};


Expand Down

0 comments on commit 2ae3c2d

Please sign in to comment.