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//----------------------------------------------------------------------
13#include "MantidAPI/DllConfig.h"
17
18#include <Poco/NObserver.h>
19#include <iterator>
20#include <mutex>
21
22namespace Mantid {
23
24namespace API {
25//----------------------------------------------------------------------
26// Forward Declarations
27//----------------------------------------------------------------------
28class Algorithm;
29
39class MANTID_API_DLL WorkspaceGroup : public Workspace {
40public:
44 ~WorkspaceGroup() override;
46 const std::string id() const override { return "WorkspaceGroup"; }
48 const std::string toString() const override;
49
51 size_t getMemorySize() const override;
53 void sortMembersByName();
55 void reorderMembersWithIndices(const std::vector<int> &indices);
59 int getNumberOfEntries() const { return static_cast<int>(this->size()); }
61 size_t size() const { return m_workspaces.size(); }
63 Workspace_sptr getItem(const size_t index) const;
65 Workspace_sptr getItem(const std::string &wsName) const;
67 std::vector<Workspace_sptr> getAllItems() const;
69 void removeItem(const size_t index);
71 void removeAll();
72 bool isGroup() const override { return true; }
74 bool isEmpty() const;
75 bool areNamesSimilar() const;
77 bool isMultiperiod() const;
79 bool isGroupPeaksWorkspaces() const;
81 bool isInGroup(const Workspace &workspaceToCheck, size_t level = 0) const;
83 void print() const;
85 void throwIndexOutOfRangeError(int index) const;
86
89 std::vector<Workspace_sptr>::iterator begin();
92 std::vector<Workspace_sptr>::iterator end();
95 std::vector<Workspace_sptr>::const_iterator begin() const;
98 std::vector<Workspace_sptr>::const_iterator end() const;
99
101
102
104 void sortByName() { AnalysisDataService::Instance().sortGroupByName(this->getName()); }
105
107 void add(const std::string &wsName) { AnalysisDataService::Instance().addToGroup(this->getName(), wsName); }
109 void remove(const std::string &wsName) { AnalysisDataService::Instance().removeFromGroup(this->getName(), wsName); }
111 bool containsInChildren(const std::string &wsName) const;
113 bool contains(const std::string &wsName) const;
115 bool contains(const Workspace_sptr &workspace) const;
117 void reportMembers(std::set<Workspace_sptr> &memberList) const;
121 std::vector<std::string> getNames() const;
123
124 WorkspaceGroup(const WorkspaceGroup &ref) = delete;
126
127private:
128 WorkspaceGroup *doClone() const override {
129 throw std::runtime_error("Cloning of WorkspaceGroup is not implemented.");
130 }
131 WorkspaceGroup *doCloneEmpty() const override {
132 throw std::runtime_error("Cloning of WorkspaceGroup is not implemented.");
133 }
136 void removeByADS(const std::string &wsName);
138 void observeADSNotifications(const bool observeADS);
140 bool isInChildGroup(const Workspace &workspaceToCheck) const;
141
143 void workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice);
144
146 void workspaceBeforeReplaceHandle(Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice);
147
153 std::vector<Workspace_sptr> m_workspaces;
157 mutable std::recursive_mutex m_mutex;
158
160 friend class Algorithm;
161};
162
163} // namespace API
164} // namespace Mantid
165
166// Instantiated and exported by API/src/PropertyWithValue.cpp
167MANTID_API_EXTERN_TEMPLATE(Mantid::Kernel::PropertyWithValue<std::shared_ptr<Mantid::API::WorkspaceGroup>>);
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
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)
MANTID_API_EXTERN_TEMPLATE(Mantid::Kernel::PropertyWithValue< std::shared_ptr< Mantid::API::WorkspaceGroup > >)
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
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
The concrete, templated class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::BeforeReplaceNotification > & WorkspaceBeforeReplaceNotification_ptr
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PostDeleteNotification > & WorkspacePostDeleteNotification_ptr
std::string toString(const T &value)
Convert values to strings.
Helper class which provides the Collimation Length for SANS instruments.