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

Wrapped ADS calls

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

Additional Inherited Members

- Protected Member Functions inherited from Mantid::API::Workspace
void setStorageMode (Parallel::StorageMode mode)
 Sets the storage mode (used for MPI runs) More...
 
 Workspace (const Workspace &)
 Protected copy constructor. May be used by childs for cloning. More...
 
- Protected Member Functions inherited from Mantid::Kernel::DataItem
Poco::RWLock * getLock () const
 Private method to access the RWLock object. More...
 

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 ( const Parallel::StorageMode  storageMode = Parallel::StorageMode::Cloned)

Default constructor.

Definition at line 23 of file WorkspaceGroup.cpp.

◆ ~WorkspaceGroup()

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

Destructor.

Definition at line 28 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 101 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 104 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 400 of file WorkspaceGroup.cpp.

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

◆ 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 268 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 276 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 145 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 155 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 123 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 122 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 125 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 284 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 292 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 218 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 205 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 483 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 176 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 388 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 68 of file WorkspaceGroup.h.

◆ 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 74 of file WorkspaceGroup.cpp.

References 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 465 of file WorkspaceGroup.cpp.

References m_mutex, m_workspaces, and workspace.

◆ isMultiperiod()

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

Inidicates 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 427 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 54 of file WorkspaceGroup.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), 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 244 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 103 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 225 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 231 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 300 of file WorkspaceGroup.cpp.

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

◆ 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 166 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 57 of file WorkspaceGroup.h.

Referenced by export_WorkspaceGroup(), getItem(), getItem(), removeItem(), sortMembersByName(), and throwIndexOutOfRangeError().

◆ sortByName()

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

Invokes the ADS to sort group members by workspace name.

Definition at line 98 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 90 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 256 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 38 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 352 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 324 of file WorkspaceGroup.cpp.

References contains(), Mantid::API::Workspace::getName(), Mantid::Kernel::SingletonHolder< T >::Instance(), isEmpty(), m_mutex, observeADSNotifications(), and removeByADS().

Friends And Related Function Documentation

◆ Algorithm

friend class Algorithm
friend

Definition at line 154 of file WorkspaceGroup.h.

◆ AnalysisDataServiceImpl

friend class AnalysisDataServiceImpl
friend

Definition at line 153 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 145 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 143 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 149 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: