27 return std::dynamic_pointer_cast<const WorkspaceGroup>(this->
object());
45 const size_t length = name.size();
46 for (
size_t i = 0; i < length; ++i) {
47 if (illegal.find_first_of(name[i]) != std::string::npos) {
48 std::ostringstream strm;
49 strm <<
"Invalid object name '" << name <<
"'. Names cannot contain any of the following characters: " << illegal;
67 auto group = std::dynamic_pointer_cast<WorkspaceGroup>(
workspace);
79 group->observeADSNotifications(
true);
80 for (
size_t i = 0; i < group->size(); ++i) {
81 auto ws = group->getItem(i);
82 std::string wsName = ws->getName();
90 if (!wsName.empty()) {
105 auto group = std::dynamic_pointer_cast<WorkspaceGroup>(
workspace);
115 group->observeADSNotifications(
true);
116 for (
size_t i = 0; i < group->size(); ++i) {
117 auto ws = group->getItem(i);
118 std::string wsName = ws->getName();
120 if (wsName.empty()) {
126 if (!wsName.empty()) {
140 auto oldWorkspace =
retrieve(oldName);
141 auto group = std::dynamic_pointer_cast<WorkspaceGroup>(oldWorkspace);
142 if (group && group->containsInChildren(newName)) {
143 throw std::invalid_argument(
"Unable to rename group as the new name matches its members");
149 ws->setName(newName);
181 bool unrollGroups)
const {
182 using WorkspacesVector = std::vector<Workspace_sptr>;
183 WorkspacesVector workspaces;
184 workspaces.reserve(names.size());
185 std::transform(std::begin(names), std::end(names), std::back_inserter(workspaces),
186 [
this](
const std::string &name) {
return this->
retrieve(name); });
187 assert(names.size() == workspaces.size());
189 using IteratorDifference = std::iterator_traits<WorkspacesVector::iterator>::difference_type;
191 bool done{workspaces.size() == 0};
194 if (
auto group = std::dynamic_pointer_cast<WorkspaceGroup>(workspaces.at(i))) {
195 const auto groupLength(group->size());
196 workspaces.erase(std::next(std::begin(workspaces),
static_cast<IteratorDifference
>(i)));
197 for (
size_t j = 0; j < groupLength; ++j) {
198 workspaces.insert(std::next(std::begin(workspaces),
static_cast<IteratorDifference
>(i + j)),
206 if (i == workspaces.size()) {
221 throw std::runtime_error(
"Workspace " + groupName +
" is not a workspace group.");
223 group->sortMembersByName();
235 throw std::runtime_error(
"Workspace " + groupName +
" is not a workspace group.");
238 if (groupName == wsName) {
239 throw std::runtime_error(
"The group name and workspace name are the same");
243 group->addWorkspace(ws);
254 throw std::runtime_error(
"Workspace " + name +
" is not a workspace group.");
256 group->observeADSNotifications(
false);
257 for (
size_t i = 0; i < group->size(); ++i) {
258 auto ws = group->getItem(i);
279 throw std::runtime_error(
"Workspace " + groupName +
" is not a workspace group.");
281 if (!group->contains(wsName)) {
282 throw std::runtime_error(
"WorkspaceGroup " + groupName +
" does not containt workspace " + wsName);
284 group->removeByADS(wsName);
294 std::map<std::string, Workspace_sptr> topLevel;
296 std::set<Workspace_sptr> groupMembers;
298 for (
const auto &topLevelName : topLevelNames) {
300 const std::string &name = topLevelName;
301 auto ws = this->
retrieve(topLevelName);
302 topLevel.emplace(name, ws);
303 if (
auto group = std::dynamic_pointer_cast<WorkspaceGroup>(ws)) {
304 group->reportMembers(groupMembers);
306 }
catch (
const std::exception &) {
311 for (
auto it = topLevel.begin(); it != topLevel.end();) {
313 if (groupMembers.count(item) == 1) {
314 topLevel.erase(it++);
365 if (!
error.empty()) {
366 throw std::invalid_argument(
error);
369 if (group && group->containsInChildren(name)) {
370 throw std::invalid_argument(
"Unable to add group as name matches its members");
IPeaksWorkspace_sptr workspace
GroupWorkspaces notification is send when a group is updated by adding or removing members.
std::shared_ptr< const WorkspaceGroup > getWorkspaceGroup() const
Returns the workspace pointer cast to WorkspaceGroup.
GroupUpdatedNotification(const std::string &name)
Constructor.
const std::string isValid(const std::string &name) const
Is the given name a valid name for an object in the ADS.
AnalysisDataServiceImpl()
Constructor.
void setIllegalCharacterList(const std::string &)
Set the list of illegal characters.
std::string m_illegalChars
The string of illegal characters.
const std::string & illegalCharacters() const
Return the list of illegal characters as one string.
virtual void rename(const std::string &oldName, const std::string &newName)
Overridden rename member to attach the new name to the workspace when a workspace object is renamed.
void add(const std::string &name, const std::shared_ptr< API::Workspace > &workspace) override
Overridden add member to attach the name to the workspace when a workspace object is added to the ser...
std::map< std::string, Workspace_sptr > topLevelItems() const
Return a lookup of the top level items.
void shutdown() override
Prepare for shutdown.
void sortGroupByName(const std::string &groupName)
Sort members by Workspace name.
void deepRemoveGroup(const std::string &name)
Remove a workspace group and all its members from the ADS.
virtual void remove(const std::string &name)
Overridden remove member to delete its name held by the workspace itself.
void addOrReplace(const std::string &name, const std::shared_ptr< API::Workspace > &workspace) override
Overridden addOrReplace member to attach the name to the workspace when a workspace object is added t...
void addToGroup(const std::string &groupName, const std::string &wsName)
Add a workspace to a group.
void verifyName(const std::string &name, const std::shared_ptr< API::WorkspaceGroup > &workspace)
Checks the name is valid, throwing if not.
std::vector< Workspace_sptr > retrieveWorkspaces(const std::vector< std::string > &names, bool unrollGroups=false) const
Given a list of names retrieve the corresponding workspace handles.
void removeFromGroup(const std::string &groupName, const std::string &wsName)
Remove a workspace from a group but not from the ADS.
Base Workspace Abstract Class.
DataService stores instances of a given type.
virtual void add(const std::string &name, const std::shared_ptr< T > &Tobject)
Add an object to the service.
bool doesExist(const std::string &name) const
Check to see if a data object exists in the store.
void rename(const std::string &oldName, const std::string &newName)
Rename an object within the service.
std::vector< std::string > getObjectNames(DataServiceSort sortState=DataServiceSort::Unsorted, DataServiceHidden hiddenState=DataServiceHidden::Auto, const std::string &contain="") const
Returns a vector of strings containing all object names in the ADS.
std::shared_ptr< API::Workspace > retrieve(const std::string &name) const
Get a shared pointer to a stored data object.
virtual void addOrReplace(const std::string &name, const std::shared_ptr< T > &Tobject)
Add or replace an object to the service.
Poco::NotificationCenter notificationCenter
Sends notifications to observers.
void remove(const std::string &name)
Remove an object from the service.
void clear()
Empty the service.
Exception for when an item is not found in a collection.
Manage the lifetime of a class intended to be a singleton.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Helper class which provides the Collimation Length for SANS instruments.
std::string to_string(const wide_integer< Bits, Signed > &n)