Skip to content

Commit

Permalink
refs #6351. API changes.
Browse files Browse the repository at this point in the history
Add new method on IMDWorkspace to get any special coordinate system settings. On concrete implementations add setters. Add tests for setters and default values.
  • Loading branch information
OwenArnold committed Jan 14, 2013
1 parent 134b486 commit de5023f
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ namespace Mantid
NumEventsNormalization = 2
};


/// Special coordinate systems
enum SpecialCoordinateSystem
{
None = 0,
HKL = 1,
QLab = 2,
QSample = 3
};


/** Basic MD Workspace Abstract Class.
*
Expand Down Expand Up @@ -110,6 +120,8 @@ namespace Mantid

/// Clear existing masks
virtual void clearMDMasking() = 0;

virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const = 0;
};

/// Shared pointer to the IMDWorkspace base class
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ namespace Mantid
/// Clear exsting masking.
void clearMDMasking();

/// @return the special coordinate system used if any.
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const;

//=====================================================================================
// End IMDWorkspace methods
//=====================================================================================
Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,14 @@ namespace Mantid
throw std::runtime_error("MatrixWorkspace::clearMDMasking has no implementation");
}

/**
@return the special coordinate system used if any.
*/
Mantid::API::SpecialCoordinateSystem MatrixWorkspace::getSpecialCoordinateSystem() const
{
return Mantid::API::None;
}


} // namespace API
} // Namespace Mantid
Expand Down
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/API/test/MatrixWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,12 @@ class MatrixWorkspaceTest : public CxxTest::TestSuite
TSM_ASSERT_THROWS("Characterisation test. This is not implemented.", ws->clearMDMasking(), std::runtime_error);
}

void test_getSpecialCoordinateSystem_default()
{
boost::shared_ptr<MatrixWorkspace> ws(new WorkspaceTester());
TSM_ASSERT_EQUALS("Should default to no special coordinate system.", Mantid::API::None, ws->getSpecialCoordinateSystem());
}

private:
boost::shared_ptr<MatrixWorkspace> ws;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class MockIEventWorkspace : public Mantid::API::IEventWorkspace
MOCK_METHOD1(getSpectrum, Mantid::API::ISpectrum*(const std::size_t));
MOCK_CONST_METHOD1(getSpectrum, const Mantid::API::ISpectrum*(const std::size_t));
MOCK_METHOD3(init, void(const size_t&, const size_t&, const size_t&));
MOCK_CONST_METHOD0(getSpecialCoordinateSystem, Mantid::API::SpecialCoordinateSystem());
virtual ~MockIEventWorkspace(){}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ namespace MDEvents
/// Clear masking
void clearMDMasking();

/// Get the special coordinate system.
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const
{
return m_coordinateSystem;
}

/// Set the special coordinate system.
void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem);

protected:

/** MDBox containing all of the events in the workspace. */
Expand All @@ -153,7 +162,10 @@ namespace MDEvents
/// Box controller in use
//Mantid::API::BoxController_sptr m_BoxController;
boost::shared_ptr<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > > m_BoxController;
private:
private:

/// The special coordinate system of the workspace.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;

public:
/// Typedef for a shared pointer of this kind of event workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ namespace MDEvents
return m_boxLength;
}

/// Get the special coordinate system.
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const
{
return m_coordinateSystem;
}

/// Set the special coordinate system.
void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem);

void setTo(signal_t signal, signal_t errorSquared, signal_t numEvents);

void applyImplicitFunction(Mantid::Geometry::MDImplicitFunction * function, signal_t signal, signal_t errorSquared);
Expand Down Expand Up @@ -430,6 +439,8 @@ namespace MDEvents
coord_t * m_origin;
/// the number of events, contributed into the workspace;
mutable uint64_t m_nEventsContributed;
/// The special coordinate system of the workspace.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;
protected:

/// Linear array of masks for each bin
Expand Down
13 changes: 12 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace MDEvents
TMDE(
MDEventWorkspace)::MDEventWorkspace()
//m_BoxController(boost::make_shared<BoxController>(nd))
: m_BoxController(boost::make_shared<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > >(nd))
: m_BoxController(boost::make_shared<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > >(nd)),
m_coordinateSystem(Mantid::API::None)
{
// First box is at depth 0, and has this default boxController
data = new MDBox<MDE, nd>(m_BoxController, 0);
Expand Down Expand Up @@ -814,6 +815,16 @@ namespace MDEvents
}
}

