Mantid
Loading...
Searching...
No Matches
DeleteWorkspaces.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
11
12namespace Mantid::Algorithms {
13
14// Register the algorithm
15DECLARE_ALGORITHM(DeleteWorkspaces)
16
17
18void DeleteWorkspaces::init() {
19 declareProperty(
20 std::make_unique<Kernel::ArrayProperty<std::string>>("WorkspaceList", std::make_shared<API::ADSValidator>()),
21 "A list of the workspaces to delete.");
22}
23
26 const std::vector<std::string> wsNames = getProperty("WorkspaceList");
27
28 // Set up progress reporting
29 API::Progress prog(this, 0.0, 1.0, wsNames.size());
30
31 for (const auto &wsName : wsNames) {
32 // run delete workspace as a child algorithm
33 if (Mantid::API::AnalysisDataService::Instance().doesExist(wsName)) {
34 // The existence of input workspaces should have been verified when
35 // properties were set. If a workspace is missing, it was probably
36 // a group workspace whose contents were deleted before the group
37 // itself.
38 auto deleteAlg = createChildAlgorithm("DeleteWorkspace", -1, -1, false);
39 deleteAlg->initialize();
40 deleteAlg->setPropertyValue("Workspace", wsName);
41 auto success = deleteAlg->execute();
42 auto executed = deleteAlg->isExecuted();
43 if (!executed || !success) {
44 g_log.error() << "Failed to delete " << wsName << ".\n";
45 }
46 }
47 prog.report();
48 }
49}
50} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
Kernel::Logger & g_log
Definition: Algorithm.h:451
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A simple algorithm to remove multiple workspaces from the ADS.
void exec() override
Overridden exec.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...