Skip to content
Snippets Groups Projects
Commit 60dfa90f authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #8922 Fix SaveNexus and SaveNexusProcessed to capture history.

SaveNexus and SaveNexusProcessed wouldn't append a record to the history.
This commit fixes that issue and leaves a record on the input workspace so the result is that we get a
complete history, but we lose the execution start time and duration.
parent 120dc060
No related merge requests found
......@@ -349,6 +349,9 @@ protected:
Kernel::Logger m_log;
Kernel::Logger &g_log;
/// Pointer to the parent history object (if set)
boost::shared_ptr<AlgorithmHistory> m_parentHistory;
private:
/// Private Copy constructor: NO COPY ALLOWED
Algorithm(const Algorithm&);
......@@ -359,11 +362,12 @@ private:
void unlockWorkspaces();
void store();
void fillHistory();
void logAlgorithmInfo() const;
bool executeAsyncImpl(const Poco::Void & i);
/// Copy workspace history for input workspaces to output workspaces and record the history for ths algorithm
void fillHistory();
// --------------------- Private Members -----------------------------------
/// Poco::ActiveMethod used to implement asynchronous execution.
......@@ -411,8 +415,6 @@ private:
size_t m_groupSize;
/// All the groups have similar names (group_1, group_2 etc.)
bool m_groupsHaveSimilarNames;
/// Pointer to the parent history object (if set)
boost::shared_ptr<AlgorithmHistory> m_parentHistory;
/// A non-recursive mutex for thread-safety
mutable Kernel::Mutex m_mutex;
};
......
......@@ -126,9 +126,9 @@ public:
// 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; }
private:
/// The name of the Algorithm
std::string m_name;
/// The version of the algorithm
......
......@@ -155,11 +155,9 @@ 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;
if (m_executionDate != Mantid::Kernel::DateAndTime::defaultTime())
{
os << std::string(indent,' ') << "Execution Date: " << m_executionDate.toFormattedString() <<std::endl;
os << std::string(indent,' ') << "Execution Duration: "<< m_executionDuration << " seconds" << std::endl;
}
os << std::string(indent,' ') << "Execution Date: " << m_executionDate.toFormattedString() <<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;
......
......@@ -295,7 +295,7 @@ void WorkspaceHistory::loadNestedHistory(::NeXus::File * file, AlgorithmHistory_
}
else
{
//if not parent point is supplied, asssume we're at the top
//if not parent point is supplied, assume we're at the top
//and attach the history to the workspace
this->addHistory(history);
}
......@@ -321,7 +321,7 @@ std::set<int> WorkspaceHistory::findHistoryEntries(::NeXus::File* file)
std::map<std::string, std::string> entries;
file->getEntries(entries);
// Histories are numberd MantidAlgorithm_0, ..., MantidAlgorithm_10, etc.
// Histories are numbered MantidAlgorithm_0, ..., MantidAlgorithm_10, etc.
// Find all the unique numbers
for (auto it = entries.begin(); it != entries.end(); ++it)
{
......@@ -381,10 +381,11 @@ AlgorithmHistory_sptr WorkspaceHistory::parseAlgorithmHistory(const std::string&
Poco::DateTime start_timedate;
//This is needed by the Poco parsing function
int tzdiff(-1);
Mantid::Kernel::DateAndTime utc_start;
if( !Poco::DateTimeParser::tryParse("%Y-%b-%d %H:%M:%S", date + " " + time, start_timedate, tzdiff))
{
g_log.warning() << "Error parsing start time in algorithm history entry." << "\n";
throw std::runtime_error("Malformed history record: could not parse algorithm start time.");
utc_start = Kernel::DateAndTime::defaultTime();
}
//Get the duration
getWordsInString(info[EXEC_DUR], dummy, dummy, temp, dummy);
......@@ -392,10 +393,9 @@ AlgorithmHistory_sptr WorkspaceHistory::parseAlgorithmHistory(const std::string&
if ( dur < 0.0 )
{
g_log.warning() << "Error parsing start time in algorithm history entry." << "\n";
throw std::runtime_error("Malformed history record: could not parse algorithm duration.");
dur = -1.0;
}
//Convert the timestamp to time_t to DateAndTime
Mantid::Kernel::DateAndTime utc_start;
utc_start.set_from_time_t( start_timedate.timestamp().epochTime() );
//Create the algorithm history
API::AlgorithmHistory alg_hist(algName, version, utc_start, dur,Algorithm::g_execCount);
......
......@@ -76,9 +76,9 @@ namespace Mantid
static void appendEventListData( std::vector<T> events, size_t offset, double * tofs, float * weights, float * errorSquareds, int64_t * pulsetimes);
void execEvent(Mantid::NeXus::NexusFileIO * nexusFile,const bool uniformSpectra,const std::vector<int> spec);
/// sets non workspace properties for the algorithm
/// sets non workspace properties for the algorithm
void setOtherProperties(IAlgorithm* alg,const std::string & propertyName,const std::string &propertyValue,int perioidNum);
/// The name and path of the input file
std::string m_filename;
/// The name and path of the input file
......@@ -91,7 +91,6 @@ namespace Mantid
DataObjects::EventWorkspace_const_sptr m_eventWorkspace;
/// Proportion of progress time expected to write initial part
double m_timeProgInit;
/// Progress bar
API::Progress * prog;
......
......@@ -195,6 +195,20 @@ void SaveNexus::runSaveNexusProcessed()
// Pass through the append property
saveNexusPro->setProperty<bool>("Append",getProperty("Append"));
// If we're tracking history, add the entry before we save it to file
if (trackingHistory())
{
m_history->setExecCount(Algorithm::g_execCount);
if (!isChild())
{
m_inputWorkspace->history().addHistory(m_history);
}
//this is a child algorithm, but we still want to keep the history.
else if (isRecordingHistoryForChild() && m_parentHistory)
{
m_parentHistory->addChildHistory(m_history);
}
}
// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try
{
......
......@@ -347,10 +347,23 @@ namespace DataHandling
} // finish table workspace specifics
// Switch to the Cpp API for the algorithm history
inputWorkspace->getHistory().saveNexus(cppFile);
if (trackingHistory())
{
m_history->setExecCount(Algorithm::g_execCount);
if (!isChild())
{
inputWorkspace->history().addHistory(m_history);
}
//this is a child algorithm, but we still want to keep the history.
else if (isRecordingHistoryForChild() && m_parentHistory)
{
m_parentHistory->addChildHistory(m_history);
}
}
inputWorkspace->history().saveNexus(cppFile);
nexusFile->closeNexusFile();
delete nexusFile;
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment