Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/DeleteLog.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef MANTID_ALGORITHMS_DELETELOG_H_ | ||
#define MANTID_ALGORITHMS_DELETELOG_H_ | ||
|
||
#include "MantidAPI/Algorithm.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
|
||
/** | ||
Copyright © 2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class DLLExport DeleteLog : public API::Algorithm | ||
{ | ||
public: | ||
virtual const std::string name() const; | ||
virtual int version() const; | ||
virtual const std::string category() const; | ||
|
||
private: | ||
virtual void initDocs(); | ||
void init(); | ||
void exec(); | ||
}; | ||
|
||
|
||
} // namespace Algorithms | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_ALGORITHMS_DELETELOG_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*WIKI* | ||
Removes a named log from the run attached to the input workspace. If the log does not exist then the algorithm simply | ||
emits a warning and does not fail. | ||
*WIKI*/ | ||
#include "MantidAlgorithms/DeleteLog.h" | ||
#include "MantidKernel/MandatoryValidator.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Algorithms | ||
{ | ||
using namespace API; | ||
using namespace Kernel; | ||
|
||
// Register the algorithm into the AlgorithmFactory | ||
DECLARE_ALGORITHM(DeleteLog) | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// @copydoc Algorithm::name | ||
const std::string DeleteLog::name() const { return "DeleteLog"; } | ||
|
||
/// @copydoc Algorithm::version | ||
int DeleteLog::version() const { return 1; } | ||
|
||
/// @copydoc Algorithm::category | ||
const std::string DeleteLog::category() const { return "DataHandling\\Logs";} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/// Sets documentation strings for this algorithm | ||
void DeleteLog::initDocs() | ||
{ | ||
this->setWikiSummary("Removes a named log from a run"); | ||
this->setOptionalMessage("Removes a named log from a run"); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Initialize the algorithm's properties. | ||
*/ | ||
void DeleteLog::init() | ||
{ | ||
declareProperty(new WorkspaceProperty<>("Workspace","",Direction::InOut), | ||
"In/out workspace containing the logs. The workspace is modified in place"); | ||
declareProperty("Name","", boost::make_shared<MandatoryValidator<std::string>>(), | ||
"", Direction::Input); | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
/** Execute the algorithm. | ||
*/ | ||
void DeleteLog::exec() | ||
{ | ||
MatrixWorkspace_sptr logWS = getProperty("Workspace"); | ||
std::string logName = getProperty("Name"); | ||
auto & run = logWS->mutableRun(); | ||
if(run.hasProperty(logName)) | ||
{ | ||
run.removeLogData(logName); | ||
} | ||
else | ||
{ | ||
g_log.warning() << "Unable to delete log '" << logName << "' from the given workspace as it does not exist.\n"; | ||
} | ||
} | ||
|
||
} // namespace Algorithms | ||
} // namespace Mantid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#ifndef MANTID_ALGORITHMS_DELETELOGTEST_H_ | ||
#define MANTID_ALGORITHMS_DELETELOGTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidAlgorithms/DeleteLog.h" | ||
#include "MantidKernel/TimeSeriesProperty.h" | ||
#include "MantidTestHelpers/WorkspaceCreationHelper.h" | ||
|
||
|
||
class DeleteLogTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static DeleteLogTest *createSuite() { return new DeleteLogTest(); } | ||
static void destroySuite( DeleteLogTest *suite ) { delete suite; } | ||
|
||
// -------------------------- Success tests -------------------------- | ||
|
||
void test_Init() | ||
{ | ||
Mantid::Algorithms::DeleteLog alg; | ||
TS_ASSERT_THROWS_NOTHING( alg.initialize() ) | ||
TS_ASSERT( alg.isInitialized() ) | ||
} | ||
|
||
void test_non_existant_log_does_not_throw_error() | ||
{ | ||
Mantid::Algorithms::DeleteLog alg; | ||
alg.initialize(); | ||
alg.setChild(true); // no ADS storage | ||
alg.setRethrows(true); | ||
TS_ASSERT_THROWS_NOTHING(alg.setProperty("Name", "NotALog")); | ||
auto ws = WorkspaceCreationHelper::Create2DWorkspace(10,10); | ||
alg.setProperty("Workspace", ws); | ||
TS_ASSERT_THROWS_NOTHING(alg.execute()); | ||
} | ||
|
||
void test_single_value_log_is_deleted() | ||
{ | ||
Mantid::Algorithms::DeleteLog alg; | ||
alg.initialize(); | ||
alg.setChild(true); // no ADS storage | ||
alg.setRethrows(true); | ||
auto ws = WorkspaceCreationHelper::Create2DWorkspace(10,10); | ||
std::string logName("SingleValue"); | ||
ws->mutableRun().addProperty<double>(logName, 1.0); | ||
alg.setProperty("Workspace", ws); | ||
|
||
TS_ASSERT_THROWS_NOTHING(alg.setProperty("Name", logName)); | ||
TS_ASSERT_THROWS_NOTHING(alg.execute()); | ||
|
||
TS_ASSERT(!ws->run().hasProperty(logName)); | ||
} | ||
|
||
void test_time_series_log_is_deleted() | ||
{ | ||
Mantid::Algorithms::DeleteLog alg; | ||
alg.initialize(); | ||
alg.setChild(true); // no ADS storage | ||
alg.setRethrows(true); | ||
auto ws = WorkspaceCreationHelper::Create2DWorkspace(10,10); | ||
std::string logName("TimeSeries"); | ||
|
||
auto *tsp = new Mantid::Kernel::TimeSeriesProperty<double>(logName); | ||
tsp->addValue("2010-09-14T04:20:12", 20.0); | ||
ws->mutableRun().addProperty(tsp); | ||
alg.setProperty("Workspace", ws); | ||
|
||
TS_ASSERT_THROWS_NOTHING(alg.setProperty("Name", logName)); | ||
TS_ASSERT_THROWS_NOTHING(alg.execute()); | ||
|
||
TS_ASSERT(!ws->run().hasProperty(logName)); | ||
} | ||
|
||
|
||
// -------------------------- Failure tests -------------------------- | ||
|
||
void test_empty_log_name_throws_invalid_argument() | ||
{ | ||
Mantid::Algorithms::DeleteLog alg; | ||
alg.initialize(); | ||
TS_ASSERT_THROWS(alg.setProperty("Name", ""), std::invalid_argument); | ||
} | ||
|
||
}; | ||
|
||
|
||
#endif /* MANTID_ALGORITHMS_DELETELOGTEST_H_ */ |