Mantid
Loading...
Searching...
No Matches
WorkspaceGroup.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 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 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
15
16#include <Poco/NObserver.h>
17#include <iterator>
18#include <mutex>
19
20namespace Mantid {
21
22namespace API {
23//----------------------------------------------------------------------
24// Forward Declarations
25//----------------------------------------------------------------------
26class Algorithm;
27
37class MANTID_API_DLL WorkspaceGroup : public Workspace {
38public:
40 WorkspaceGroup(const Parallel::StorageMode storageMode = Parallel::StorageMode::Cloned);
42 ~WorkspaceGroup() override;
44 const std::string id() const override { return "WorkspaceGroup"; }
46 const std::string toString() const override;
47
49 size_t getMemorySize() const override;
51 void sortMembersByName();
55 int getNumberOfEntries() const { return static_cast<int>(this->size()); }
57 size_t size() const { return m_workspaces.size(); }
59 Workspace_sptr getItem(const size_t index) const;
61 Workspace_sptr getItem(const std::string &wsName) const;
63 std::vector<Workspace_sptr> getAllItems() const;
65 void removeItem(const size_t index);
67 void removeAll();
68 bool isGroup() const override { return true; }
70 bool isEmpty() const;
71 bool areNamesSimilar() const;
73 bool isMultiperiod() const;
75 bool isInGroup(const Workspace &workspaceToCheck, size_t level = 0) const;
77 void print() const;
79 void throwIndexOutOfRangeError(int index) const;
80
83 std::vector<Workspace_sptr>::iterator begin();
86 std::vector<Workspace_sptr>::iterator end();
89 std::vector<Workspace_sptr>::const_iterator begin() const;
92 std::vector<Workspace_sptr>::const_iterator end() const;
93
95
96
98 void sortByName() { AnalysisDataService::Instance().sortGroupByName(this->getName()); }
99
101 void add(const std::string &wsName) { AnalysisDataService::Instance().addToGroup(this->getName(), wsName); }
103 void remove(const std::string &wsName) { AnalysisDataService::Instance().removeFromGroup(this->getName(), wsName); }
105 bool containsInChildren(const std::string &wsName) const;
107 bool contains(const std::string &wsName) const;
109 bool contains(const Workspace_sptr &workspace) const;
111 void reportMembers(std::set<Workspace_sptr> &memberList) const;
115 std::vector<std::string> getNames() const;
117
118 WorkspaceGroup(const WorkspaceGroup &ref) = delete;
120
121private:
122 WorkspaceGroup *doClone() const override {
123 throw std::runtime_error("Cloning of WorkspaceGroup is not implemented.");
124 }
125 WorkspaceGroup *doCloneEmpty() const override {
126 throw std::runtime_error("Cloning of WorkspaceGroup is not implemented.");
127 }
130 void removeByADS(const std::string &wsName);
132 void observeADSNotifications(const bool observeADS);
134 bool isInChildGroup(const Workspace &workspaceToCheck) const;
135
137 void workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice);
138
140 void workspaceBeforeReplaceHandle(Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice);
141
147 std::vector<Workspace_sptr> m_workspaces;
151 mutable std::recursive_mutex m_mutex;
152
154 friend class Algorithm;
155};
156
157} // namespace API
158} // namespace Mantid
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
PyObject * getItem(WorkspaceGroup &self, const int &index)
void removeItem(WorkspaceGroup &self, const std::string &name)
void addWorkspace(WorkspaceGroup &self, const boost::python::object &pyobj)
std::string getName(const IMDDimension &self)
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
Class to hold a set of workspaces.
void remove(const std::string &wsName)
Remove a name from the group.
WorkspaceGroup(const WorkspaceGroup &ref)=delete
Poco::NObserver< WorkspaceGroup, Mantid::API::WorkspaceBeforeReplaceNotification > m_beforeReplaceObserver
Observer for workspace before-replace notifications.
int getNumberOfEntries() const
Return the number of entries within the group.
const std::string id() const override
Return a string ID of the class.
Poco::NObserver< WorkspaceGroup, Mantid::API::WorkspacePostDeleteNotification > m_deleteObserver
Observer for workspace delete notifications.
WorkspaceGroup * doClone() const override
Virtual clone method. Not implemented to force implementation in children.
bool isGroup() const override
bool m_observingADS
Flag as to whether the observers have been added to the ADS.
std::vector< Workspace_sptr > m_workspaces
The list of workspace pointers in the group.
WorkspaceGroup & operator=(const WorkspaceGroup &)=delete
void sortByName()
Invokes the ADS to sort group members by workspace name.
std::recursive_mutex m_mutex
Recursive mutex to avoid simultaneous access.
void add(const std::string &wsName)
Adds a workspace to the group.
WorkspaceGroup * doCloneEmpty() const override
Virtual cloneEmpty method.
size_t size() const
Return the size of the group, so it is more like a container.
Base Workspace Abstract Class.
Definition: Workspace.h:30
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::BeforeReplaceNotification > & WorkspaceBeforeReplaceNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PostDeleteNotification > & WorkspacePostDeleteNotification_ptr
Helper class which provides the Collimation Length for SANS instruments.