Skip to content

Commit

Permalink
refs #4328 #3641. Make WorkspaceMemento ADT workspace type intependent
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 5, 2012
1 parent 937d359 commit 935605e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ namespace MantidQt
virtual bool checkStillThere() const;
/**
Getter for the workspace itself
@returns the matrix workspace
@returns the workspace
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const;
virtual Mantid::API::Workspace_sptr fetchIt() const;

/*
Do nothing clean-up method.
Expand All @@ -77,7 +77,7 @@ namespace MantidQt
virtual ~WorkspaceInADS();

//Apply actions wrapped up in this memento.
virtual void applyActions();
virtual Mantid::API::Workspace_sptr applyActions();

private:
/// Id/name of the workspace in the ADS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "MantidKernel/System.h"
#include "MantidKernel/Matrix.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Workspace.h"
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace MantidQt
@returns the matrix workspace
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const = 0;
virtual Mantid::API::Workspace_sptr fetchIt() 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 All @@ -87,7 +87,7 @@ namespace MantidQt
/// Common implementation for generating status
Status generateStatus() const;
/// Apply actions wrapped up in the memento back to the original workspace
virtual void applyActions() = 0;
virtual Mantid::API::Workspace_sptr applyActions() = 0;

protected:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ namespace MantidQt
virtual bool checkStillThere() const;
/**
Getter for the workspace itself
@returns the matrix workspace
@returns the workspace
@throw if workspace has been moved since instantiation.
*/
virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const;
virtual Mantid::API::Workspace_sptr fetchIt() const;
///Clean-up operations
virtual void cleanUp();
/// Destructor
Expand All @@ -73,7 +73,7 @@ namespace MantidQt
}

//Apply actions wrapped up in this memento.
virtual void applyActions();
virtual Mantid::API::Workspace_sptr applyActions();

private:
/// Helper method to delete a workspace out of memory after loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <boost/regex.hpp>
#include <boost/algorithm/string.hpp>

using namespace Mantid::API;

namespace MantidQt
{
Expand Down Expand Up @@ -208,7 +209,7 @@ void CreateMDWorkspace::setUBMatrixClicked()
try
{
WorkspaceMemento_sptr memento = getFirstSelected();
Mantid::API::MatrixWorkspace_sptr ws = memento->fetchIt();
Mantid::API::MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>( memento->fetchIt() );
QString id = QString(memento->getId().c_str());

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

QString pyInput =
Expand Down
14 changes: 8 additions & 6 deletions Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "MantidAPI/AnalysisDataService.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
Expand All @@ -12,7 +14,7 @@ namespace MantidQt
*/
WorkspaceInADS::WorkspaceInADS(std::string wsName) : m_wsName(wsName)
{
using namespace Mantid::API;

if(!checkStillThere())
{
throw std::runtime_error("WorkspaceInADS:: Workspace does not exist in the ADS: " + wsName);
Expand Down Expand Up @@ -65,15 +67,14 @@ namespace MantidQt
@returns the matrix workspace
@throw if workspace has been moved since instantiation.
*/
Mantid::API::MatrixWorkspace_sptr WorkspaceInADS::fetchIt() const
Workspace_sptr WorkspaceInADS::fetchIt() const
{
using namespace Mantid::API;
if(!checkStillThere())
{
std::string msg("WorkspaceInADS is attempting to fetch a workspace out of the ADS that has been removed or renamed. Original name: " + m_wsName);
throw std::runtime_error(msg);
}
return boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(m_wsName));
return AnalysisDataService::Instance().retrieve(m_wsName);
}

/// Destructor
Expand All @@ -84,9 +85,10 @@ namespace MantidQt
/*
Apply actions. Load workspace and apply all actions to it.
*/
void WorkspaceInADS::applyActions()
Workspace_sptr WorkspaceInADS::applyActions()
{
//Do nothing.
//Do nothing because everything should already have been applied to the workspace in the ADS. Just return it for consistency.
return AnalysisDataService::Instance().retrieve(m_wsName);
}
}
}
16 changes: 8 additions & 8 deletions Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <fstream>
#include <boost/regex.hpp>

using namespace Mantid::API;

namespace MantidQt
{
namespace CustomInterfaces
Expand Down Expand Up @@ -35,7 +37,7 @@ namespace MantidQt
m_adsID = m_adsID.substr(0, m_adsID.find('.'));

//Generate an initial report.
Mantid::API::MatrixWorkspace_sptr ws = fetchIt();
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(fetchIt());
if(ws->mutableSample().hasOrientedLattice())
{
std::vector<double> ub = ws->mutableSample().getOrientedLattice().getUB().get_vector();
Expand Down Expand Up @@ -78,10 +80,8 @@ namespace MantidQt
@returns the matrix workspace
@throw if workspace has been moved since instantiation.
*/
Mantid::API::MatrixWorkspace_sptr WorkspaceOnDisk::fetchIt() const
Mantid::API::Workspace_sptr WorkspaceOnDisk::fetchIt() const
{
using namespace Mantid::API;

checkStillThere();

IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("LoadRaw");
Expand All @@ -98,7 +98,7 @@ namespace MantidQt
{
throw std::invalid_argument("This raw file corresponds to a WorkspaceGroup. Cannot process groups like this. Import via MantidPlot instead.");
}
return boost::dynamic_pointer_cast<MatrixWorkspace>(ws);
return ws;
}

/**
Expand All @@ -107,7 +107,6 @@ namespace MantidQt
*/
void WorkspaceOnDisk::dumpIt(const std::string& name)
{
using Mantid::API::AnalysisDataService;
if(AnalysisDataService::Instance().doesExist(name))
{
AnalysisDataService::Instance().remove(name);
Expand All @@ -128,9 +127,9 @@ namespace MantidQt
/*
Apply actions. Load workspace and apply all actions to it.
*/
void WorkspaceOnDisk::applyActions()
Mantid::API::Workspace_sptr WorkspaceOnDisk::applyActions()
{
Mantid::API::MatrixWorkspace_sptr ws = fetchIt();
Mantid::API::Workspace_sptr ws = fetchIt();

Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("SetUB");
alg->initialize();
Expand All @@ -139,6 +138,7 @@ namespace MantidQt
alg->setProperty("UB", m_ub);
alg->execute();

return AnalysisDataService::Instance().retrieve(m_adsID);
}

}
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());
Mantid::API::MatrixWorkspace_sptr result = memento.fetchIt();
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>( memento.fetchIt() );
TS_ASSERT(result != NULL);
}

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::MatrixWorkspace_sptr fetchIt() const
virtual Mantid::API::Workspace_sptr fetchIt() const
{
throw std::runtime_error("Not implemented");
}
Expand All @@ -52,7 +52,7 @@ class ConcreteWorkspaceMemento : public WorkspaceMemento
throw std::runtime_error("Not implemented");
}

virtual void applyActions()
virtual Mantid::API::Workspace_sptr applyActions()
{
throw std::runtime_error("Not implemented");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidQtCustomInterfaces/WorkspaceOnDisk.h"
#include "MantidAPI/FileFinder.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"

using namespace MantidQt::CustomInterfaces;
Expand Down Expand Up @@ -43,7 +44,7 @@ class WorkspaceOnDiskTest : public CxxTest::TestSuite
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
TSM_ASSERT("File should be present", memento.checkStillThere());
MatrixWorkspace_sptr result = memento.fetchIt();
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.fetchIt());
TSM_ASSERT("Should have fetched the workspace", result);
}

Expand All @@ -57,8 +58,8 @@ class WorkspaceOnDiskTest : public CxxTest::TestSuite
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
memento.setUB(0,0,2,0,4,0,-8,0,0);
memento.applyActions();
std::vector<double> ub = memento.fetchIt()->sample().getOrientedLattice().getUB().get_vector();
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.applyActions());
std::vector<double> ub = ws->sample().getOrientedLattice().getUB().get_vector();
TS_ASSERT_EQUALS(0, ub[0]);
TS_ASSERT_EQUALS(0, ub[1]);
TS_ASSERT_EQUALS(2, ub[2]);
Expand All @@ -68,8 +69,6 @@ class WorkspaceOnDiskTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(-8, ub[6]);
TS_ASSERT_EQUALS(0, ub[7]);
TS_ASSERT_EQUALS(0, ub[8]);


}

};
Expand Down

0 comments on commit 935605e

Please sign in to comment.