Skip to content

Commit

Permalink
refs #5862. Swap boxcontroller as part of mdew copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 22, 2012
1 parent 52a2937 commit 6dc34c0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ namespace MDEvents
/** Set the box controller used.
* @param controller :: Mantid::API::BoxController_sptr
*/
void setBoxController(Mantid::API::BoxController_sptr controller)
virtual void setBoxController(Mantid::API::BoxController_sptr controller)
{ m_BoxController = controller; }

//-----------------------------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/MDEvents/inc/MantidMDEvents/MDGridBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ namespace MDEvents

void refreshCentroid(Kernel::ThreadScheduler * ts = NULL);

// Set the box controller overrriden.
virtual void setBoxController(Mantid::API::BoxController_sptr controller);

// ======================= Testing/Debugging Methods =================
/** For testing: get (a reference to) the vector of boxes */
std::vector<MDBoxBase<MDE, nd>*> & getBoxes()
Expand Down
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ namespace MDEvents
const MDBox<MDE,nd> * mdbox = dynamic_cast<const MDBox<MDE,nd> *>(other.data);
const MDGridBox<MDE,nd> * mdgridbox = dynamic_cast<const MDGridBox<MDE,nd> *>(other.data);
if (mdbox)
{
data = new MDBox<MDE, nd>(*mdbox);
}
else if (mdgridbox)
{
data = new MDGridBox<MDE, nd>(*mdgridbox);
}
else
{
throw std::runtime_error("MDEventWorkspace::copy_ctor(): unexpected data box type found.");
}
data->setBoxController(m_BoxController);
}

//-----------------------------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDGridBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,22 @@ namespace MDEvents
numBoxes = boxes.size();
}

//-----------------------------------------------------------------------------------------------
/** Setter for the box controller. Sets the box controller on all children.
*
* @param controller: BoxController to set.
*/
TMDE(
void MDGridBox)::setBoxController(Mantid::API::BoxController_sptr controller)
{
MDBoxBase::setBoxController(controller);
// Set on all childern.
for (size_t i=0; i<boxes.size(); i++)
{
boxes[i]->setBoxController(controller);
}
}


//-----------------------------------------------------------------------------------------------
/** Helper function to get the index into the linear array given
Expand Down
40 changes: 35 additions & 5 deletions Code/Mantid/Framework/MDEvents/test/MDEventWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <map>
#include <memory>
#include <vector>
#include <typeinfo>
#include <boost/math/special_functions/fpclassify.hpp>

using namespace Mantid;
Expand Down Expand Up @@ -95,21 +96,50 @@ class MDEventWorkspaceTest : public CxxTest::TestSuite
void test_copy_constructor()
{
MDEventWorkspace<MDLeanEvent<3>, 3> ew3;

for (size_t i=0; i<3; i++)
ew3.addDimension( MDHistoDimension_sptr(new MDHistoDimension("x","x","m",-1,1,0)) );
ew3.initialize();
ew3.addEvent( MDLeanEvent<3>(1.23, 4.56) );
ew3.getBoxController()->setSplitThreshold(1);
ew3.addEvent( MDLeanEvent<3>(1.0, 1.0) );
ew3.addEvent( MDLeanEvent<3>(2.0, 2.0) );
ew3.addEvent( MDLeanEvent<3>(3.0, 3.0) );
ew3.splitBox();

ExperimentInfo_sptr ei(new ExperimentInfo);
TS_ASSERT_EQUALS( ew3.addExperimentInfo(ei), 0);

MDEventWorkspace<MDLeanEvent<3>, 3> copy(ew3);
TS_ASSERT( !copy.isGridBox());
TS_ASSERT_EQUALS( copy.getNumDims(), 3);
TS_ASSERT_EQUALS( copy.getDimension(0)->getName(), "x");
TS_ASSERT_EQUALS( copy.getNumExperimentInfo(), 1);
TSM_ASSERT_DIFFERS( "ExperimentInfo's were deep-copied", copy.getExperimentInfo(0), ew3.getExperimentInfo(0));
TSM_ASSERT_DIFFERS( "BoxController was deep-copied", copy.getBoxController(), ew3.getBoxController());
TSM_ASSERT_DIFFERS( "Dimensions were deep-copied", copy.getDimension(0), ew3.getDimension(0));
TSM_ASSERT_DIFFERS( "ExperimentInfo's were not deep-copied", copy.getExperimentInfo(0), ew3.getExperimentInfo(0));
TSM_ASSERT_DIFFERS( "BoxController was not deep-copied", copy.getBoxController(), ew3.getBoxController());
TSM_ASSERT_DIFFERS( "Dimensions were not deep-copied", copy.getDimension(0), ew3.getDimension(0));

/*Test that the boxes were deep copied and that their BoxController pointers have been updated too.*/
typedef MDBoxBase<MDLeanEvent<3>, 3> MDBoxBaseType;
std::vector<MDBoxBaseType *> originalBoxes;
ew3.getBox()->getBoxes(originalBoxes, 10000, false);

std::vector<MDBoxBaseType *> copiedBoxes;
copy.getBox()->getBoxes(copiedBoxes, 10000, false);

// Quick check.
TSM_ASSERT_EQUALS("Number of boxes should be the same before and after the copy.", originalBoxes.size(), copiedBoxes.size());
for(size_t i = 0; i < originalBoxes.size(); ++i)
{
MDBoxBaseType* originalMDBox = originalBoxes[i];
MDBoxBaseType* copiedMDBox = copiedBoxes[i];

auto originalBoxTypeName = std::string(typeid(*originalMDBox).name());
auto copiedBoxTypeName = std::string(typeid(*copiedMDBox).name());

// Check the types
TS_ASSERT("Box types are not the same", originalBoxTypeName.compare(copiedBoxTypeName)==0); // Comparing them this way will at least produce a useful error if type matching fails.
TSM_ASSERT_DIFFERS( "BoxController should be different between original and copied boxes", originalMDBox->getBoxController(), copiedMDBox->getBoxController());
TSM_ASSERT_EQUALS("BoxController on copied box does not match that in copied workspace", copy.getBoxController(), copiedMDBox->getBoxController());
}
}

void test_initialize_throws()
Expand Down
14 changes: 14 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDGridBoxTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ class MDGridBoxTest : public CxxTest::TestSuite
check_MDGridBox(g2);
}

void test_setBoxController()
{
MDGridBox<MDLeanEvent<1>,1> * box = MDEventsTestHelper::makeMDGridBox<1>(10,10,0.0, 10.0);
BoxController_sptr originalBoxController = box->getBoxController();
BoxController_sptr newBoxController = BoxController_sptr(new BoxController(*originalBoxController));

box->setBoxController(newBoxController);
auto boxes = box->getBoxes();
for(size_t i = 0; i < boxes.size(); ++i)
{
TSM_ASSERT_EQUALS("All child boxes should have the same box controller as the parent.", newBoxController, boxes[i]->getBoxController());
}
}



//-----------------------------------------------------------------------------------------
Expand Down

0 comments on commit 6dc34c0

Please sign in to comment.