-
Notifications
You must be signed in to change notification settings - Fork 122
/
DeleteWorkspaces.cpp
51 lines (45 loc) · 1.83 KB
/
DeleteWorkspaces.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAlgorithms/DeleteWorkspaces.h"
#include "MantidAPI/ADSValidator.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidKernel/ArrayProperty.h"
namespace Mantid {
namespace Algorithms {
// Register the algorithm
DECLARE_ALGORITHM(DeleteWorkspaces)
/// Initialize the algorithm properties
void DeleteWorkspaces::init() {
declareProperty(
std::make_unique<Kernel::ArrayProperty<std::string>>("WorkspaceList", std::make_shared<API::ADSValidator>()),
"A list of the workspaces to delete.");
}
/// Execute the algorithm
void DeleteWorkspaces::exec() {
const std::vector<std::string> wsNames = getProperty("WorkspaceList");
// Set up progress reporting
API::Progress prog(this, 0.0, 1.0, wsNames.size());
for (const auto &wsName : wsNames) {
// run delete workspace as a child algorithm
if (Mantid::API::AnalysisDataService::Instance().doesExist(wsName)) {
// The existence of input workspaces should have been verified when
// properties were set. If a workspace is missing, it was probably
// a group workspace whose contents were deleted before the group
// itself.
auto deleteAlg = createChildAlgorithm("DeleteWorkspace", -1, -1, false);
deleteAlg->initialize();
deleteAlg->setPropertyValue("Workspace", wsName);
bool success = deleteAlg->execute();
if (!deleteAlg->isExecuted() || !success) {
g_log.error() << "Failed to delete " << wsName << ".\n";
}
}
prog.report();
}
}
} // namespace Algorithms
} // namespace Mantid