Skip to content

Commit

Permalink
Refs #6352. Merge branch '6352_vsi_peaks_display'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Reuter committed Jan 17, 2013
2 parents 9ae3f94 + 19abe76 commit 091f2b0
Show file tree
Hide file tree
Showing 48 changed files with 501 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDEventWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace API

virtual bool threadSafe() const;

virtual void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem) = 0;

protected:
/// Marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
bool m_fileNeedsUpdating;
Expand Down
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,
QLab = 1,
QSample = 2,
HKL = 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
15 changes: 12 additions & 3 deletions Code/Mantid/Framework/MDAlgorithms/test/ConvertToMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ void testExecNoQ()
pAlg->setRethrows(true);
TS_ASSERT_THROWS_NOTHING(pAlg->execute());
checkHistogramsHaveBeenStored("WS3DNoQ");
AnalysisDataService::Instance().remove("WS3DNoQ");

auto outWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>("WS3DNoQ");
TS_ASSERT_EQUALS(Mantid::API::None, outWS->getSpecialCoordinateSystem());

AnalysisDataService::Instance().remove("WS3DNoQ");
}

void testExecModQ()
Expand All @@ -131,8 +134,11 @@ void testExecModQ()
pAlg->setRethrows(true);
TS_ASSERT_THROWS_NOTHING(pAlg->execute());
checkHistogramsHaveBeenStored("WS3DmodQ");
AnalysisDataService::Instance().remove("WS3DmodQ");

auto outWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>("WS3DmodQ");
TS_ASSERT_EQUALS(Mantid::API::None, outWS->getSpecialCoordinateSystem());

AnalysisDataService::Instance().remove("WS3DmodQ");
}

void testExecQ3D()
Expand All @@ -147,11 +153,14 @@ void testExecQ3D()
pAlg->setPropertyValue("MinValues","-10,-10,-10, 0,-10,-10");
pAlg->setPropertyValue("MaxValues"," 10, 10, 10, 20, 40, 20");


pAlg->setRethrows(false);
pAlg->execute();
TSM_ASSERT("Shoud finish succesfully",pAlg->isExecuted());
checkHistogramsHaveBeenStored("WS5DQ3D");

auto outWS = AnalysisDataService::Instance().retrieveWS<IMDWorkspace>("WS5DQ3D");
TS_ASSERT_EQUALS(Mantid::API::QSample, outWS->getSpecialCoordinateSystem());

AnalysisDataService::Instance().remove("WS5DQ3D");
}

Expand Down
40 changes: 40 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/test/LoadMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,46 @@ class LoadMDTest : public CxxTest::TestSuite
doTestHisto(ws);
}

/// More of an integration test as it uses both load and save.
void test_save_and_load_special_coordinates()
{
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 2);
// Set the special coordinate system
const SpecialCoordinateSystem appliedCoordinateSystem = QSample;
ws->setCoordinateSystem(appliedCoordinateSystem);

const std::string inputWSName = "SaveMDSpecialCoordinatesTest";
const std::string fileName = inputWSName + ".nxs";
AnalysisDataService::Instance().addOrReplace(inputWSName, ws);

SaveMD saveAlg;
saveAlg.initialize();
saveAlg.isInitialized();
saveAlg.setPropertyValue("InputWorkspace", inputWSName);
saveAlg.setPropertyValue("Filename", fileName);
saveAlg.execute();
TS_ASSERT( saveAlg.isExecuted() );

LoadMD loadAlg;
loadAlg.initialize();
loadAlg.isInitialized();
loadAlg.setPropertyValue("Filename", fileName);
loadAlg.setProperty("FileBackEnd", false);
loadAlg.setPropertyValue("OutputWorkspace", "reloaded_again");
loadAlg.execute();
TS_ASSERT( loadAlg.isExecuted() );

// Check that the special coordinate system is the same before the save-load cycle.
TS_ASSERT_EQUALS(appliedCoordinateSystem, ws->getSpecialCoordinateSystem());

if (Poco::File(fileName).exists())
{
Poco::File(fileName).remove();
}
AnalysisDataService::Instance().remove(inputWSName);
AnalysisDataService::Instance().remove("OutputWorkspace");
}

};

#endif /* MANTID_MDEVENTS_LOADMDEWTEST_H_ */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ namespace MDEvents
// On multiprocessor machine the algorithm should run and utilizes all cores (see Kernel::Threadpool),
// but this can be chenged setting this parameter to 0 (no multithreading) or positive number specifying the requested nymber of threads
int m_NumThreads;
/// Any special coordinate system used.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;
private:
/** internal function which do one peace of work, which should be performed by one thread
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class ConvToMDEventsWS: public ConvToMDBase

/**function converts particular type of events into MD space and add these events to the workspace itself */
template <class T> size_t convertEventList(size_t workspaceIndex);

};

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

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

/// 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 +159,7 @@ namespace MDEvents
/// Box controller in use
//Mantid::API::BoxController_sptr m_BoxController;
boost::shared_ptr<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > > m_BoxController;
private:
private:

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,12 @@ namespace MDEvents
return m_boxLength;
}

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

/// 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 +436,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
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ class DLLExport MDWSDescription : public Kernel::PropertyManager
static void fillAddProperties(Mantid::API::MatrixWorkspace_const_sptr inWS2D,const std::vector<std::string> &dimProperyNames,std::vector<coord_t> &AddCoord);

