-
Notifications
You must be signed in to change notification settings - Fork 122
/
DeleteWorkspace.cpp
53 lines (46 loc) · 1.82 KB
/
DeleteWorkspace.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
52
53
// 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/DeleteWorkspace.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/WorkspaceGroup.h"
namespace Mantid::Algorithms {
using namespace Kernel;
using namespace API;
// Register the algorithm
DECLARE_ALGORITHM(DeleteWorkspace)
/// Initialize the algorithm properties
void DeleteWorkspace::init() {
declareProperty(std::make_unique<API::WorkspaceProperty<API::Workspace>>("Workspace", "", Kernel::Direction::Input),
"Name of the workspace to delete.");
}
/// Execute the algorithm
void DeleteWorkspace::exec() {
using API::AnalysisDataService;
using API::AnalysisDataServiceImpl;
AnalysisDataServiceImpl &dataStore = AnalysisDataService::Instance();
const std::string wsName = getProperty("Workspace");
dataStore.remove(wsName); // Logs if it doesn't exist
}
/**
* We want most of the functionality from checkGroups, but will handle empty groups separately as we still
* want to be able to delete them.
* @return If the workspace should be processed using processGroups.
*/
bool DeleteWorkspace::checkGroups() {
AnalysisDataServiceImpl &dataStore = AnalysisDataService::Instance();
const std::string wsName = getProperty("Workspace");
if (dataStore.doesExist(wsName)) {
auto wsPtr = dataStore.retrieve(wsName);
if (wsPtr->isGroup() && !dataStore.retrieveWS<WorkspaceGroup>(wsName)->isEmpty()) {
return Algorithm::checkGroups();
}
return false;
} else {
return Algorithm::checkGroups();
}
}
} // namespace Mantid::Algorithms