Mantid
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Mantid::API::WorkspaceGroup Class Reference

Class to hold a set of workspaces. More...

#include <WorkspaceGroup.h>

Inheritance diagram for Mantid::API::WorkspaceGroup:
Mantid::API::Workspace Mantid::Kernel::DataItem

Public Member Functions

void addWorkspace (const Workspace_sptr &workspace)
 Adds a workspace to the group.
 
bool areNamesSimilar () const
 Are the members of this group of similar names, e.g.
 
std::vector< Workspace_sptr >::iterator begin ()
 Returns a non-const iterator pointing at the first element in the workspace group.
 
std::vector< Workspace_sptr >::const_iterator begin () const
 Returns a const iterator pointing at the first element in the workspace group.
 
std::vector< Workspace_sptr >::iterator end ()
 Returns a non-const iterator pointing at the last element in the workspace group.
 
std::vector< Workspace_sptr >::const_iterator end () const
 Returns a const iterator pointing at the last element in the workspace group.
 
std::vector< Workspace_sptrgetAllItems () const
 Return all workspaces in the group as one call for thread safety.
 
Workspace_sptr getItem (const size_t index) const
 Return the ith workspace.
 
Workspace_sptr getItem (const std::string &wsName) const
 Return the workspace by name.
 
size_t getMemorySize () const override
 Return the memory size of all workspaces in this group and subgroups.
 
int getNumberOfEntries () const
 Return the number of entries within the group.
 
const std::string id () const override
 Return a string ID of the class.
 
bool isEmpty () const
 This method returns true if the group is empty (no member workspace)
 
bool isGroup () const override
 
bool isGroupPeaksWorkspaces () const
 Check if the workspace group contains just peak workspaces.
 
bool isInGroup (const Workspace &workspaceToCheck, size_t level=0) const
 Check if a workspace is included in this group or any nested groups.
 
bool isMultiperiod () const
 Indicates that the workspace group can be treated as multiperiod.
 
void print () const
 Prints the group to the screen using the logger at debug.
 
void removeAll ()
 Remove all names from the group but do not touch the ADS.
 
void removeItem (const size_t index)
 Remove a workspace from the group.
 
void reorderMembersWithIndices (const std::vector< int > &indices)
 Reorder the group members using a list of indices (e.g the list 4,3,2,1 would reverse the order)
 
size_t size () const
 Return the size of the group, so it is more like a container.
 
void sortMembersByName ()
 Sort the internal data structure according to member name.
 
void throwIndexOutOfRangeError (int index) const
 Throws an out_of_range error for an invalid index.
 
const std::string toString () const override
 Returns a formatted string detailing the contents of the group.
 
 WorkspaceGroup ()
 Default constructor.
 
 ~WorkspaceGroup () override
 Destructor.
 
- Public Member Functions inherited from Mantid::API::Workspace
Workspace_uptr clone () const
 Returns a clone (copy) of the workspace with covariant return type in all derived classes.
 
Workspace_uptr cloneEmpty () const
 Returns a default-initialized clone of the workspace.
 
const std::string & getComment () const
 Get the workspace comment.
 
const WorkspaceHistorygetHistory () const
 Returns a reference to the WorkspaceHistory const.
 
std::string getMemorySizeAsStr () const
 Returns the memory footprint in sensible units.
 
const std::string & getName () const override
 Get the workspace name.
 
const std::string & getPythonVariableName () const
 
virtual const std::string getTitle () const
 Get the workspace title.
 
WorkspaceHistoryhistory ()
 Returns a reference to the WorkspaceHistory.
 
bool isDirty (const int n=1) const
 Check whether other algorithms have been applied to the workspace by checking the history length.
 
Workspaceoperator= (const Workspace &other)=delete
 
void setComment (const std::string &)
 Set the comment field of the workspace.
 
void setPythonVariableName (const std::string &)
 
virtual void setTitle (const std::string &)
 Set the title of the workspace.
 
bool threadSafe () const override
 Marks the workspace as safe for multiple threads to edit data simutaneously.
 
 Workspace ()
 
 ~Workspace ()
 
