Skip to content
Snippets Groups Projects
Commit 8b941af9 authored by Doucet, Mathieu's avatar Doucet, Mathieu
Browse files

Added isDirty method. Exposed to python. Added test. Re #2761

parent 7f423737
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,7 @@ public:
const std::string& getTitle() const;
const std::string& getComment() const;
const std::string& getName() const;
bool isDirty(const int n=1) const;
/// Get the footprint in memory in bytes.
virtual size_t getMemorySize() const = 0;
......
......@@ -52,6 +52,7 @@ public:
////
void copyAlgorithmHistory(const WorkspaceHistory& otherHistory);
void addAlgorithmHistory(const AlgorithmHistory& algHistory);
size_t length() const;
void printSelf(std::ostream&, const int indent = 0) const;
......
......@@ -64,6 +64,21 @@ const std::string& Workspace::getName() const
return m_name;
}
/**
* Check whether other algorithms have been applied to the
* workspace by checking the history length.
*
* By default a workspace is called dirty if its history is
* longer than one. This default can be changed to allow for
* workspace creation processes that necessitate more than
* a single algorithm.
*
* @param n: number of algorithms defining a clean workspace
*/
bool Workspace::isDirty(const int n) const
{
return m_history.length()>n;
}
} // namespace API
} // Namespace Mantid
......
......@@ -54,6 +54,14 @@ void WorkspaceHistory::addAlgorithmHistory(const AlgorithmHistory& algHistory)
m_algorithms.push_back(algHistory);
}
/*
Return the history length
*/
size_t WorkspaceHistory::length() const
{
return m_algorithms.size();
}
/** Prints a text representation of itself
* @param os :: The ouput stream to write to
* @param indent :: an indentation value to make pretty printing of object and sub-objects
......
......@@ -172,6 +172,11 @@ namespace PythonAPI
#undef EXPORT_GETLISTPROPERTY
}
bool _isDirty_default(API::Workspace& self)
{
return self.isDirty();
}
void export_workspace()
{
/// Shared pointer registration
......@@ -183,6 +188,8 @@ namespace PythonAPI
.def("getComment", &API::MatrixWorkspace::getComment,
return_value_policy< copy_const_reference >() )
.def("getMemorySize", &API::Workspace::getMemorySize)
.def("isDirty", &API::Workspace::isDirty)
.def("isDirty", &_isDirty_default)
.def("getName", &API::Workspace::getName, return_value_policy< copy_const_reference >())
.def("__str__", &API::Workspace::getName, return_value_policy< copy_const_reference >())
;
......
......@@ -30,6 +30,12 @@ class MatrixWorkspaceTest(unittest.TestCase):
DeleteWorkspace(alf_1)
DeleteWorkspace(alf_2)
def test_is_dirty(self):
CreateWorkspace("test", DataX=1, DataY=1, DataE=1)
self.assertFalse(mtd["test"].isDirty())
Scale(InputWorkspace="test", OutputWorkspace="test", Factor=2.0)
self.assertTrue(mtd["test"].isDirty())
if __name__ == '__main__':
unittest.main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment