Mantid
Loading...
Searching...
No Matches
UnGroupWorkspace.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
13DECLARE_ALGORITHM(UnGroupWorkspace)
14
15using namespace Kernel;
16using namespace API;
17
20 const AnalysisDataServiceImpl &data_store = AnalysisDataService::Instance();
21 // Get the list of workspaces in the ADS
22 auto workspaceList = data_store.getObjectNames();
23 std::unordered_set<std::string> groupWorkspaceList;
24 // Not iterate over, removing all those which are not group workspaces
25 for (const auto &wsName : workspaceList) {
26 WorkspaceGroup_const_sptr group = std::dynamic_pointer_cast<const WorkspaceGroup>(data_store.retrieve(wsName));
27 // RNT: VC returns bad pointer after erase
28 // if ( !group ) workspaceList.erase(it);
29 if (group) {
30 groupWorkspaceList.insert(wsName);
31 }
32 }
33 // Declare a text property with the list of group workspaces as its allowed
34 // values
35 declareProperty("InputWorkspace", "", "Name of the input workspace to ungroup",
36 std::make_shared<StringListValidator>(groupWorkspaceList));
37}
38
43 const std::string inputws = getProperty("InputWorkspace");
44 AnalysisDataServiceImpl &data_store = Mantid::API::AnalysisDataService::Instance();
45
46 // Retrieve the input workspace
47 Workspace_sptr wsSptr = data_store.retrieve(inputws);
48 // Try to cast it to a WorkspaceGroup
49 WorkspaceGroup_sptr wsGrpSptr = std::dynamic_pointer_cast<WorkspaceGroup>(wsSptr);
50 // Test the cast succeeded - it always should because of ListValidator on
51 // input property
52 if (!wsGrpSptr) {
53 throw std::runtime_error("Selected Workspace is not a WorkspaceGroup");
54 }
55 // add algorithm history to the workspaces being released from the group
56 fillHistory(wsGrpSptr->getAllItems());
57 // Notify observers that a WorkspaceGroup is about to be unrolled
58 data_store.notificationCenter.postNotification(new Mantid::API::WorkspaceUnGroupingNotification(inputws, wsSptr));
59 // Now remove the WorkspaceGroup from the ADS
60 data_store.remove(inputws);
61}
62} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual void fillHistory()
Copy workspace history from input workspaces to output workspaces and record the history for ths algo...
UnGroupingWorkspace notification is sent from UnGroupWorkspace algorithm before the WorkspaceGroup is...
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
virtual Workspace_sptr remove(const std::string &name)
Overridden remove member to delete its name held by the workspace itself.
void exec() override
overridden execute method
void init() override
Overridden Init method.
std::vector< std::string > getObjectNames(DataServiceSort sortState=DataServiceSort::Unsorted, DataServiceHidden hiddenState=DataServiceHidden::Auto, const std::string &contain="") const
Returns a vector of strings containing all object names in the ADS.
std::shared_ptr< T > retrieve(const std::string &name) const
Get a shared pointer to a stored data object.
Poco::NotificationCenter notificationCenter
Sends notifications to observers.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const WorkspaceGroup > WorkspaceGroup_const_sptr
shared pointer to Mantid::API::WorkspaceGroup, pointer to const version