- Public Member Functions inherited from Mantid::Kernel::DataItem
 DataItem ()
 Default constructor.
 
 DataItem (const DataItem &other)
 Copy constructor Always makes a unique lock.
 
virtual ~DataItem ()
 Destructor.
 
void readLock ()
 Acquires a read lock.
 
void unlock ()
 

Wrapped ADS calls

Poco::NObserver< WorkspaceGroup, Mantid::API::WorkspacePostDeleteNotificationm_deleteObserver
 Observer for workspace delete notifications.
 
Poco::NObserver< WorkspaceGroup, Mantid::API::WorkspaceBeforeReplaceNotificationm_beforeReplaceObserver
 Observer for workspace before-replace notifications.
 
std::vector< Workspace_sptrm_workspaces
 The list of workspace pointers in the group.
 
bool m_observingADS
 Flag as to whether the observers have been added to the ADS.
 
std::recursive_mutex m_mutex
 Recursive mutex to avoid simultaneous access.
 
class AnalysisDataServiceImpl
 
class Algorithm
 
void sortByName ()
 Invokes the ADS to sort group members by workspace name.
 
void add (const std::string &wsName)
 Adds a workspace to the group.
 
void remove (const std::string &wsName)
 Remove a name from the group.
 
bool containsInChildren (const std::string &wsName) const
 Does a workspace exist within the group or any groups within this group.
 
bool contains (const std::string &wsName) const
 Does a workspace exist within the group.
 
bool contains (const Workspace_sptr &workspace) const
 Does a workspace exist within the group.
 
void reportMembers (std::set< Workspace_sptr > &memberList) const
 Add the members of the group to the given list.
 
std::vector< std::string > getNames () const
 Returns the names of workspaces that make up this group.
 
 WorkspaceGroup (const WorkspaceGroup &ref)=delete
 
WorkspaceGroupoperator= (const WorkspaceGroup &)=delete
 
WorkspaceGroupdoClone () const override
 Virtual clone method. Not implemented to force implementation in children.
 
WorkspaceGroupdoCloneEmpty () const override
 Virtual cloneEmpty method.
 
void removeByADS (const std::string &wsName)
 ADS removes a member of this group using this method.
 
void observeADSNotifications (const bool observeADS)
 Turn ADS observations on/off.
 
bool isInChildGroup (const Workspace &workspaceToCheck) const
 Check if a workspace is included in any child groups and groups in them.
 
void workspaceDeleteHandle (Mantid::API::WorkspacePostDeleteNotification_ptr notice)
 Callback when a delete notification is received.
 
void workspaceBeforeReplaceHandle (Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice)
 Callback when a before-replace notification is received.
 

Additional Inherited Members

- Protected Member Functions inherited from Mantid::API::Workspace
 Workspace (const Workspace &)
 Protected copy constructor. May be used by childs for cloning.
 
- Protected Member Functions inherited from Mantid::Kernel::DataItem
Poco::RWLock * getLock () const
 Private method to access the RWLock object.
 

Detailed Description

Class to hold a set of workspaces.

The workspace group can be an entry in the AnalysisDataService. Its constituent workspaces should also have individual ADS entries. Workspace groups can be used in algorithms in the same way as single workspaces.

Author
Sofia Antony, ISIS, RAL
Date
12/06/2009

Definition at line 37 of file WorkspaceGroup.h.

Constructor & Destructor Documentation

◆ WorkspaceGroup() [1/2]

Mantid::API::WorkspaceGroup::WorkspaceGroup ( )

Default constructor.

Definition at line 24 of file WorkspaceGroup.cpp.

◆ ~WorkspaceGroup()

Mantid::API::WorkspaceGroup::~WorkspaceGroup ( )
override

Destructor.

Definition at line 29 of file WorkspaceGroup.cpp.

References observeADSNotifications().

◆ WorkspaceGroup() [2/2]

Mantid::API::WorkspaceGroup::WorkspaceGroup ( const WorkspaceGroup ref)
delete

Member Function Documentation

◆ add()

void Mantid::API::WorkspaceGroup::add ( const std::string &  wsName)
inline

Adds a workspace to the group.

Definition at line 105 of file WorkspaceGroup.h.

References getName().

