Mantid
Loading...
Searching...
No Matches
DeleteWorkspace.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 +
10
11namespace Mantid::Algorithms {
12
13using namespace Kernel;
14using namespace API;
15
16// Register the algorithm
17DECLARE_ALGORITHM(DeleteWorkspace)
18
19
20void DeleteWorkspace::init() {
21 declareProperty(std::make_unique<API::WorkspaceProperty<API::Workspace>>("Workspace", "", Kernel::Direction::Input),
22 "Name of the workspace to delete.");
23}
24
30 const std::string wsName = getProperty("Workspace");
31 dataStore.remove(wsName); // Logs if it doesn't exist
32}
33
41 const std::string wsName = getProperty("Workspace");
42 if (dataStore.doesExist(wsName)) {
43 auto wsPtr = dataStore.retrieve(wsName);
44 if (wsPtr->isGroup() && !dataStore.retrieveWS<WorkspaceGroup>(wsName)->isEmpty()) {
46 }
47 return false;
48 } else {
50 }
51}
52
53} // 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 bool checkGroups()
Check the input workspace properties for groups.
Definition: Algorithm.cpp:1154
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
virtual void remove(const std::string &name)
Overridden remove member to delete its name held by the workspace itself.
std::shared_ptr< WSTYPE > retrieveWS(const std::string &name) const
Retrieve a workspace and cast it to the given WSTYPE.
Class to hold a set of workspaces.
bool isEmpty() const
This method returns true if the group is empty (no member workspace)
A property class for workspaces.
A simple algorithm to remove a workspace from the ADS.
bool checkGroups() override
We want most of the functionality from checkGroups, but will handle empty groups separately as we sti...
void exec() override
Overridden exec.
bool doesExist(const std::string &name) const
Check to see if a data object exists in the store.
Definition: DataService.h:370
std::shared_ptr< T > retrieve(const std::string &name) const
Get a shared pointer to a stored data object.
Definition: DataService.h:350
Manage the lifetime of a class intended to be a singleton.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ Input
An input workspace.
Definition: Property.h:53