Example #1
0
/**
 * Overwridden add member to attach the name to the workspace when a workspace
 * object is added to the service
 * If the name already exists then this throws a std::runtime_error. If a
 * workspace group is added adds the
 * members which are not in the ADS yet.
 * @param name The name of the object
 * @param workspace The shared pointer to the workspace to store
 */
void AnalysisDataServiceImpl::add(
    const std::string &name,
    const boost::shared_ptr<API::Workspace> &workspace) {
  verifyName(name);
  // Attach the name to the workspace
  if (workspace)
    workspace->setName(name);
  Kernel::DataService<API::Workspace>::add(name, workspace);

  // if a group is added add its members as well
  auto group = boost::dynamic_pointer_cast<WorkspaceGroup>(workspace);
  if (!group)
    return;
  group->observeADSNotifications(true);
  for (size_t i = 0; i < group->size(); ++i) {
    auto ws = group->getItem(i);
    std::string wsName = ws->name();
    // if anonymous make up a name and add
    if (wsName.empty()) {
      wsName = name + "_" + boost::lexical_cast<std::string>(i + 1);
    } else if (doesExist(wsName)) { // if ws is already there do nothing
      wsName.clear();
    }
    // add member workspace if needed
    if (!wsName.empty()) {
      add(wsName, ws);
    }
  }
}
Example #2
0
/** 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
 *deteleted.
 *
 * @param notice :: A pointer to a workspace delete notificiation object
 */
void WorkspaceGroup::workspaceDeleteHandle(
    Mantid::API::WorkspacePostDeleteNotification_ptr notice) {
  std::unique_lock<std::recursive_mutex> _lock(m_mutex);
  const std::string deletedName = notice->objectName();
  if (!this->contains(deletedName))
    return;

  if (deletedName != this->getName()) {
    this->removeByADS(deletedName);
    if (isEmpty()) {
      // We are about to get deleted so we don't want to recieve any
      // notifications
      // The unique lock needs to be unlocked at this point as the workspace
      // is about to destroy itself. We have to make sure that the mutex is
      // not locked.
      _lock.unlock();
      observeADSNotifications(false);
      AnalysisDataService::Instance().remove(this->getName());
    }
  }
}
Example #3
0
WorkspaceGroup::~WorkspaceGroup() { observeADSNotifications(false); }