Skip to content

Commit

Permalink
refs #3641. Improve speed by loading minimal data.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 6, 2012
1 parent 9708cb2 commit 12405b0
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ namespace MantidQt
/**
Getter for the workspace itself
@returns the workspace
@param protocol : fetch protocol
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::Workspace_sptr fetchIt() const;
virtual Mantid::API::Workspace_sptr fetchIt(FetchProtocol protocol) const;
///Clean-up operations
virtual void cleanUp();
/// Destructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ namespace MantidQt
/**
Getter for the workspace itself
@returns the workspace
@param protocol : fetch protocol
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::Workspace_sptr fetchIt() const;
virtual Mantid::API::Workspace_sptr fetchIt(FetchProtocol protocol) const;
///Clean-up operations
virtual void cleanUp();
/// Destructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ namespace MantidQt
/**
Getter for the workspace itself
@returns the workspace
@param protocol : fetch protocol
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::Workspace_sptr fetchIt() const;
virtual Mantid::API::Workspace_sptr fetchIt(FetchProtocol protocol) const;

/*
Do nothing clean-up method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,16 @@ namespace MantidQt
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

// Fetch protocal enumeration type.
enum FetchProtocol{Everything=0, MinimalData};

class DLLExport WorkspaceMemento
{
public:
//Status enumeration type.

// Status enumeration type.
enum Status{NoOrientedLattice=0, Ready};


/// Constructor for the workspace memento.
WorkspaceMemento();
Expand All @@ -66,10 +71,11 @@ namespace MantidQt
virtual bool checkStillThere() const = 0;
/**
Getter for the workspace itself
@returns the matrix workspace
@returns the workspace
@param protocol : Follow the protocol to fetch all spectrum or just the first.
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::Workspace_sptr fetchIt() const = 0;
virtual Mantid::API::Workspace_sptr fetchIt(FetchProtocol protocol) const = 0;
/// Generates a status report based on the workspace state.
std::string statusReport() const;
/// Perform any clean up operations of the underlying workspace
Expand Down
12 changes: 7 additions & 5 deletions Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void CreateMDWorkspace::findUBMatrixClicked()
try
{
WorkspaceMemento_sptr memento = getFirstSelected();
memento->fetchIt();
memento->fetchIt(MinimalData);

// Find the peaks workspace in detector space
command = "from mantidsimple import *\n"
Expand Down Expand Up @@ -210,10 +210,11 @@ Event handler for setting the UB Matrix
*/
void CreateMDWorkspace::setUBMatrixClicked()
{
WorkspaceMemento_sptr memento;
try
{
WorkspaceMemento_sptr memento = getFirstSelected();
Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( memento->fetchIt() );
memento = getFirstSelected();
Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( memento->fetchIt(MinimalData) );
QString id = QString(memento->getId().c_str());

QString pyInput =
Expand All @@ -236,14 +237,15 @@ void CreateMDWorkspace::setUBMatrixClicked()
if (ub.size() == 9 )
{
memento->setUB(ub[0].toDouble(), ub[1].toDouble(), ub[2].toDouble(), ub[3].toDouble(), ub[4].toDouble(), ub[5].toDouble(), ub[6].toDouble(), ub[7].toDouble(), ub[8].toDouble());
memento->cleanUp();
m_model->update();
}
}
catch(std::invalid_argument& ex)
{
runConfirmation(ex.what());
}
memento->cleanUp();

}

/*
Expand Down Expand Up @@ -340,7 +342,7 @@ void CreateMDWorkspace::setGoniometerClicked()
runConfirmation("Currently, Goniometer settings may only be applied to Workspace in memory");
return;
}
Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( memento->fetchIt() );
Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( memento->fetchIt(MinimalData) );
QString id = QString(memento->getId().c_str());

QString pyInput =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace MantidQt
m_adsID = m_adsID.substr(0, m_adsID.find('.'));

//Generate an initial report.
IEventWorkspace_sptr ws = boost::dynamic_pointer_cast<IEventWorkspace>(fetchIt());
IEventWorkspace_sptr ws = boost::dynamic_pointer_cast<IEventWorkspace>(fetchIt(MinimalData));
if(ws->mutableSample().hasOrientedLattice())
{
std::vector<double> ub = ws->mutableSample().getOrientedLattice().getUB().get_vector();
Expand Down Expand Up @@ -79,9 +79,10 @@ namespace MantidQt
/**
Getter for the workspace itself
@returns the matrix workspace
@param protocol : Follow the protocol to fetch all spectrum or just the first.
@throw if workspace has been moved since instantiation.
*/
Mantid::API::Workspace_sptr EventNexusFileMemento::fetchIt() const
Mantid::API::Workspace_sptr EventNexusFileMemento::fetchIt(FetchProtocol protocol) const
{
checkStillThere();

Expand All @@ -90,6 +91,10 @@ namespace MantidQt
alg->setRethrows(true);
alg->setProperty("Filename", m_fileName);
alg->setPropertyValue("OutputWorkspace", m_adsID);
if(protocol == MinimalData)
{
//Peform as speed up here to fetch the minimum amount of data.
}
alg->execute();

Workspace_sptr ws = AnalysisDataService::Instance().retrieve(m_adsID);
Expand Down Expand Up @@ -130,7 +135,7 @@ namespace MantidQt
*/
Mantid::API::Workspace_sptr EventNexusFileMemento::applyActions()
{
Mantid::API::Workspace_sptr ws = fetchIt();
Mantid::API::Workspace_sptr ws = fetchIt(Everything);

if(m_ub.size() == 9)
{
Expand Down
12 changes: 9 additions & 3 deletions Code/Mantid/MantidQt/CustomInterfaces/src/RawFileMemento.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace MantidQt
m_adsID = m_adsID.substr(0, m_adsID.find('.'));

//Generate an initial report.
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(fetchIt());
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(fetchIt(MinimalData));
if(ws->mutableSample().hasOrientedLattice())
{
std::vector<double> ub = ws->mutableSample().getOrientedLattice().getUB().get_vector();
Expand Down Expand Up @@ -79,9 +79,10 @@ namespace MantidQt
/**
Getter for the workspace itself
@returns the matrix workspace
@param protocol : Follow the protocol to fetch all spectrum or just the first.
@throw if workspace has been moved since instantiation.
*/
Mantid::API::Workspace_sptr RawFileMemento::fetchIt() const
Mantid::API::Workspace_sptr RawFileMemento::fetchIt(FetchProtocol protocol) const
{
checkStillThere();

Expand All @@ -90,6 +91,11 @@ namespace MantidQt
alg->setRethrows(true);
alg->setProperty("Filename", m_fileName);
alg->setPropertyValue("OutputWorkspace", m_adsID);
if(protocol == MinimalData)
{
alg->setProperty("SpectrumMin", 1);
alg->setProperty("SpectrumMax", 1);
}
alg->execute();

Workspace_sptr ws = AnalysisDataService::Instance().retrieve(m_adsID);
Expand Down Expand Up @@ -130,7 +136,7 @@ namespace MantidQt
*/
Mantid::API::Workspace_sptr RawFileMemento::applyActions()
{
Mantid::API::Workspace_sptr ws = fetchIt();
Mantid::API::Workspace_sptr ws = fetchIt(Everything);

if(m_ub.size() == 9)
{
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ namespace MantidQt
/**
Getter for the workspace itself
@returns the matrix workspace
@param protocol : fetch protocol
@throw if workspace has been moved since instantiation.
*/
Workspace_sptr WorkspaceInADS::fetchIt() const
Workspace_sptr WorkspaceInADS::fetchIt(FetchProtocol) const
{
if(!checkStillThere())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EventNexusFileMementoTest : public CxxTest::TestSuite
{
EventNexusFileMemento memento(getSuitableFileNamePath());
TSM_ASSERT("File should be present", memento.checkStillThere());
IEventWorkspace_sptr result = boost::dynamic_pointer_cast<IEventWorkspace>(memento.fetchIt());
IEventWorkspace_sptr result = boost::dynamic_pointer_cast<IEventWorkspace>(memento.fetchIt(MinimalData));
TSM_ASSERT("Should have fetched the workspace", result);
}

Expand Down
16 changes: 15 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/test/RawFileMementoTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,24 @@ class RawFileMementoTest : public CxxTest::TestSuite
{
RawFileMemento memento(getSuitableFileNamePath());
TSM_ASSERT("File should be present", memento.checkStillThere());
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.fetchIt());
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.fetchIt(MinimalData));
TSM_ASSERT("Should have fetched the workspace", result);
}

void testFetchItWithMinimalData()
{
RawFileMemento memento(getSuitableFileNamePath());
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.fetchIt(MinimalData));
TS_ASSERT_EQUALS(1, result->getNumberHistograms());
}

void testFetchItWithEverything()
{
RawFileMemento memento(getSuitableFileNamePath());
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.fetchIt(Everything));
TS_ASSERT(result->getNumberHistograms() > 1);
}

void testNoExistingUB()
{
RawFileMemento memento(getSuitableFileNamePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WorkspaceInADSTest : public CxxTest::TestSuite
AnalysisDataService::Instance().addOrReplace("ws", ws);
WorkspaceInADS memento("ws");
TS_ASSERT(memento.checkStillThere());
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>( memento.fetchIt() );
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>( memento.fetchIt(MinimalData) );
TS_ASSERT(result != NULL);
}

Expand All @@ -66,7 +66,7 @@ class WorkspaceInADSTest : public CxxTest::TestSuite
WorkspaceInADS memento("ws");
AnalysisDataService::Instance().remove("ws");
TS_ASSERT(!memento.checkStillThere());
TS_ASSERT_THROWS(memento.fetchIt(), std::runtime_error);
TS_ASSERT_THROWS(memento.fetchIt(MinimalData), std::runtime_error);
}

void testExtractExistingUB()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConcreteWorkspaceMemento : public WorkspaceMemento
throw std::runtime_error("Not implemented");
}

virtual Mantid::API::Workspace_sptr fetchIt() const
virtual Mantid::API::Workspace_sptr fetchIt(FetchProtocol) const
{
throw std::runtime_error("Not implemented");
}
Expand Down

0 comments on commit 12405b0

Please sign in to comment.