diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h b/Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h index b0b0d6f1e967..9c5a4b5a36da 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h @@ -325,7 +325,7 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag /// Set if an exception is thrown, and not caught, within a parallel region bool m_parallelException; - friend class WorkspaceHistory; // Allow workspace history loading to adjust g_execCount + friend class WorkspaceHistory; // Allow workspace history loading to adjust g_execCount static size_t g_execCount; ///< Counter to keep track of algorithm execution order // ------------------ For WorkspaceGroups ------------------------------------ diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h index 49367687a100..ce56efc5f6f5 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h @@ -70,8 +70,6 @@ class MANTID_API_DLL AlgorithmHistory /// add a child algorithm history record to this history object void addChildHistory(const AlgorithmHistory& childHist); - /// set the duration time this algorithm history object - void setDuration(const double& duration); // get functions /// get name of algorithm in history const const std::string& name() const {return m_name;} @@ -89,6 +87,8 @@ class MANTID_API_DLL AlgorithmHistory AlgorithmHistories getChildHistories() const { return m_childHistories; } /// Retrieve a child algorithm history by index const AlgorithmHistory & getChildAlgorithmHistory(const size_t index) const; + /// Add operator[] access + const AlgorithmHistory & operator[](const size_t index) const; /// Retrieve the number of child algorithms size_t childHistorySize() const; /// print contents of object @@ -106,8 +106,14 @@ class MANTID_API_DLL AlgorithmHistory } /// Create a concrete algorithm based on a history record boost::shared_ptr createAlgorithm() const; + // Allow Algorithm::execute to change the exec count & duration after the algorithm was executed + friend class Algorithm; private: + // Set the execution count + void setExecCount(std::size_t execCount) { m_execCount = execCount; } + /// Set the duration time + void setDuration(const double& duration) { m_executionDuration = duration; } /// The name of the Algorithm std::string m_name; /// The version of the algorithm diff --git a/Code/Mantid/Framework/API/src/Algorithm.cpp b/Code/Mantid/Framework/API/src/Algorithm.cpp index ec3c7d04ec5a..358345ccfeec 100644 --- a/Code/Mantid/Framework/API/src/Algorithm.cpp +++ b/Code/Mantid/Framework/API/src/Algorithm.cpp @@ -616,7 +616,7 @@ 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); + AlgorithmHistory algHist(this, start_time); m_history = boost::make_shared(algHist); // Start a timer @@ -628,6 +628,7 @@ namespace Mantid // Get how long this algorithm took to run const float duration = timer.elapsed(); m_history->setDuration(duration); + m_history->setExecCount(Algorithm::g_execCount); // need it to throw before trying to run fillhistory() on an algorithm which has failed if(trackingHistory()) diff --git a/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp b/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp index ccecd4f99737..8fa76c4b7a38 100644 --- a/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp +++ b/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp @@ -30,7 +30,6 @@ AlgorithmHistory::AlgorithmHistory(const Algorithm* const alg, const Kernel::Dat } } - /// Destructor AlgorithmHistory::~AlgorithmHistory() {} @@ -122,12 +121,15 @@ const AlgorithmHistory & AlgorithmHistory::getChildAlgorithmHistory(const size_t return *start; } -/** Set the duration time of the algorithm in the history - * @param duration :: The time the algorithm took to execute +/** + * Index operator[] access to a child algorithm history + * @param index :: An index within the algorithm history + * @returns A reference to a const AlgorithmHistory object + * @throws std::out_of_range error if the index is invalid */ -void AlgorithmHistory::setDuration(const double& duration) +const AlgorithmHistory& AlgorithmHistory::operator[](const size_t index) const { - m_executionDuration = duration; + return getChildAlgorithmHistory(index); } /** Prints a text representation of itself