Commit eec355f3 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #8913 Modify Algorithm and DataProcessorAlgorithm

These classes should now capture the history of child algorithms.
parent 96c50a5f
......@@ -314,7 +314,7 @@ protected:
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);
void trackAlgorithmHistory(boost::shared_ptr<AlgorithmHistory> parentHist);
/// get whether we are tracking the history for this algorithm,
bool trackingHistory();
......@@ -339,6 +339,8 @@ protected:
/// All the WorkspaceProperties that are Input or InOut. Set in execute()
std::vector<IWorkspaceProperty *> m_inputWorkspaceProps;
/// Pointer to the history for the algorithm being executed
boost::shared_ptr<AlgorithmHistory> m_history;
/// Logger for this algorithm
Kernel::Logger m_log;
......@@ -354,7 +356,7 @@ private:
void unlockWorkspaces();
void store();
void fillHistory(Mantid::Kernel::DateAndTime, double,std::size_t);
void fillHistory();
void logAlgorithmInfo() const;
......@@ -407,7 +409,7 @@ private:
/// 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;
boost::shared_ptr<AlgorithmHistory> m_parentHistory;
/// A non-recursive mutex for thread-safety
mutable Kernel::Mutex m_mutex;
};
......
......@@ -71,7 +71,7 @@ public:
/// add a child algorithm history record to this history object
void addChildHistory(const AlgorithmHistory& childHist);
/// set the duration time this algorithm history object
void setAlgorithmDuration(const double& duration);
void setDuration(const double& duration);
// get functions
/// get name of algorithm in history const
const std::string& name() const {return m_name;}
......
......@@ -46,6 +46,8 @@ public:
virtual ~DataProcessorAlgorithm();
protected:
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);
void setLoadAlg(const std::string & alg);
void setLoadAlgFileProp(const std::string & filePropName);
void setAccumAlg(const std::string & alg);
......
......@@ -84,8 +84,7 @@ 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_parentHistory(NULL)
m_singleGroup(-1), m_groupSize(0), m_groupsHaveSimilarNames(false)
{
}
......@@ -606,6 +605,10 @@ namespace Mantid
}
start_time = Mantid::Kernel::DateAndTime::getCurrentTime();
//populate history record before execution so we can record child algorithms in it
AlgorithmHistory algHist(this, start_time, -1.0, Algorithm::g_execCount);
m_history = boost::make_shared<AlgorithmHistory>(algHist);
// Start a timer
Timer timer;
// Call the concrete algorithm's exec method
......@@ -614,10 +617,11 @@ namespace Mantid
interruption_point();
// Get how long this algorithm took to run
const float duration = timer.elapsed();
m_history->setDuration(duration);
// need it to throw before trying to run fillhistory() on an algorithm which has failed
if(trackingHistory())
fillHistory(start_time,duration,Algorithm::g_execCount);
fillHistory();
// Put any output workspaces into the AnalysisDataService - if this is not a child algorithm
if (!isChild() || m_alwaysStoreInADS)
......@@ -1009,15 +1013,11 @@ namespace Mantid
* @param duration :: a double defining the length of duration of the algorithm
* @param uexecCount an unsigned int for defining the excution order of algorithm
*/
void Algorithm::fillHistory(Mantid::Kernel::DateAndTime start,double duration,std::size_t uexecCount)
void Algorithm::fillHistory()
{
// Create two vectors to hold a list of pointers to the input & output workspaces (InOut's go in both)
std::vector<Workspace_sptr> inputWorkspaces, outputWorkspaces;
findWorkspaceProperties(inputWorkspaces,outputWorkspaces);
// Create the history object for this algorithm
AlgorithmHistory algHistory(this,start,duration,uexecCount);
//this is not a child algorithm. Add the history algorithm to the WorkspaceHistory object.
if (!isChild())
......@@ -1035,21 +1035,22 @@ namespace Mantid
(*outWS)->history().addHistory( (*inWS)->getHistory() );
}
// Add the history for the current algorithm to all the output workspaces
(*outWS)->history().addHistory(algHistory);
(*outWS)->history().addHistory(*m_history);
}
}
//this is a child algorithm, but we still want to keep the history.
else if (m_recordHistoryForChild && m_parentHistory)
{
m_parentHistory->addHistory(algHistory);
m_parentHistory->addChildHistory(*m_history);
}
}
/** 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)
void Algorithm::trackAlgorithmHistory(boost::shared_ptr<AlgorithmHistory> parentHist)
{
m_recordHistoryForChild = true;
m_parentHistory = parentHist;
......
......@@ -30,6 +30,7 @@ AlgorithmHistory::AlgorithmHistory(const Algorithm* const alg, const Kernel::Dat
}
}
/// Destructor
AlgorithmHistory::~AlgorithmHistory()
{}
......@@ -93,7 +94,7 @@ void AlgorithmHistory::addChildHistory(const AlgorithmHistory& childHist)
/** Set the duration time of the algorithm in the history
* @param duration :: The time the algorithm took to execute
*/
void AlgorithmHistory::setAlgorithmDuration(const double& duration)
void AlgorithmHistory::setDuration(const double& duration)
{
m_executionDuration = duration;
}
......
......@@ -42,6 +42,15 @@ namespace API
}
//----------------------------------------------------------------------------------------------
boost::shared_ptr<Algorithm> DataProcessorAlgorithm::createChildAlgorithm(const std::string& name, const double startProgress,
const double endProgress, const bool enableLogging, const int& version)
{
//pass pointer to the history object created in Algorithm to the child
trackAlgorithmHistory(m_history);
//call parent method to create the child algorithm
return Algorithm::createChildAlgorithm(name, startProgress, endProgress, enableLogging, version);
}
void DataProcessorAlgorithm::setLoadAlg(const std::string &alg)
{
if (alg.empty())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment