Newer
Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/AlgorithmHistory.h"
Russell Taylor
committed
#include "MantidAPI/Algorithm.h"
namespace Mantid
{
Russell Taylor
committed
namespace API
{
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) :
m_name(alg->name()), m_version(alg->version()), m_executionDate(start), m_executionDuration(duration)
{
// Now go through the algorithm's properties and create the PropertyHistory objects.
// Would like to have PropertyManager & Property do this but can't because PropertyHistory has to know
// about Workspace Properties, which is in API whereas PropertyManager/Property are in Kernel.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
*/
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)
{
}
/** 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,' ') << "Name : " << m_name << std::endl;
os << std::string(indent,' ') << "Version: " << m_version << std::endl;
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++)
{
os << std::endl;
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