static boost::shared_ptr<Geometry::OrientedLattice> getOrientedLattice(Mantid::API::MatrixWorkspace_const_sptr inWS2D);

/// Set the special coordinate system if any.
void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem system);
/// @return the special coordinate system if any.
Mantid::API::SpecialCoordinateSystem getCoordinateSystem() const;
protected: // until MDWSDesctiptionDepricatedExist
/// the variable which describes the number of the dimensions, in the target workspace.
/// Calculated from number of input properties and the operations, performed on input workspace;
Expand All @@ -151,7 +156,9 @@ class DLLExport MDWSDescription : public Kernel::PropertyManager
//********************* internal helpers
/// helper function to resize all vectors, responsible for MD dimensions in one go
void resizeDimDescriptions(unsigned int Dims,size_t nBins=10);

private:
/// Coordinate system.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;
};

}
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ namespace Mantid
}
catch(Kernel::Exception::NotFoundError &){}


// Record any special coordinate system known to the description.
m_coordinateSystem = WSD.getCoordinateSystem();

return n_spectra;
};

/** empty default constructor */
ConvToMDBase::ConvToMDBase():m_NumThreads(-1)
ConvToMDBase::ConvToMDBase():m_NumThreads(-1), m_coordinateSystem(Mantid::API::None)
{ }


Expand Down
6 changes: 5 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/ConvToMDEventsWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace Mantid
if(!m_EventWS)
throw(std::logic_error(" ConvertToMDEventWS should work with defined event workspace"));

// Record any special coordinate system known to the description.
m_coordinateSystem = WSD.getCoordinateSystem();
return numSpec;
}

Expand Down Expand Up @@ -180,8 +182,10 @@ namespace Mantid
m_OutWSWrapper->pWorkspace()->refreshCache();
m_OutWSWrapper->refreshCentroid();
pProgress->report();
}

/// Set the special coordinate system flag on the output workspace.
m_OutWSWrapper->pWorkspace()->setCoordinateSystem(m_coordinateSystem);
}


} // endNamespace MDEvents
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/ConvToMDHistoWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ namespace Mantid
}
m_OutWSWrapper->pWorkspace()->refreshCache();
m_OutWSWrapper->refreshCentroid();
pProgress->report();
pProgress->report();

/// Set the special coordinate system flag on the output workspace.
m_OutWSWrapper->pWorkspace()->setCoordinateSystem(m_coordinateSystem);
}
/**function calculates the size of temporary memory used to keep convertTo MD data before these data should be added to MDEvents
* @param nThreads -- number of threads used to process data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ namespace MDEvents

std::string dimensionNames[3] = {"Q_lab_x", "Q_lab_y", "Q_lab_z"};
std::string dimensionUnits = "Angstroms^-1";
Mantid::API::SpecialCoordinateSystem coordinateSystem = Mantid::API::QLab;
if (OutputDimensions == "Q (sample frame)")
{
// Set the matrix based on goniometer angles
Expand All @@ -410,6 +411,7 @@ namespace MDEvents
dimensionNames[0] = "Q_sample_x";
dimensionNames[1] = "Q_sample_y";
dimensionNames[2] = "Q_sample_z";
coordinateSystem = Mantid::API::QSample;
}
else if (OutputDimensions == "HKL")
{
Expand All @@ -426,6 +428,7 @@ namespace MDEvents
dimensionNames[1] = "K";
dimensionNames[2] = "L";
dimensionUnits = "lattice";
coordinateSystem = Mantid::API::HKL;
}
// Q in the lab frame is the default, so nothing special to do.

Expand Down Expand Up @@ -616,6 +619,8 @@ namespace MDEvents
g_log.information() << std::endl;
}

// Set the special coordinate system.
ws->setCoordinateSystem(coordinateSystem);

// Save the output
setProperty("OutputWorkspace", boost::dynamic_pointer_cast<IMDEventWorkspace>(ws));
Expand Down
42 changes: 42 additions & 0 deletions Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <algorithm>
#include "MantidMDEvents/MDBoxIterator.h"
#include "MantidKernel/Memory.h"
#include "MantidKernel/Exception.h"

using namespace Mantid;
using namespace Mantid::Kernel;
Expand Down Expand Up @@ -814,6 +815,47 @@ 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)
{
// If there isn't an experiment info, create one.
if(this->getNumExperimentInfo() == 0)
{
ExperimentInfo_sptr expInfo = boost::shared_ptr<ExperimentInfo>(new ExperimentInfo());
this->addExperimentInfo(expInfo);
}
this->getExperimentInfo(0)->mutableRun().addProperty("CoordinateSystem", (int)coordinateSystem, true);
}

/**
Get the special coordinate system (if any) to use.
@return Special coordinate system if any.
*/
TMDE(
Mantid::API::SpecialCoordinateSystem MDEventWorkspace)::getSpecialCoordinateSystem() const
{
Mantid::API::SpecialCoordinateSystem result = None;
try
{
auto nInfos = this->getNumExperimentInfo();
if(nInfos > 0)
{
Property* prop = this->getExperimentInfo(0)->run().getProperty("CoordinateSystem");
PropertyWithValue<int>* p = dynamic_cast<PropertyWithValue<int>* >(prop);
int temp = *p;
result = (SpecialCoordinateSystem)temp;
}
}
catch(Mantid::Kernel::Exception::NotFoundError&)
{
}
return result;
}

}//namespace MDEvents

}//namespace Mantid
Expand Down

0 comments on commit 091f2b0

Please sign in to comment.