Skip to content

Commit

Permalink
Refs #8922 Add support for nested history saving.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed May 13, 2014
1 parent 39aaa4f commit a7f230e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h
Expand Up @@ -7,6 +7,7 @@
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/PropertyHistory.h"
#include "MantidKernel/DateAndTime.h"
#include <nexus/NeXusFile.hpp>

#include <boost/bind.hpp>
#include <boost/function.hpp>
Expand Down Expand Up @@ -120,6 +121,8 @@ class MANTID_API_DLL AlgorithmHistory
boost::shared_ptr<IAlgorithm> createAlgorithm() const;
/// Create an child algorithm from a history record at a given index
boost::shared_ptr<IAlgorithm> getChildAlgorithm(const size_t index) const;
/// Write this history object to a nexus file
void saveNexus(::NeXus::File* file, int& algCount) const;
// Allow Algorithm::execute to change the exec count & duration after the algorithm was executed
friend class Algorithm;

Expand Down
29 changes: 29 additions & 0 deletions Code/Mantid/Framework/API/src/AlgorithmHistory.cpp
Expand Up @@ -3,6 +3,7 @@
//----------------------------------------------------------------------
#include "MantidAPI/AlgorithmHistory.h"
#include "MantidAPI/Algorithm.h"
#include <sstream>

namespace Mantid
{
Expand Down Expand Up @@ -208,5 +209,33 @@ std::ostream& operator<<(std::ostream& os, const AlgorithmHistory& AH)
return os;
}

/** Write out this history record to file.
* @param file :: The handle to the nexus file to save to
* @param algCount :: Counter of the number of algorithms written to file.
*/
void AlgorithmHistory::saveNexus(::NeXus::File* file, int& algCount) const
{
std::stringstream algNumber;
++algCount;
algNumber << "MantidAlgorithm_" << algCount; //history entry names start at 1 not 0

std::stringstream algData;
printSelf(algData);

file->makeGroup(algNumber.str(), "NXnote", true);
file->writeData("author", std::string("mantid"));
file->writeData("description", std::string("Mantid Algorithm data"));
file->writeData("data", algData.str());

//child algorithms
AlgorithmHistories::const_iterator histIter = m_childHistories.begin();
for(; histIter != m_childHistories.end(); ++histIter)
{
(*histIter)->saveNexus(file, algCount);
}

file->closeGroup();
}

} // namespace API
} // namespace Mantid
31 changes: 6 additions & 25 deletions Code/Mantid/Framework/API/src/WorkspaceHistory.cpp
Expand Up @@ -187,33 +187,14 @@ void WorkspaceHistory::saveNexus(::NeXus::File * file) const
file->closeGroup();

// Algorithm History
typedef std::map <std::size_t,std::string> orderedHistMap;
orderedHistMap ordMap;
for(std::size_t i=0;i<this->size();i++)
int algCount = 0;
AlgorithmHistories::const_iterator histIter = m_algorithms.begin();
for(; histIter != m_algorithms.end(); ++histIter)
{
std::stringstream algData;
auto entry = this->getAlgorithmHistory(i);
entry->printSelf(algData);

//get execute count
std::size_t nexecCount=entry->execCount();
//order by execute count
ordMap.insert(orderedHistMap::value_type(nexecCount,algData.str()));
}
int num=0;
std::map <std::size_t,std::string>::iterator m_Iter;
for (m_Iter=ordMap.begin( );m_Iter!=ordMap.end( );++m_Iter)
{
++num;
std::stringstream algNumber;
algNumber << "MantidAlgorithm_" << num;

file->makeGroup(algNumber.str(), "NXnote", true);
file->writeData("author", std::string("mantid"));
file->writeData("description", std::string("Mantid Algorithm data"));
file->writeData("data", m_Iter->second);
file->closeGroup();
(*histIter)->saveNexus(file, algCount);
}

//close process group
file->closeGroup();
}

Expand Down

0 comments on commit a7f230e

Please sign in to comment.