Referenced by addItem().

◆ addWorkspace()

void Mantid::API::WorkspaceGroup::addWorkspace ( const Workspace_sptr workspace)

Adds a workspace to the group.

The workspace does not have to be in the ADS

Parameters
workspace:: A shared pointer to a workspace to add. If the workspace already exists give a warning.

Definition at line 132 of file WorkspaceGroup.cpp.

References Mantid::API::g_log, m_mutex, m_workspaces, Mantid::Kernel::Logger::warning(), and workspace.

Referenced by addWorkspace(), and Mantid::CurveFitting::FuncMinimisers::FABADAMinimizer::outputPDF().

◆ areNamesSimilar()

bool Mantid::API::WorkspaceGroup::areNamesSimilar ( ) const

Are the members of this group of similar names, e.g.

for a WorkspaceGroup names "groupname", the members are "groupname_1", "groupname_2", etc.

Returns
true if the names match this pattern.

Definition at line 425 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

Referenced by Mantid::API::Algorithm::checkGroups().

◆ begin() [1/2]

std::vector< Workspace_sptr >::iterator Mantid::API::WorkspaceGroup::begin ( )

Returns a non-const iterator pointing at the first element in the workspace group.

Returns an iterator pointing to the first element in the group.

Returns
A non-const iterator pointing to the first workspace in this workspace group.

Definition at line 293 of file WorkspaceGroup.cpp.

References m_workspaces.

◆ begin() [2/2]

std::vector< Workspace_sptr >::const_iterator Mantid::API::WorkspaceGroup::begin ( ) const

Returns a const iterator pointing at the first element in the workspace group.

Returns a const iterator pointing to the first element in the group.

Returns
A const iterator pointing to the first workspace in this workspace group.

Definition at line 301 of file WorkspaceGroup.cpp.

References m_workspaces.

◆ contains() [1/2]

bool Mantid::API::WorkspaceGroup::contains ( const std::string &  wsName) const

Does a workspace exist within the group.

Does this group contain the named workspace?

Parameters
wsName:: A string to compare
Returns
True if the name is part of this group, false otherwise

Definition at line 170 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

Referenced by export_WorkspaceGroup(), and workspaceDeleteHandle().

◆ contains() [2/2]

bool Mantid::API::WorkspaceGroup::contains ( const Workspace_sptr workspace) const

Does a workspace exist within the group.

Parameters
workspaceA pointer to a workspace
Returns
True if the workspace exists in the group, false otherwise

Definition at line 180 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

◆ containsInChildren()

bool Mantid::API::WorkspaceGroup::containsInChildren ( const std::string &  wsName) const

Does a workspace exist within the group or any groups within this group.

Does this group or any of it's child groups contain the named workspace?

Parameters
wsName:: A string to compare
Returns
True if the name is part of this group, false otherwise

Definition at line 151 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

◆ doClone()

WorkspaceGroup * Mantid::API::WorkspaceGroup::doClone ( ) const
inlineoverrideprivatevirtual

Virtual clone method. Not implemented to force implementation in children.

Implements Mantid::API::Workspace.

Definition at line 126 of file WorkspaceGroup.h.

◆ doCloneEmpty()

WorkspaceGroup * Mantid::API::WorkspaceGroup::doCloneEmpty ( ) const
inlineoverrideprivatevirtual

Virtual cloneEmpty method.

Not implemented to force implementation in children.

Implements Mantid::API::Workspace.

Definition at line 129 of file WorkspaceGroup.h.

◆ end() [1/2]

std::vector< Workspace_sptr >::iterator Mantid::API::WorkspaceGroup::end ( )

Returns a non-const iterator pointing at the last element in the workspace group.

Returns an iterator pointing to the past-the-end element in the group.

Returns
A non-const iterator pointing to the last workspace in this workspace group.

Definition at line 309 of file WorkspaceGroup.cpp.

References m_workspaces.

Referenced by group_end().

◆ end() [2/2]

std::vector< Workspace_sptr >::const_iterator Mantid::API::WorkspaceGroup::end ( ) const

Returns a const iterator pointing at the last element in the workspace group.

Returns a const iterator pointing to the past-the-end element in the group.

