Skip to content

Commit

Permalink
Refs #8913 Add new methods to Algorithm class for nested history.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Apr 28, 2014
1 parent 0b5f05e commit 96c50a5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
12 changes: 9 additions & 3 deletions Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h
Expand Up @@ -270,7 +270,7 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
static IAlgorithm_sptr fromHistory(const AlgorithmHistory & history);
//@}

boost::shared_ptr<Algorithm> createChildAlgorithm(const std::string& name, const double startProgress = -1.,
virtual boost::shared_ptr<Algorithm> createChildAlgorithm(const std::string& name, const double startProgress = -1.,
const double endProgress = -1., const bool enableLogging=true, const int& version = -1);

protected:
Expand Down Expand Up @@ -312,6 +312,11 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag

///checks the property is a workspace property
bool isWorkspaceProperty(const Kernel::Property* const prop) const;

/// set whether we wish to track the child algorithm's history and pass it the parent object to fill.
void trackAlgorithmHistory(AlgorithmHistory* parentHist);
/// get whether we are tracking the history for this algorithm,
bool trackingHistory();

/// Set to true to stop execution
bool m_cancel;
Expand All @@ -334,7 +339,7 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag

/// All the WorkspaceProperties that are Input or InOut. Set in execute()
std::vector<IWorkspaceProperty *> m_inputWorkspaceProps;

/// Logger for this algorithm
Kernel::Logger m_log;
Kernel::Logger &g_log;
Expand Down Expand Up @@ -381,7 +386,6 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
std::string m_WikiDescription; ///< Description in the wiki page.
std::vector<boost::weak_ptr<IAlgorithm>> m_ChildAlgorithms; ///< A list of weak pointers to any child algorithms created


/// Vector of all the workspaces that have been read-locked
WorkspaceVector m_readLockedWorkspaces;
/// Vector of all the workspaces that have been write-locked
Expand All @@ -402,6 +406,8 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
size_t m_groupSize;
/// All the groups have similar names (group_1, group_2 etc.)
bool m_groupsHaveSimilarNames;
/// Pointer to the parent history object (if set)
AlgorithmHistory* m_parentHistory;
/// A non-recursive mutex for thread-safety
mutable Kernel::Mutex m_mutex;
};
Expand Down
59 changes: 45 additions & 14 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Expand Up @@ -2,8 +2,8 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/AlgorithmProxy.h"
#include "MantidAPI/AlgorithmHistory.h"
#include "MantidAPI/AlgorithmProxy.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/DeprecatedAlgorithm.h"
#include "MantidAPI/AlgorithmManager.h"
Expand Down Expand Up @@ -84,7 +84,8 @@ namespace Mantid
m_isInitialized(false), m_isExecuted(false),m_isChildAlgorithm(false), m_recordHistoryForChild(false),
m_alwaysStoreInADS(false),m_runningAsync(false),
m_running(false),m_rethrow(false),m_algorithmID(this),
m_singleGroup(-1), m_groupSize(0), m_groupsHaveSimilarNames(false)
m_singleGroup(-1), m_groupSize(0), m_groupsHaveSimilarNames(false),
m_parentHistory(NULL)
{
}

Expand Down Expand Up @@ -596,7 +597,7 @@ namespace Mantid
Poco::FastMutex::ScopedLock _lock(m_mutex);
m_running = true;
}
if(!isChild() || m_recordHistoryForChild)
if(trackingHistory())
{
// count used for defining the algorithm execution order
// If history is being recorded we need to count this as a separate algorithm
Expand All @@ -615,7 +616,7 @@ namespace Mantid
const float duration = timer.elapsed();

// need it to throw before trying to run fillhistory() on an algorithm which has failed
if(!isChild() || m_recordHistoryForChild)
if(trackingHistory())
fillHistory(start_time,duration,Algorithm::g_execCount);

// Put any output workspaces into the AnalysisDataService - if this is not a child algorithm
Expand Down Expand Up @@ -1017,22 +1018,52 @@ namespace Mantid
// Create the history object for this algorithm
AlgorithmHistory algHistory(this,start,duration,uexecCount);

std::vector<Workspace_sptr>::iterator outWS;
std::vector<Workspace_sptr>::const_iterator inWS;
// Loop over the output workspaces
for (outWS = outputWorkspaces.begin(); outWS != outputWorkspaces.end(); ++outWS)

//this is not a child algorithm. Add the history algorithm to the WorkspaceHistory object.
if (!isChild())
{
// Loop over the input workspaces, making the call that copies their history to the output ones
// (Protection against copy to self is in WorkspaceHistory::copyAlgorithmHistory)
for (inWS = inputWorkspaces.begin(); inWS != inputWorkspaces.end(); ++inWS)
std::vector<Workspace_sptr>::iterator outWS;
std::vector<Workspace_sptr>::const_iterator inWS;

// Loop over the output workspaces
for (outWS = outputWorkspaces.begin(); outWS != outputWorkspaces.end(); ++outWS)
{
(*outWS)->history().addHistory( (*inWS)->getHistory() );
// Loop over the input workspaces, making the call that copies their history to the output ones
// (Protection against copy to self is in WorkspaceHistory::copyAlgorithmHistory)
for (inWS = inputWorkspaces.begin(); inWS != inputWorkspaces.end(); ++inWS)
{
(*outWS)->history().addHistory( (*inWS)->getHistory() );
}
// Add the history for the current algorithm to all the output workspaces
(*outWS)->history().addHistory(algHistory);
}
// Add the history for the current algorithm to all the output workspaces
(*outWS)->history().addHistory(algHistory);
}
//this is a child algorithm, but we still want to keep the history.
else if (m_recordHistoryForChild && m_parentHistory)
{
m_parentHistory->addHistory(algHistory);
}
}

/** Indicates that this algrithms history should be tracked regardless of if it is a child.
* @param state :: a boolean indicating whether to track the history or not
* @param parent :: the parent algorithm history object the history in.
*/
void Algorithm::trackAlgorithmHistory(AlgorithmHistory* parentHist)
{
m_recordHistoryForChild = true;
m_parentHistory = parentHist;
}

/** Check if we are tracking history for thus algorithm
* @return if we are tracking the history of this algorithm
*/
bool Algorithm::trackingHistory()
{
return (!isChild() || m_recordHistoryForChild);
}


/** Populate lists of the input & output workspace properties.
* (InOut workspaces go in both lists)
* @param inputWorkspaces :: A reference to a vector for the input workspaces
Expand Down

0 comments on commit 96c50a5

Please sign in to comment.