18size_t MAXIMUM_DEPTH = 100;
20Kernel::Logger
g_log(
"WorkspaceGroup");
25 m_beforeReplaceObserver(*this, &
WorkspaceGroup::workspaceBeforeReplaceHandle), m_workspaces(),
26 m_observingADS(false) {}
39 const std::string firstLine = this->
id() +
"\n";
40 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
41 const auto descr = std::accumulate(
43 [](
const auto &
string,
const auto &
workspace) { return string +
" -- " + workspace->getName() +
'\n'; });
75 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
80 if (group->isInGroup(workspaceToCheck))
91 if (this->
size() == 0) {
105 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
107 g_log.
warning(
"Can't add a workspace as a child of itself!\n");
114 g_log.
warning() <<
"Workspace already exists in a WorkspaceGroup\n";
124 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
128 const auto group = std::dynamic_pointer_cast<WorkspaceGroup>(
workspace);
129 if (group->containsInChildren(wsName)) {
146 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
148 [&wsName](
const auto &
workspace) { return workspace->getName() == wsName; });
156 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
167 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
177 std::vector<std::string> out;
178 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
182 [](
const auto &ws) { return ws->getName(); });
193 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
206 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
208 [&wsName](
const auto &
workspace) { return workspace->getName() == wsName; });
210 throw std::out_of_range(
"Workspace " + wsName +
" not contained in the group");
219 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
232 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
235 if ((**it).getName() == wsName) {
245 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
257 std::ostringstream os;
258 os <<
"WorkspaceGroup - index out of range. Requested=" <<
index <<
", current size=" << this->
size();
259 throw std::out_of_range(os.str());
301 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
303 if (!this->
getName().empty()) {
304 throw std::runtime_error(
"AnalysisDataService must be used to remove a "
305 "workspace from group.");
308 std::ostringstream os;
309 os <<
"WorkspaceGroup - index out of range. Requested=" <<
index <<
", current size=" << this->
size();
310 throw std::out_of_range(os.str());
325 std::unique_lock<std::recursive_mutex> _lock(
m_mutex);
326 const std::string deletedName = notice->objectName();
330 if (deletedName != this->
getName()) {
353 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
355 const auto oldObject = notice->oldObject();
356 const auto newObject = notice->newObject();
358 bool foundOld(
false);
359 bool foundDuplicate(
false);
371 foundDuplicate =
true;
374 if (foundOld && foundDuplicate) {
389 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
401 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
407 const std::string &wsName =
workspace->getName();
409 std::size_t pos = wsName.find_last_of(
'_');
411 if (pos == std::string::npos)
415 std::string commonpart(wsName.substr(0, pos));
416 if (this->
getName() != commonpart)
428 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
430 g_log.
debug(
"Not a multiperiod-group with < 1 nested workspace.");
441 g_log.
debug(
"Not a multiperiod-group with nperiods log < 1.");
445 g_log.
debug(
"Not a multiperiod-group without nperiods log on all "
446 "nested workspaces.");
450 g_log.
debug(
"Not a multiperiod-group unless all inner workspaces are "
451 "Matrix Workspaces.");
467 if (level > MAXIMUM_DEPTH) {
468 throw std::runtime_error(
"WorkspaceGroup nesting level is too deep.");
470 std::lock_guard<std::recursive_mutex> _lock(
m_mutex);
472 if (
workspace.get() == &workspaceToCheck)
476 if (group->isInGroup(workspaceToCheck, level + 1))
484 auto total = std::size_t(0);
489 total = total + std::dynamic_pointer_cast<WorkspaceGroup>(
workspace)->getMemorySize();
492 total = total +
workspace->getMemorySize();
505IPropertyManager::getValue<Mantid::API::WorkspaceGroup_sptr>(
const std::string &name)
const {
510 std::string message =
511 "Attempt to assign property " + name +
" to incorrect type. Expected shared_ptr<WorkspaceGroup>.";
512 throw std::runtime_error(message);
518IPropertyManager::getValue<Mantid::API::WorkspaceGroup_const_sptr>(
const std::string &name)
const {
519 auto *prop =
dynamic_cast<PropertyWithValue<Mantid::API::WorkspaceGroup_sptr> *
>(getPointerToProperty(name));
521 return prop->operator()();
523 std::string message =
524 "Attempt to assign property " + name +
" to incorrect type. Expected const shared_ptr<WorkspaceGroup>.";
525 throw std::runtime_error(message);
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
Class to hold a set of workspaces.
std::vector< Workspace_sptr > getAllItems() const
Return all workspaces in the group as one call for thread safety.
void observeADSNotifications(const bool observeADS)
Turn ADS observations on/off.
void addWorkspace(const Workspace_sptr &workspace)
Adds a workspace to the group.
const std::string toString() const override
Returns a formatted string detailing the contents of the group.
std::vector< Workspace_sptr >::iterator end()
Returns a non-const iterator pointing at the last element in the workspace group.
Poco::NObserver< WorkspaceGroup, Mantid::API::WorkspaceBeforeReplaceNotification > m_beforeReplaceObserver
Observer for workspace before-replace notifications.
void removeAll()
Remove all names from the group but do not touch the ADS.
WorkspaceGroup(const Parallel::StorageMode storageMode=Parallel::StorageMode::Cloned)
Default constructor.
void workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice)
Callback when a delete notification is received.
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() override
Destructor.
size_t getMemorySize() const override
Return the memory size of all workspaces in this group and subgroups.
bool m_observingADS
Flag as to whether the observers have been added to the ADS.
std::vector< Workspace_sptr >::iterator begin()
Returns a non-const iterator pointing at the first element in the workspace group.
void removeByADS(const std::string &wsName)
ADS removes a member of this group using this method.
void print() const
Prints the group to the screen using the logger at debug.
bool isEmpty() const
This method returns true if the group is empty (no member workspace)
void removeItem(const size_t index)
Remove a workspace from the group.
bool contains(const std::string &wsName) const
Does a workspace exist within the group.
Workspace_sptr getItem(const size_t index) const
Return the ith workspace.
bool containsInChildren(const std::string &wsName) const
Does a workspace exist within the group or any groups within this group.
void reportMembers(std::set< Workspace_sptr > &memberList) const
Add the members of the group to the given list.
std::vector< Workspace_sptr > m_workspaces
The list of workspace pointers in the group.
bool isInChildGroup(const Workspace &workspaceToCheck) const
Check if a workspace is included in any child groups and groups in them.
std::vector< std::string > getNames() const
Returns the names of workspaces that make up this group.
std::recursive_mutex m_mutex
Recursive mutex to avoid simultaneous access.
void sortMembersByName()
Sort the internal data structure according to member name.
void workspaceBeforeReplaceHandle(Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice)
Callback when a before-replace notification is received.
void throwIndexOutOfRangeError(int index) const
Throws an out_of_range error for an invalid index.
bool isMultiperiod() const
Inidicates that the workspace group can be treated as multiperiod.
bool areNamesSimilar() const
Are the members of this group of similar names, e.g.
bool isInGroup(const Workspace &workspaceToCheck, size_t level=0) const
Check if a workspace is included in this group or any nested groups.
size_t size() const
Return the size of the group, so it is more like a container.
Base Workspace Abstract Class.
const std::string & getName() const override
Get the workspace name.
Exception for when an item is not found in a collection.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
The concrete, templated class for properties.
Base class for properties.
virtual std::string value() const =0
Returns the value of the property as a string.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< const WorkspaceGroup > WorkspaceGroup_const_sptr
shared pointer to Mantid::API::WorkspaceGroup, pointer to const version
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::BeforeReplaceNotification > & WorkspaceBeforeReplaceNotification_ptr
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
const Poco::AutoPtr< Mantid::Kernel::DataService< Mantid::API::Workspace >::PostDeleteNotification > & WorkspacePostDeleteNotification_ptr
int convert(const std::string &A, T &out)
Convert a string into a number.