Newer
Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/AlgorithmHistory.h"
Russell Taylor
committed
#include "MantidAPI/Algorithm.h"
namespace Mantid
{
Russell Taylor
committed
namespace API
{
using Kernel::Property;
Russell Taylor
committed
/** Constructor
* @param alg A pointer to the algorithm for which the history should be constructed
* @param start The start time of the algorithm execution (optional)
* @param duration The time (in seconds) that it took to run this algorithm (optional)
*/
AlgorithmHistory::AlgorithmHistory(const Algorithm* const alg, const dateAndTime& start, const double& duration,unsigned int uexeccount) :
m_name(alg->name()), m_version(alg->version()), m_executionDate(start), m_executionDuration(duration),m_execCount(uexeccount)
Russell Taylor
committed
{
// Now go through the algorithm's properties and create the PropertyHistory objects.
const std::vector<Property*>& properties = alg->getProperties();
std::vector<Property*>::const_iterator it;
for (it = properties.begin(); it != properties.end(); ++it)
{
m_properties.push_back( (*it)->createHistory() );
}
}
Russell Taylor
committed
/// Destructor
AlgorithmHistory::~AlgorithmHistory()
{}
Russell Taylor
committed
/*!
Standard Copy Constructor
\param A :: AlgorithmHistory Item to copy
Russell Taylor
committed
*/
AlgorithmHistory::AlgorithmHistory(const AlgorithmHistory& A) :
m_name(A.m_name),m_version(A.m_version),m_executionDate(A.m_executionDate),
m_executionDuration(A.m_executionDuration),m_properties(A.m_properties),m_execCount(A.m_execCount)
Russell Taylor
committed
{
}
/** Add details of an algorithm's execution to an existing history object
* @param start The start time of the algorithm execution
* @param duration The time (in seconds) that it took to run this algorithm
*/
void AlgorithmHistory::addExecutionInfo(const dateAndTime& start, const double& duration)
{
m_executionDate = start;
m_executionDuration = duration;
}
/** Prints a text representation of itself
* @param os The ouput stream to write to
* @param indent an indentation value to make pretty printing of object and sub-objects
*/
void AlgorithmHistory::printSelf(std::ostream& os, const int indent)const
{
os << std::string(indent,' ') << "Algorithm: " << m_name;
os << std::string(indent,' ') << " v" << m_version << std::endl;
Russell Taylor
committed
if (m_executionDate)
{
char buffer [25];
strftime (buffer,25,"%Y-%b-%d %H:%M:%S",localtime(&m_executionDate));
os << std::string(indent,' ') << "Execution Date: " << buffer<<std::endl;
os << std::string(indent,' ') << "Execution Duration: "<< m_executionDuration << " seconds" << std::endl;
}
std::vector<Kernel::PropertyHistory>::const_iterator it;
os << std::string(indent,' ') << "Parameters:" <<std::endl;
Russell Taylor
committed
for (it=m_properties.begin();it!=m_properties.end();it++)
{
it->printSelf( os, indent+2 );
}
}
Russell Taylor
committed
/*!
Standard Assignment operator
\param A :: AlgorithmHistory Item to assign to 'this'
Russell Taylor
committed
*/
AlgorithmHistory& AlgorithmHistory::operator=(const AlgorithmHistory& A)
{
if (this!=&A)
{
m_name=A.m_name;
m_version=A.m_version;
m_executionDate=A.m_executionDate;
m_executionDuration=A.m_executionDuration;
m_properties=A.m_properties;
}
return *this;
}
Russell Taylor
committed
/** Prints a text representation
* @param os The ouput stream to write to
* @param AH The AlgorithmHistory to output
* @returns The ouput stream
*/
std::ostream& operator<<(std::ostream& os, const AlgorithmHistory& AH)
{
AH.printSelf(os);
return os;
}
Russell Taylor
committed
} // namespace API
} // namespace Mantid