Returns
A const iterator pointing to the last workspace in this workspace group.

Definition at line 317 of file WorkspaceGroup.cpp.

References m_workspaces.

◆ getAllItems()

std::vector< Workspace_sptr > Mantid::API::WorkspaceGroup::getAllItems ( ) const

Return all workspaces in the group as one call for thread safety.

Definition at line 243 of file WorkspaceGroup.cpp.

References m_mutex, and m_workspaces.

◆ getItem() [1/2]

Workspace_sptr Mantid::API::WorkspaceGroup::getItem ( const size_t  index) const

◆ getItem() [2/2]

Workspace_sptr Mantid::API::WorkspaceGroup::getItem ( const std::string &  wsName) const

Return the workspace by name.

Parameters
wsNameThe name of the workspace
Exceptions
anout_of_range error if the workspace's name not contained in the group's list of workspace names

Definition at line 230 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

◆ getMemorySize()

size_t Mantid::API::WorkspaceGroup::getMemorySize ( ) const
overridevirtual

Return the memory size of all workspaces in this group and subgroups.

Implements Mantid::API::Workspace.

Definition at line 516 of file WorkspaceGroup.cpp.

References m_workspaces, and workspace.

◆ getNames()

std::vector< std::string > Mantid::API::WorkspaceGroup::getNames ( ) const

Returns the names of workspaces that make up this group.

Note that this returns a copy as the internal vector can mutate while the vector is being iterated over.

Definition at line 201 of file WorkspaceGroup.cpp.

References m_mutex, and m_workspaces.

Referenced by Mantid::DataHandling::LoadFITS::doLoadFiles(), Mantid::MDAlgorithms::MergeMD::exec(), export_WorkspaceGroup(), and Mantid::Algorithms::RunCombinationHelper::unWrapGroups().

◆ getNumberOfEntries()

int Mantid::API::WorkspaceGroup::getNumberOfEntries ( ) const
inline

◆ id()

const std::string Mantid::API::WorkspaceGroup::id ( ) const
inlineoverridevirtual

Return a string ID of the class.

Implements Mantid::Kernel::DataItem.

Definition at line 44 of file WorkspaceGroup.h.

Referenced by toString().

◆ isEmpty()

bool Mantid::API::WorkspaceGroup::isEmpty ( ) const

This method returns true if the group is empty (no member workspace)

This method returns true if the workspace group is empty.

Returns
true if workspace is empty

Definition at line 413 of file WorkspaceGroup.cpp.

References m_mutex, and m_workspaces.

Referenced by Mantid::Algorithms::DeleteWorkspace::checkGroups(), and workspaceDeleteHandle().

◆ isGroup()

bool Mantid::API::WorkspaceGroup::isGroup ( ) const
inlineoverridevirtual

Reimplemented from Mantid::API::Workspace.

Definition at line 70 of file WorkspaceGroup.h.

◆ isGroupPeaksWorkspaces()

bool Mantid::API::WorkspaceGroup::isGroupPeaksWorkspaces ( ) const

Check if the workspace group contains just peak workspaces.

Returns
:: True if all of the workspaces in the group are peak workspaces

Definition at line 486 of file WorkspaceGroup.cpp.

References m_workspaces.

◆ isInChildGroup()

bool Mantid::API::WorkspaceGroup::isInChildGroup ( const Workspace workspaceToCheck) const
private

Check if a workspace is included in any child groups and groups in them.

Parameters
workspaceToCheck:: A workspace to check.
Returns
:: True if the workspace is found.

Definition at line 75 of file WorkspaceGroup.cpp.

References group, m_mutex, m_workspaces, and workspace.

◆ isInGroup()

bool Mantid::API::WorkspaceGroup::isInGroup ( const Workspace workspaceToCheck,
size_t  level = 0 
) const

Check if a workspace is included in this group or any nested groups.

Parameters
workspaceToCheck:: A workspace to check.
level:: The current nesting level. Intended for internal use only by WorkspaceGroup.
Returns
:: True if the worspace is found in any of the nested groups in this group.

Definition at line 498 of file WorkspaceGroup.cpp.

References group, m_mutex, m_workspaces, and workspace.

◆ isMultiperiod()

bool Mantid::API::WorkspaceGroup::isMultiperiod ( ) const

Indicates that the workspace group can be treated as multiperiod.

Determine in the WorkspaceGroup is multiperiod.

Returns
True if the WorkspaceGroup instance is multiperiod.

Definition at line 452 of file WorkspaceGroup.cpp.

References Mantid::Kernel::Strings::convert(), Mantid::Kernel::Logger::debug(), Mantid::API::g_log, m_mutex, m_workspaces, Mantid::Kernel::Property::value(), and workspace.

Referenced by export_WorkspaceGroup().

◆ observeADSNotifications()

void Mantid::API::WorkspaceGroup::observeADSNotifications ( const bool  observeADS)
private

Turn ADS observations on/off.

Turn on/off observing delete and rename notifications to update the group accordingly It can be useful to turn them off when constructing the group.

Parameters
observeADS:: If true observe the ADS notifications, otherwise disable them

Definition at line 55 of file WorkspaceGroup.cpp.

References m_beforeReplaceObserver, m_deleteObserver, and m_observingADS.

Referenced by workspaceDeleteHandle(), and ~WorkspaceGroup().

◆ operator=()

WorkspaceGroup & Mantid::API::WorkspaceGroup::operator= ( const WorkspaceGroup )
delete

◆ print()

void Mantid::API::WorkspaceGroup::print ( ) const

Prints the group to the screen using the logger at debug.

Print the names of all the workspaces in this group to the logger (at debug level)

Definition at line 269 of file WorkspaceGroup.cpp.

References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, m_mutex, m_workspaces, and workspace.

◆ remove()

void Mantid::API::WorkspaceGroup::remove ( const std::string &  wsName)
inline

Remove a name from the group.

Definition at line 107 of file WorkspaceGroup.h.

References getName().

Referenced by removeItem().

◆ removeAll()

void Mantid::API::WorkspaceGroup::removeAll ( )

Remove all names from the group but do not touch the ADS.

Empty all the entries out of the workspace group.

Does not remove the workspaces from the ADS.

Definition at line 250 of file WorkspaceGroup.cpp.

References m_workspaces.

◆ removeByADS()

void Mantid::API::WorkspaceGroup::removeByADS ( const std::string &  wsName)
private

ADS removes a member of this group using this method.

Remove the named workspace from the group.

It doesn't send notifications in contrast to remove(name).

Does not delete the workspace from the AnalysisDataService.

Parameters
wsName:: The name of the workspace to be removed from the group.

Definition at line 256 of file WorkspaceGroup.cpp.

References m_mutex, and m_workspaces.

Referenced by workspaceDeleteHandle().

◆ removeItem()

void Mantid::API::WorkspaceGroup::removeItem ( const size_t  index)

Remove a workspace from the group.

Remove a workspace pointed to by an index.

The workspace remains in the ADS if it was there

Parameters
index:: Index of a workspace to delete.

Definition at line 325 of file WorkspaceGroup.cpp.

References Mantid::API::Workspace::getName(), index, m_mutex, m_workspaces, and size().

◆ reorderMembersWithIndices()

void Mantid::API::WorkspaceGroup::reorderMembersWithIndices ( const std::vector< int > &  indices)

Reorder the group members using a list of indices (e.g the list 4,3,2,1 would reverse the order)

Reorder the group members using a list of indices (e.g the list 3,2,1,0 would reverse the order)

Definition at line 102 of file WorkspaceGroup.cpp.

References Mantid::API::g_log, m_workspaces, and Mantid::Kernel::Logger::warning().

Referenced by reorder().

◆ reportMembers()

void Mantid::API::WorkspaceGroup::reportMembers ( std::set< Workspace_sptr > &  memberList) const

Add the members of the group to the given list.

Adds the current workspace members to the given list.

Parameters
memberList

Definition at line 191 of file WorkspaceGroup.cpp.

References m_mutex, and m_workspaces.

◆ size()

size_t Mantid::API::WorkspaceGroup::size ( ) const
inline

Return the size of the group, so it is more like a container.

Definition at line 59 of file WorkspaceGroup.h.

