diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h index e602fd049ded..ab5171845f3f 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/AddTimeSeriesLog.h @@ -40,6 +40,11 @@ namespace Mantid virtual void initDocs(); void init(); void exec(); + + /// Remove an existing log of the given name + void removeExisting(API::MatrixWorkspace_sptr &logWS, const std::string & name); + /// Create or update the named log entry + void createOrUpdate(API::Run &run, const std::string & name); }; } // namespace Algorithms diff --git a/Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp b/Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp index 340d9e5f86d3..fb7973771ce8 100644 --- a/Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp +++ b/Code/Mantid/Framework/Algorithms/src/AddTimeSeriesLog.cpp @@ -43,8 +43,8 @@ namespace Mantid * @param value The value at the given time */ template - void createOrUpdate(API::Run& run, const std::string & name, - const std::string & time, const T value) + void createOrUpdateValue(API::Run& run, const std::string & name, + const std::string & time, const T value) { TimeSeriesProperty *timeSeries(NULL); if(run.hasProperty(name)) @@ -62,7 +62,6 @@ namespace Mantid } - // Register the algorithm into the AlgorithmFactory DECLARE_ALGORITHM(AddTimeSeriesLog) @@ -122,17 +121,33 @@ namespace Mantid void AddTimeSeriesLog::exec() { 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(); - } + auto &run = logWS->mutableRun(); + if(deleteExisting && run.hasProperty(name)) removeExisting(logWS, name); + + createOrUpdate(run, name); + } + + /** + * @param logWS The workspace containing the log + * @param name The name of the log to delete + */ + void AddTimeSeriesLog::removeExisting(API::MatrixWorkspace_sptr &logWS, const std::string & name) + { + auto deleter = createChildAlgorithm("DeleteLog",-1,-1,false); + deleter->setProperty("Workspace", logWS); + deleter->setProperty("Name", name); + deleter->executeAsChildAlg(); + } + /** + * @param run The run object that either has the log or will store it + * @param name The name of the log to create/update + */ + void AddTimeSeriesLog::createOrUpdate(API::Run &run, const std::string & name) + { std::string time = getProperty("Time"); double valueAsDouble = getProperty("Value"); std::string type = getProperty("Type"); @@ -140,13 +155,15 @@ namespace Mantid if(asInt) { - createOrUpdate(run, name, time, static_cast(valueAsDouble)); + createOrUpdateValue(run, name, time, static_cast(valueAsDouble)); } else { - createOrUpdate(run, name, time, valueAsDouble); + createOrUpdateValue(run, name, time, valueAsDouble); } + } + } // namespace Algorithms } // namespace Mantid