Skip to content

Commit

Permalink
Fixed bug with data service creating multiple workspace references
Browse files Browse the repository at this point in the history
Refs #7807
  • Loading branch information
Samuel Jackson committed Aug 28, 2013
1 parent 2d778cc commit 4c63d9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
16 changes: 7 additions & 9 deletions Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
Expand Up @@ -290,15 +290,13 @@ void WorkspaceGroup::workspaceReplaceHandle(Mantid::API::WorkspaceBeforeReplaceN
bool isObserving = m_observingADS;
if ( isObserving )
observeADSNotifications( false );
const std::string replacedName = notice->object_name();
for(auto citr=m_workspaces.begin(); citr!=m_workspaces.end(); ++citr)
{
if ( (**citr).name() == replacedName )
{
*citr = notice->new_object();
break;
}
}

//remove any workspace that already exists with the name
this->remove(notice->object_name());

//replace the object in the group
this->addWorkspace(notice->new_object());

if ( isObserving )
observeADSNotifications( true );
}
Expand Down
25 changes: 5 additions & 20 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/DataService.h
Expand Up @@ -278,7 +278,7 @@ class DLLExport DataService
{
checkForEmptyName(newName);

// Make DataService access thread-safe
auto item = this->retrieve(oldName);
m_mutex.lock();

std::string foundName;
Expand All @@ -290,29 +290,14 @@ class DLLExport DataService
return;
}

// delete the object with the old name
// delete the object with the old name silently
auto object = it->second;
datamap.erase( it );
datamap.erase(it);

// if there is another object which has newName delete it
it = datamap.find( newName );
if ( it != datamap.end() )
{
notificationCenter.postNotification(new AfterReplaceNotification(newName,object));
datamap.erase( it );
}
m_mutex.unlock();

// insert the old object with the new name
if ( ! datamap.insert(typename svcmap::value_type(newName, object)).second )
{
std::string error=" add : Unable to insert Data Object : '"+newName+"'";
g_log.error(error);
m_mutex.unlock();
throw std::runtime_error(error);
}
g_log.information("Data Object '"+ foundName +"' renamed to '" + newName + "'");
this->addOrReplace(newName,item);

m_mutex.unlock();
notificationCenter.postNotification(new RenameNotification(oldName, newName));

return;
Expand Down

0 comments on commit 4c63d9a

Please sign in to comment.