Referenced by export_WorkspaceGroup(), getItem(), getItem(), removeItem(), sortMembersByName(), throwIndexOutOfRangeError(), and Mantid::DataHandling::SaveReflectometryAscii::validateInputs().

◆ sortByName()

void Mantid::API::WorkspaceGroup::sortByName ( )
inline

Invokes the ADS to sort group members by workspace name.

Definition at line 102 of file WorkspaceGroup.h.

References getName().

Referenced by export_WorkspaceGroup().

◆ sortMembersByName()

void Mantid::API::WorkspaceGroup::sortMembersByName ( )

Sort the internal data structure according to member name.

Sort members by Workspace name.

Definition at line 91 of file WorkspaceGroup.cpp.

References m_workspaces, and size().

◆ throwIndexOutOfRangeError()

void Mantid::API::WorkspaceGroup::throwIndexOutOfRangeError ( int  index) const

Throws an out_of_range error for an invalid index.

Definition at line 281 of file WorkspaceGroup.cpp.

References index, and size().

Referenced by getItem(), and getItem().

◆ toString()

const std::string Mantid::API::WorkspaceGroup::toString ( ) const
overridevirtual

Returns a formatted string detailing the contents of the group.

The format is: ID – Name1 – Name2.

Returns
A formatted human-readable string specifying the contents of the group

Implements Mantid::Kernel::DataItem.

Definition at line 39 of file WorkspaceGroup.cpp.

References id(), m_mutex, m_workspaces, and workspace.

◆ workspaceBeforeReplaceHandle()

void Mantid::API::WorkspaceGroup::workspaceBeforeReplaceHandle ( Mantid::API::WorkspaceBeforeReplaceNotification_ptr  notice)
private

Callback when a before-replace notification is received.

Callback when a before-replace notification is received Replaces a member if it was replaced in the ADS and checks for duplicate members within the group.

Parameters
notice:: A pointer to a workspace before-replace notification object

Definition at line 377 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

◆ workspaceDeleteHandle()

void Mantid::API::WorkspaceGroup::workspaceDeleteHandle ( Mantid::API::WorkspacePostDeleteNotification_ptr  notice)
private

Callback when a delete notification is received.

Callback for a workspace delete notification.

Removes any deleted entries from the group. This also deletes the workspace group when the last member of it gets deleted.

Parameters
notice:: A pointer to a workspace delete notificiation object

Definition at line 349 of file WorkspaceGroup.cpp.

References contains(), Mantid::API::Workspace::getName(), isEmpty(), m_mutex, observeADSNotifications(), and removeByADS().

Friends And Related Symbol Documentation

◆ Algorithm

friend class Algorithm
friend

Definition at line 158 of file WorkspaceGroup.h.

◆ AnalysisDataServiceImpl

friend class AnalysisDataServiceImpl
friend

Definition at line 157 of file WorkspaceGroup.h.

Member Data Documentation

◆ m_beforeReplaceObserver

Poco::NObserver<WorkspaceGroup, Mantid::API::WorkspaceBeforeReplaceNotification> Mantid::API::WorkspaceGroup::m_beforeReplaceObserver
private

Observer for workspace before-replace notifications.

Definition at line 149 of file WorkspaceGroup.h.

Referenced by observeADSNotifications().

◆ m_deleteObserver

Poco::NObserver<WorkspaceGroup, Mantid::API::WorkspacePostDeleteNotification> Mantid::API::WorkspaceGroup::m_deleteObserver
private

Observer for workspace delete notifications.

Definition at line 147 of file WorkspaceGroup.h.

Referenced by observeADSNotifications().

◆ m_mutex

std::recursive_mutex Mantid::API::WorkspaceGroup::m_mutex
mutableprivate

◆ m_observingADS

bool Mantid::API::WorkspaceGroup::m_observingADS
private

Flag as to whether the observers have been added to the ADS.

Definition at line 153 of file WorkspaceGroup.h.

Referenced by observeADSNotifications().

◆ m_workspaces

std::vector<Workspace_sptr> Mantid::API::WorkspaceGroup::m_workspaces
private

The documentation for this class was generated from the following files: