Skip to content

Commit

Permalink
Refs #8913 Set exec count after algorithm is executed.
Browse files Browse the repository at this point in the history
Otherwise LoadProcessNexus modifies the execution counter when it loads
histories from file and the parent algorithm gets the incorrect exec count.

As you should never need to set the exec count except in Algorithm, I've made
the method private and made Algorithm a friend class.
  • Loading branch information
Samuel Jackson committed Apr 29, 2014
1 parent 6d43b7c commit 93d0174
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h
Expand Up @@ -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 ------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h
Expand Up @@ -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;}
Expand All @@ -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
Expand All @@ -106,8 +106,14 @@ class MANTID_API_DLL AlgorithmHistory
}
/// Create a concrete algorithm based on a history record
boost::shared_ptr<IAlgorithm> 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
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/Framework/API/src/Algorithm.cpp
Expand Up @@ -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<AlgorithmHistory>(algHist);

// Start a timer
Expand All @@ -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())
Expand Down
12 changes: 7 additions & 5 deletions Code/Mantid/Framework/API/src/AlgorithmHistory.cpp
Expand Up @@ -30,7 +30,6 @@ AlgorithmHistory::AlgorithmHistory(const Algorithm* const alg, const Kernel::Dat
}
}


/// Destructor
AlgorithmHistory::~AlgorithmHistory()
{}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 93d0174

Please sign in to comment.