/**
Set the special coordinate system (if any) to use.
@param coordinateSystem : Special coordinate system to use.
*/
TMDE(
void MDEventWorkspace)::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem)
{
m_coordinateSystem = coordinateSystem;
}

}//namespace MDEvents

}//namespace Mantid
Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ namespace MDEvents
Mantid::Geometry::MDHistoDimension_sptr dimZ, Mantid::Geometry::MDHistoDimension_sptr dimT)
: IMDHistoWorkspace(),
numDimensions(0),
m_nEventsContributed(std::numeric_limits<uint64_t>::quiet_NaN())
m_nEventsContributed(std::numeric_limits<uint64_t>::quiet_NaN()),
m_coordinateSystem(None)
{
std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions;
if (dimX) dimensions.push_back(dimX);
Expand Down Expand Up @@ -1259,6 +1260,15 @@ namespace MDEvents
return sum;
}

/**
Set the special coordinate system (if any) to use.
@param coordinateSystem : Special coordinate system to use.
*/
void MDHistoWorkspace::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem)
{
m_coordinateSystem = coordinateSystem;
}

} // namespace Mantid
} // namespace MDEvents

15 changes: 15 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDEventWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,21 @@ class MDEventWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_THROWS_NOTHING(ws->clearMDMasking());
TSM_ASSERT_EQUALS("Nothing should be masked.", 0, getNumberMasked(ws));
}

void test_getSpecialCoordinateSystem_default()
{
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 1 /*event per box*/);
TSM_ASSERT_EQUALS("Should default to no special coordinate system.", Mantid::API::None, ws->getSpecialCoordinateSystem());
}

void test_setSpecialCoordinateSystem_default()
{
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 1 /*event per box*/);
TS_ASSERT_EQUALS(Mantid::API::None, ws->getSpecialCoordinateSystem());

ws->setCoordinateSystem(Mantid::API::QLab);
TS_ASSERT_EQUALS(Mantid::API::QLab, ws->getSpecialCoordinateSystem());
}
};

class MDEventWorkspaceTestPerformance : public CxxTest::TestSuite
Expand Down
14 changes: 14 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDHistoWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,20 @@ class MDHistoWorkspaceTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("Nothing should be masked.", 0, getNumberMasked(ws));
}

void test_getSpecialCoordinateSystem_default()
{
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1);
TSM_ASSERT_EQUALS("Should default to no special coordinate system.", Mantid::API::None, ws->getSpecialCoordinateSystem());
}

void test_setSpecialCoordinateSystem_default()
{
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1);
TS_ASSERT_EQUALS(Mantid::API::None, ws->getSpecialCoordinateSystem());

ws->setCoordinateSystem(Mantid::API::QLab);
TS_ASSERT_EQUALS(Mantid::API::QLab, ws->getSpecialCoordinateSystem());
}

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class WorkspaceTester : public MatrixWorkspace
ISpectrum * getSpectrum(const size_t index) { return &vec[index]; }
const ISpectrum * getSpectrum(const size_t index) const { return &vec[index];; }
void generateHistogram(const std::size_t , const MantidVec& , MantidVec& , MantidVec& , bool ) const { }
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const { return Mantid::API::None;}

private:
std::vector<SpectrumTester> vec;
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Vates/VatesAPI/test/MockObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class MockIMDWorkspace: public Mantid::API::IMDWorkspace
MOCK_CONST_METHOD0(getNonIntegratedDimensions, Mantid::Geometry::VecIMDDimension_const_sptr());
MOCK_METHOD1(setMDMasking, void(Mantid::Geometry::MDImplicitFunction*));
MOCK_METHOD0(clearMDMasking,void());
MOCK_CONST_METHOD0(getSpecialCoordinateSystem, Mantid::API::SpecialCoordinateSystem());

virtual void getLinePlot(const Mantid::Kernel::VMD & , const Mantid::Kernel::VMD & ,
Mantid::API::MDNormalization , std::vector<Mantid::coord_t> & , std::vector<Mantid::signal_t> & , std::vector<Mantid::signal_t> & ) const
Expand Down

0 comments on commit de5023f

Please sign in to comment.