Skip to content

Commit

Permalink
Add ability to wipe a whole log first before creating
Browse files Browse the repository at this point in the history
Refs #9227
  • Loading branch information
martyngigg committed Apr 1, 2014
1 parent f3588ba commit d2eabc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp
Expand Up @@ -111,6 +111,8 @@ namespace Mantid
"An optional type for the given value. A double value with a Type=int will have "
"the fractional part chopped off.",
Direction::Input);
declareProperty("DeleteExisting", false,
"If true and the named log exists then the whole log is removed first.", Direction::Input);
}

//----------------------------------------------------------------------------------------------
Expand All @@ -122,6 +124,15 @@ namespace Mantid
MatrixWorkspace_sptr logWS = getProperty("Workspace");
auto &run = logWS->mutableRun();
std::string name = getProperty("Name");
const bool deleteExisting = getProperty("DeleteExisting");
if(deleteExisting && run.hasProperty(name))
{
auto deleter = createChildAlgorithm("DeleteLog",-1,-1,false);
deleter->setProperty("Workspace", logWS);
deleter->setProperty("Name", name);
deleter->executeAsChildAlg();
}

std::string time = getProperty("Time");
double valueAsDouble = getProperty("Value");
std::string type = getProperty("Type");
Expand Down
13 changes: 12 additions & 1 deletion Code/Mantid/Framework/Algorithms/test/AddTimeSeriesLogTest.h
Expand Up @@ -10,6 +10,7 @@ class AddTimeSeriesLogTest : public CxxTest::TestSuite
{
private:
enum LogType { Double, Integer };
enum UpdateType { Update, Delete };

public:
// This pair of boilerplate methods prevent the suite being created statically
Expand Down Expand Up @@ -50,6 +51,15 @@ class AddTimeSeriesLogTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(1, allowedValues.count("double"));
}

void test_delete_existing_removes_complete_log_first()
{
auto ws = WorkspaceCreationHelper::Create2DWorkspace(10,10);
TS_ASSERT_THROWS_NOTHING(executeAlgorithm(ws, "Test Name", "2010-09-14T04:20:12", 20.0));
checkLogWithEntryExists<double>(ws, "Test Name", "2010-09-14T04:20:12", 20.0, 0);
TS_ASSERT_THROWS_NOTHING(executeAlgorithm(ws, "Test Name", "2010-09-14T04:20:19", 40.0, Double, Delete));

checkLogWithEntryExists<double>(ws, "Test Name", "2010-09-14T04:20:19", 40.0, 0);
}

//-------------------------- Failure cases ------------------------------------
void test_empty_log_name_not_allowed()
Expand Down Expand Up @@ -108,7 +118,7 @@ class AddTimeSeriesLogTest : public CxxTest::TestSuite
private:

void executeAlgorithm(Mantid::API::MatrixWorkspace_sptr testWS, const std::string & logName, const std::string & logTime,
const double logValue, const LogType type = Double)
const double logValue, const LogType type = Double, const UpdateType update = Update)
{
//execute algorithm
Mantid::Algorithms::AddTimeSeriesLog alg;
Expand All @@ -121,6 +131,7 @@ class AddTimeSeriesLogTest : public CxxTest::TestSuite
alg.setPropertyValue("Time", logTime);
alg.setProperty("Value", logValue);
if(type == Integer) alg.setProperty("Type", "int");
if(update == Delete) alg.setProperty("DeleteExisting", true);
alg.setRethrows(true);
alg.execute();
}
Expand Down

0 comments on commit d2eabc9

Please sign in to comment.