Mantid
|
Class to hold a set of workspaces. More...
#include <WorkspaceGroup.h>
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_sptr > | getAllItems () 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 WorkspaceHistory & | getHistory () 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... | |
WorkspaceHistory & | history () |
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 |
Workspace & | operator= (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::WorkspacePostDeleteNotification > | m_deleteObserver |
Observer for workspace delete notifications. More... | |
Poco::NObserver< WorkspaceGroup, Mantid::API::WorkspaceBeforeReplaceNotification > | m_beforeReplaceObserver |
Observer for workspace before-replace notifications. More... | |
std::vector< Workspace_sptr > | m_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 | |
WorkspaceGroup & | operator= (const WorkspaceGroup &)=delete |
WorkspaceGroup * | doClone () const override |
Virtual clone method. Not implemented to force implementation in children. More... | |
WorkspaceGroup * | doCloneEmpty () 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... | |
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.
Definition at line 37 of file WorkspaceGroup.h.
Mantid::API::WorkspaceGroup::WorkspaceGroup | ( | const Parallel::StorageMode | storageMode = Parallel::StorageMode::Cloned | ) |
Default constructor.
Definition at line 23 of file WorkspaceGroup.cpp.
|
override |
|
delete |
|
inline |
Adds a workspace to the group.
Definition at line 101 of file WorkspaceGroup.h.
References getName().
Referenced by addItem().
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
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().
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.
Definition at line 400 of file WorkspaceGroup.cpp.
References Mantid::API::Workspace::getName(), m_mutex, m_workspaces, and workspace.
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.
Definition at line 268 of file WorkspaceGroup.cpp.
References m_workspaces.
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.
Definition at line 276 of file WorkspaceGroup.cpp.
References m_workspaces.
bool Mantid::API::WorkspaceGroup::contains | ( | const std::string & | wsName | ) | const |
Does a workspace exist within the group.
Does this group contain the named workspace?
wsName | :: A string to compare |
Definition at line 145 of file WorkspaceGroup.cpp.
References m_mutex, m_workspaces, and workspace.
Referenced by export_WorkspaceGroup(), and workspaceDeleteHandle().
bool Mantid::API::WorkspaceGroup::contains | ( | const Workspace_sptr & | workspace | ) | const |
Does a workspace exist within the group.
workspace | A pointer to a workspace |
Definition at line 155 of file WorkspaceGroup.cpp.
References m_mutex, m_workspaces, and workspace.
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?
wsName | :: A string to compare |
Definition at line 123 of file WorkspaceGroup.cpp.
References m_mutex, m_workspaces, and workspace.
|
inlineoverrideprivatevirtual |
Virtual clone method. Not implemented to force implementation in children.
Implements Mantid::API::Workspace.
Definition at line 122 of file WorkspaceGroup.h.
|
inlineoverrideprivatevirtual |
Virtual cloneEmpty method.
Not implemented to force implementation in children.
Implements Mantid::API::Workspace.
Definition at line 125 of file WorkspaceGroup.h.
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.
Definition at line 284 of file WorkspaceGroup.cpp.
References m_workspaces.
Referenced by group_end().
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.
Definition at line 292 of file WorkspaceGroup.cpp.
References m_workspaces.
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.
Workspace_sptr Mantid::API::WorkspaceGroup::getItem | ( | const size_t | index | ) | const |
Return the ith workspace.
index | The index within the group |
an | out_of_range error if the index is invalid |
Definition at line 192 of file WorkspaceGroup.cpp.
References index, m_mutex, m_workspaces, size(), and throwIndexOutOfRangeError().
Referenced by Mantid::DataHandling::MultiPeriodLoadMuonStrategy::applyTimeZeroCorrection(), getItem(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::getLoadedDetectors(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::getTimeZeroTable(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadDetectorGrouping(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadGoodFrames(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadMuonLogData(), and Mantid::Algorithms::CalculateEfficiency2::mergeGroup().
Workspace_sptr Mantid::API::WorkspaceGroup::getItem | ( | const std::string & | wsName | ) | const |
Return the workspace by name.
wsName | The name of the workspace |
an | out_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.
|
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.
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().
|
inline |
Return the number of entries within the group.
Definition at line 55 of file WorkspaceGroup.h.
Referenced by Mantid::DataHandling::MultiPeriodLoadMuonStrategy::applyTimeZeroCorrection(), export_WorkspaceGroup(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadDeadTimeTable(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadDetectorGrouping(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadGoodFrames(), Mantid::DataHandling::MultiPeriodLoadMuonStrategy::loadMuonLogData(), and Mantid::Algorithms::CalculateEfficiency2::mergeGroup().
|
inlineoverridevirtual |
Return a string ID of the class.
Implements Mantid::Kernel::DataItem.
Definition at line 44 of file WorkspaceGroup.h.
Referenced by toString().
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.
Definition at line 388 of file WorkspaceGroup.cpp.
References m_mutex, and m_workspaces.
Referenced by Mantid::Algorithms::DeleteWorkspace::checkGroups(), and workspaceDeleteHandle().
|
inlineoverridevirtual |
Reimplemented from Mantid::API::Workspace.
Definition at line 68 of file WorkspaceGroup.h.
|
private |
Check if a workspace is included in any child groups and groups in them.
workspaceToCheck | :: A workspace to check. |
Definition at line 74 of file WorkspaceGroup.cpp.
References m_mutex, m_workspaces, and workspace.
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.
workspaceToCheck | :: A workspace to check. |
level | :: The current nesting level. Intended for internal use only by WorkspaceGroup. |
Definition at line 465 of file WorkspaceGroup.cpp.
References m_mutex, m_workspaces, and workspace.
bool Mantid::API::WorkspaceGroup::isMultiperiod | ( | ) | const |
Inidicates that the workspace group can be treated as multiperiod.
Determine in the WorkspaceGroup 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().
|
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.
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().
|
delete |
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.
|
inline |
Remove a name from the group.
Definition at line 103 of file WorkspaceGroup.h.
References getName().
Referenced by removeItem().
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.
|
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.
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().
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
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().
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.
memberList |
Definition at line 166 of file WorkspaceGroup.cpp.
References m_mutex, and m_workspaces.
|
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().
|
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().
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().
void Mantid::API::WorkspaceGroup::throwIndexOutOfRangeError | ( | int | index | ) | const |
|
overridevirtual |
Returns a formatted string detailing the contents of the group.
The format is: ID – Name1 – Name2.
Implements Mantid::Kernel::DataItem.
Definition at line 38 of file WorkspaceGroup.cpp.
References id(), m_mutex, m_workspaces, and workspace.
|
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.
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.
|
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.
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().
|
friend |
Definition at line 154 of file WorkspaceGroup.h.
|
friend |
Definition at line 153 of file WorkspaceGroup.h.
|
private |
Observer for workspace before-replace notifications.
Definition at line 145 of file WorkspaceGroup.h.
Referenced by observeADSNotifications().
|
private |
Observer for workspace delete notifications.
Definition at line 143 of file WorkspaceGroup.h.
Referenced by observeADSNotifications().
|
mutableprivate |
Recursive mutex to avoid simultaneous access.
Definition at line 151 of file WorkspaceGroup.h.
Referenced by addWorkspace(), areNamesSimilar(), contains(), containsInChildren(), getAllItems(), getItem(), getNames(), isEmpty(), isInChildGroup(), isInGroup(), isMultiperiod(), print(), removeByADS(), removeItem(), reportMembers(), toString(), workspaceBeforeReplaceHandle(), and workspaceDeleteHandle().
|
private |
Flag as to whether the observers have been added to the ADS.
Definition at line 149 of file WorkspaceGroup.h.
Referenced by observeADSNotifications().
|
private |
The list of workspace pointers in the group.
Definition at line 147 of file WorkspaceGroup.h.
Referenced by addWorkspace(), areNamesSimilar(), begin(), contains(), containsInChildren(), end(), getAllItems(), getItem(), getMemorySize(), getNames(), isEmpty(), isInChildGroup(), isInGroup(), isMultiperiod(), print(), removeAll(), removeByADS(), removeItem(), reportMembers(), sortMembersByName(), toString(), and workspaceBeforeReplaceHandle().