Skip to content

Commit

Permalink
refs #3641. Prepare for additional memento types
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 6, 2012
1 parent d076cce commit a722e89
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace MantidQt
{
namespace CustomInterfaces
{
/** @class WorkspaceOnDisk
A workspace memento refering to a workspace in the Analysis Data Service.
/** @class RawFileMemento
A workspace memento refering to a Raw File on disk
Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand All @@ -30,13 +30,13 @@ namespace MantidQt
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport WorkspaceOnDisk : public WorkspaceMemento
class DLLExport RawFileMemento : public WorkspaceMemento
{
public:
/**
@param fileName : path + name of the file holding the workspace
*/
WorkspaceOnDisk(std::string fileName);
RawFileMemento(std::string fileName);
/**
Getter for the id of the workspace
@return the id of the workspace
Expand All @@ -61,7 +61,7 @@ namespace MantidQt
///Clean-up operations
virtual void cleanUp();
/// Destructor
virtual ~WorkspaceOnDisk();
virtual ~RawFileMemento();

/*
Location type associated with this type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void CreateMDWorkspace::addFileClicked()
{
try
{
WorkspaceMemento_sptr candidate(new WorkspaceOnDisk(name));
WorkspaceMemento_sptr candidate(new RawFileMemento(name));
addUniqueMemento(candidate);
}
catch(std::invalid_argument& arg)
Expand Down
22 changes: 11 additions & 11 deletions Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ namespace MantidQt
Constructor
@param fileName : path + name of the file to load
*/
WorkspaceOnDisk::WorkspaceOnDisk(std::string fileName) : m_fileName(fileName)
RawFileMemento::RawFileMemento(std::string fileName) : m_fileName(fileName)
{
boost::regex pattern("(RAW)$", boost::regex_constants::icase);

if(!boost::regex_search(fileName, pattern))
{
std::string msg = "WorkspaceOnDisk:: Unknown File extension on: " + fileName;
std::string msg = "RawFileMemento:: Unknown File extension on: " + fileName;
throw std::invalid_argument(msg);
}

if(!checkStillThere())
{
throw std::runtime_error("WorkspaceOnDisk:: File doesn't exist");
throw std::runtime_error("RawFileMemento:: File doesn't exist");
}

std::vector<std::string> strs;
Expand All @@ -51,7 +51,7 @@ namespace MantidQt
Getter for the id of the workspace
@return the id of the workspace
*/
std::string WorkspaceOnDisk::getId() const
std::string RawFileMemento::getId() const
{
return m_adsID;
}
Expand All @@ -60,7 +60,7 @@ namespace MantidQt
Getter for the type of location where the workspace is stored
@ return the location type
*/
std::string WorkspaceOnDisk::locationType() const
std::string RawFileMemento::locationType() const
{
return locType();
}
Expand All @@ -69,7 +69,7 @@ namespace MantidQt
Check that the workspace has not been deleted since instantiating this memento
@return true if still in specified location
*/
bool WorkspaceOnDisk::checkStillThere() const
bool RawFileMemento::checkStillThere() const
{
std::ifstream ifile;
ifile.open(m_fileName.c_str(), std::ifstream::in);
Expand All @@ -81,7 +81,7 @@ namespace MantidQt
@returns the matrix workspace
@throw if workspace has been moved since instantiation.
*/
Mantid::API::Workspace_sptr WorkspaceOnDisk::fetchIt() const
Mantid::API::Workspace_sptr RawFileMemento::fetchIt() const
{
checkStillThere();

Expand All @@ -106,7 +106,7 @@ namespace MantidQt
Dump the workspace out of memory:
@name : name of the workspace to clean-out.
*/
void WorkspaceOnDisk::dumpIt(const std::string& name)
void RawFileMemento::dumpIt(const std::string& name)
{
if(AnalysisDataService::Instance().doesExist(name))
{
Expand All @@ -115,20 +115,20 @@ namespace MantidQt
}

/// Destructor
WorkspaceOnDisk::~WorkspaceOnDisk()
RawFileMemento::~RawFileMemento()
{
}

/// Clean up.
void WorkspaceOnDisk::cleanUp()
void RawFileMemento::cleanUp()
{
dumpIt(m_adsID);
}

/*
Apply actions. Load workspace and apply all actions to it.
*/
Mantid::API::Workspace_sptr WorkspaceOnDisk::applyActions()
Mantid::API::Workspace_sptr RawFileMemento::applyActions()
{
Mantid::API::Workspace_sptr ws = fetchIt();

Expand Down
14 changes: 7 additions & 7 deletions Code/Mantid/MantidQt/CustomInterfaces/test/WorkspaceOnDiskTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace MantidQt::CustomInterfaces;
//using namespace Mantid::DataObjects;
using namespace Mantid::API;

class WorkspaceOnDiskTest : public CxxTest::TestSuite
class RawFileMementoTest : public CxxTest::TestSuite
{
private:

Expand All @@ -26,37 +26,37 @@ class WorkspaceOnDiskTest : public CxxTest::TestSuite
void testConstructorThrowsWithWrongExtension()
{
std::string badFile = "MAR11001.rrr"; //Fictional extension
TSM_ASSERT_THROWS("Unknown extension, should throw.", new WorkspaceOnDisk(badFile), std::invalid_argument);
TSM_ASSERT_THROWS("Unknown extension, should throw.", new RawFileMemento(badFile), std::invalid_argument);
}

void testFileExists()
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
RawFileMemento memento(getSuitableFileNamePath());
TSM_ASSERT("File should be present", memento.checkStillThere());
}

void testConstructThrowsWhenFileDoesntExist()
{
TSM_ASSERT_THROWS("Unknown file, should throw.", new WorkspaceOnDisk("MadeUp.raw"), std::runtime_error);
TSM_ASSERT_THROWS("Unknown file, should throw.", new RawFileMemento("MadeUp.raw"), std::runtime_error);
}

void testFetchItSucceedsWhenFileExists()
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
RawFileMemento memento(getSuitableFileNamePath());
TSM_ASSERT("File should be present", memento.checkStillThere());
MatrixWorkspace_sptr result = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.fetchIt());
TSM_ASSERT("Should have fetched the workspace", result);
}

void testNoExistingUB()
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
RawFileMemento memento(getSuitableFileNamePath());
TS_ASSERT_EQUALS(WorkspaceMemento::NoOrientedLattice, memento.generateStatus());
}

void testApplyActions()
{
WorkspaceOnDisk memento(getSuitableFileNamePath());
RawFileMemento memento(getSuitableFileNamePath());
memento.setUB(0,0,2,0,4,0,-8,0,0);
MatrixWorkspace_sptr ws = boost::dynamic_pointer_cast<MatrixWorkspace>(memento.applyActions());
std::vector<double> ub = ws->sample().getOrientedLattice().getUB().get_vector();
Expand Down

0 comments on commit a722e89

Please sign in to comment.