Skip to content

Commit

Permalink
Hidden observeADSnotifications switch in WorkspaceGroup. Re #7253.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jun 18, 2013
1 parent f1beb62 commit 1c5fb65
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
11 changes: 8 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace Kernel

namespace API
{
//----------------------------------------------------------------------
// Forward Declarations
//----------------------------------------------------------------------
class Algorithm;

/** Class to hold a set of workspaces.
The workspace group can be an entry in the AnalysisDataService.
Expand Down Expand Up @@ -56,15 +60,13 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
{
public:
/// Default constructor.
WorkspaceGroup(const bool observeADS = true);
WorkspaceGroup();
/// Destructor
~WorkspaceGroup();
/// Return a string ID of the class
virtual const std::string id() const { return "WorkspaceGroup"; }
/// The collection itself is considered to take up no space
virtual size_t getMemorySize() const { return 0; }
/// Turn ADS observations on/off
void observeADSNotifications(const bool observeADS);
/// Adds a workspace to the group.
void addWorkspace(Workspace_sptr workspace);
/// Return the number of entries within the group
Expand Down Expand Up @@ -108,6 +110,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
const WorkspaceGroup& operator=(const WorkspaceGroup&);
/// ADS removes a member of this group using this method. It doesn't send notifications in contrast to remove(name).
void removeByADS(const std::string& name);
/// Turn ADS observations on/off
void observeADSNotifications(const bool observeADS);
/// Callback when a delete notification is received
void workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice);
/// Observer for workspace delete notfications
Expand All @@ -126,6 +130,7 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
static Kernel::Logger& g_log;

friend class AnalysisDataServiceImpl;
friend class Algorithm;
};

/// Shared pointer to a workspace group class
Expand Down
8 changes: 3 additions & 5 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,11 @@ namespace Mantid
for (size_t owp=0; owp<m_pureOutputWorkspaceProps.size(); owp++)
{
Property * prop = dynamic_cast<Property *>(m_pureOutputWorkspaceProps[owp]);
// Do not observe ADS notifications while constructing the group
WorkspaceGroup_sptr outWSGrp = WorkspaceGroup_sptr(new WorkspaceGroup(false));
WorkspaceGroup_sptr outWSGrp = WorkspaceGroup_sptr(new WorkspaceGroup());
outGroups.push_back(outWSGrp);
// Put the GROUP in the ADS
AnalysisDataService::Instance().addOrReplace(prop->value(), outWSGrp );
outWSGrp->observeADSNotifications(false);
}

// Go through each entry in the input group(s)
Expand Down Expand Up @@ -1219,12 +1219,10 @@ namespace Mantid

} // for each entry in each group

// Finish up
// restore group notifications
for (size_t i=0; i<outGroups.size(); i++)
{
// Go back to observing ADS in each group.
outGroups[i]->observeADSNotifications(true);
//outGroups[i]->updated();
}

// We finished successfully.
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/src/AnalysisDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace Mantid
// 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 );
Expand Down Expand Up @@ -109,6 +110,7 @@ namespace Mantid
// 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 );
Expand Down
4 changes: 1 addition & 3 deletions Code/Mantid/Framework/API/src/MultiPeriodGroupAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ namespace Mantid
const std::string outName = outputWorkspaceProperty->value();

size_t nPeriods = m_multiPeriodGroups[0]->size();
const bool doObserveADSNotifications = true;
WorkspaceGroup_sptr outputWS = boost::make_shared<WorkspaceGroup>(!doObserveADSNotifications);
WorkspaceGroup_sptr outputWS = boost::make_shared<WorkspaceGroup>();
AnalysisDataService::Instance().addOrReplace(outName, outputWS);

// Loop through all the periods. Create spawned algorithms of the same type as this to process pairs from the input groups.
Expand Down Expand Up @@ -279,7 +278,6 @@ namespace Mantid

}

outputWS->observeADSNotifications(doObserveADSNotifications);
this->setProperty("OutputWorkspace", outputWS);
this->setExecuted(true);
return true;
Expand Down
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ namespace API

Kernel::Logger& WorkspaceGroup::g_log = Kernel::Logger::get("WorkspaceGroup");

WorkspaceGroup::WorkspaceGroup(const bool observeADS) :
WorkspaceGroup::WorkspaceGroup() :
Workspace(),
m_deleteObserver(*this, &WorkspaceGroup::workspaceDeleteHandle),
m_replaceObserver(*this, &WorkspaceGroup::workspaceReplaceHandle),
m_workspaces(), m_observingADS(false)
{
observeADSNotifications(observeADS);
}

WorkspaceGroup::~WorkspaceGroup()
Expand Down
5 changes: 0 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/GroupWorkspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ void GroupWorkspaces::exec()
}
//creates workspace group pointer
WorkspaceGroup_sptr outgrp_sptr = WorkspaceGroup_sptr(new WorkspaceGroup);
// prevent sending unnecessary notifications
outgrp_sptr->observeADSNotifications( false );

setProperty("OutputWorkspace", outgrp_sptr);

Expand Down Expand Up @@ -95,9 +93,6 @@ void GroupWorkspaces::exec()
}
}//end of for loop for input workspaces

// restore notification sending
outgrp_sptr->observeADSNotifications( true );

// Notify listeners that a new grop has been created
Mantid::API::AnalysisDataService::Instance().notificationCenter.postNotification(
new WorkspacesGroupedNotification(inputworkspaces));
Expand Down
2 changes: 0 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/LoadSassena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ void LoadSassena::exec()
gws = boost::make_shared<API::WorkspaceGroup>();
setProperty("OutputWorkspace", boost::dynamic_pointer_cast<API::Workspace>(gws));
}
gws->observeADSNotifications( false ); // Prevent sending unnecessary notifications

//populate m_validSets
int nvalidSets = 4;
Expand Down Expand Up @@ -393,7 +392,6 @@ void LoadSassena::exec()
this->g_log.information("Dataset "+setName+" not present in file");
}// end of iterate over the valid sets

gws->observeADSNotifications( true ); // Restore notification sending
H5Fclose(h5file);
} // end of LoadSassena::exec()

Expand Down

0 comments on commit 1c5fb65

Please sign in to comment.