Skip to content

Commit

Permalink
Refs #5292. Starting MD checking work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reuter committed May 8, 2012
1 parent dd1c900 commit 7a7db90
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class DLLExport CheckWorkspacesMatch : public API::Algorithm
bool checkMasking(API::MatrixWorkspace_const_sptr ws1, API::MatrixWorkspace_const_sptr ws2);
bool checkSample(const API::Sample& sample1, const API::Sample& sample2);
bool checkRunProperties(const API::Run& run1, const API::Run& run2);
bool checkMDCommon(API::IMDWorkspace_const_sptr ws1, API::IMDWorkspace_const_sptr ws2);


std::string result; ///< the result string
Expand Down
64 changes: 63 additions & 1 deletion Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*WIKI*
/*WIKI*
Compares two workspaces for equality. This algorithm is mainly intended for use by Mantid developers as part of the testing process.
Expand All @@ -13,6 +13,9 @@ In the case of [[EventWorkspace]]s, they are checked to hold identical event lis
// Includes
//----------------------------------------------------------------------
#include "MantidAlgorithms/CheckWorkspacesMatch.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidAPI/IMDHistoWorkspace.h"
#include "MantidAPI/SpectraDetectorMap.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidDataObjects/EventWorkspace.h"
Expand Down Expand Up @@ -290,6 +293,53 @@ void CheckWorkspacesMatch::doComparison()
}
return;
}

// Check things for IMDEventWorkspaces
IMDEventWorkspace_const_sptr mdews1, mdews2;
mdews1 = boost::dynamic_pointer_cast<const IMDEventWorkspace>(w1);
mdews2 = boost::dynamic_pointer_cast<const IMDEventWorkspace>(w2);
if (checkType)
{
if ((mdews1 && !mdews2) ||(!mdews1 && mdews2))
{
result = "One workspace is an IMDEventWorkspace and the other is not.";
return;
}
}
if (mdews1 && mdews2)
{
this->checkMDCommon(mdews1, mdews2);
if (mdews1->getNPoints() != mdews2->getNPoints())
{
result = "Mismatch in number of MD events";
return;
}
return;
}

// Check things for MDHistoWorkspaces
IMDHistoWorkspace_const_sptr mdhws1, mdhws2;
mdhws1 = boost::dynamic_pointer_cast<const IMDHistoWorkspace>(w1);
mdhws2 = boost::dynamic_pointer_cast<const IMDHistoWorkspace>(w2);
if (checkType)
{
if ((mdhws1 && !mdhws2) ||(!mdhws1 && mdhws2))
{
result = "One workspace is an IMDHistoWorkspace and the other is not.";
return;
}
}
if (mdhws1 && mdhws2)
{
this->checkMDCommon(mdhws1, mdhws2);
if (mdhws1->getNPoints() != mdhws2->getNPoints())
{
result = "Mismatch in number of MD histogram bins";
return;
}
return;
}

MatrixWorkspace_const_sptr ws1, ws2;
ws1 = boost::dynamic_pointer_cast<const MatrixWorkspace>(w1);
ws2 = boost::dynamic_pointer_cast<const MatrixWorkspace>(w2);
Expand Down Expand Up @@ -726,6 +776,18 @@ bool CheckWorkspacesMatch::checkRunProperties(const API::Run& run1, const API::R
return true;
}

bool CheckWorkspacesMatch::checkMDCommon(IMDWorkspace_const_sptr ws1,
IMDWorkspace_const_sptr ws2)
{
if (ws1->getNumDims() != ws2->getNumDims())
{
result = "Mismatch in number of reported dimensions";
return false;
}

return true;
}

} // namespace Algorithms
} // namespace Mantid

39 changes: 39 additions & 0 deletions Code/Mantid/Framework/Algorithms/test/CheckWorkspacesMatchTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "MantidKernel/UnitFactory.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidMDEvents/MDHistoWorkspace.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include "MantidTestHelpers/MDEventsTestHelper.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidAlgorithms/CreatePeaksWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
Expand All @@ -19,6 +21,7 @@ using namespace Mantid::Algorithms;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
using namespace Mantid::MDEvents;

class CheckWorkspacesMatchTest : public CxxTest::TestSuite
{
Expand Down Expand Up @@ -211,6 +214,42 @@ class CheckWorkspacesMatchTest : public CxxTest::TestSuite
TS_ASSERT( (!Mantid::API::equals(ews1, ews2)) );
}

void testMDEvents_matches()
{
if ( !checker.isInitialized() ) checker.initialize();

MDEventWorkspace3Lean::sptr mdews1 = MDEventsTestHelper::makeFileBackedMDEW("mdev1", false);
MDEventWorkspace3Lean::sptr mdews2 = MDEventsTestHelper::makeFileBackedMDEW("mdev2", false);
TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1", boost::dynamic_pointer_cast<IMDWorkspace>(mdews1)) );
TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2", boost::dynamic_pointer_cast<IMDWorkspace>(mdews2)) );
TS_ASSERT( checker.execute() );
TS_ASSERT_EQUALS( checker.getPropertyValue("Result"), checker.successString() );
}

void testMDHisto_matches()
{
if ( !checker.isInitialized() ) checker.initialize();

MDHistoWorkspace_sptr mdhws1 = MDEventsTestHelper::makeFakeMDHistoWorkspace(5.0, 4);
MDHistoWorkspace_sptr mdhws2 = MDEventsTestHelper::makeFakeMDHistoWorkspace(5.0, 4);
TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1", boost::dynamic_pointer_cast<IMDWorkspace>(mdhws1)) );
TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2", boost::dynamic_pointer_cast<IMDWorkspace>(mdhws2)) );
TS_ASSERT( checker.execute() );
TS_ASSERT_EQUALS( checker.getPropertyValue("Result"), checker.successString() );
}

void testMDHist_different_dims()
{
if ( !checker.isInitialized() ) checker.initialize();

MDHistoWorkspace_sptr mdhws1 = MDEventsTestHelper::makeFakeMDHistoWorkspace(5.0, 4);
MDHistoWorkspace_sptr mdhws2 = MDEventsTestHelper::makeFakeMDHistoWorkspace(5.0, 3);
TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace1", boost::dynamic_pointer_cast<IMDWorkspace>(mdhws1)) );
TS_ASSERT_THROWS_NOTHING( checker.setProperty("Workspace2", boost::dynamic_pointer_cast<IMDWorkspace>(mdhws2)) );
TS_ASSERT( checker.execute() );
TS_ASSERT_DIFFERS( checker.getPropertyValue("Result"), checker.successString() );
}

void testDifferentSize()
{
if ( !checker.isInitialized() ) checker.initialize();
Expand Down

0 comments on commit 7a7db90

Please sign in to comment.