diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h index 01c3da5be058..52870483455e 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/AlgorithmHistory.h @@ -7,6 +7,7 @@ #include "MantidAPI/DllConfig.h" #include "MantidKernel/PropertyHistory.h" #include "MantidKernel/DateAndTime.h" +#include #include #include @@ -120,6 +121,8 @@ class MANTID_API_DLL AlgorithmHistory boost::shared_ptr createAlgorithm() const; /// Create an child algorithm from a history record at a given index boost::shared_ptr 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; diff --git a/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp b/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp index 3f7c08bef36c..d9361ee1ad13 100644 --- a/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp +++ b/Code/Mantid/Framework/API/src/AlgorithmHistory.cpp @@ -3,6 +3,7 @@ //---------------------------------------------------------------------- #include "MantidAPI/AlgorithmHistory.h" #include "MantidAPI/Algorithm.h" +#include namespace Mantid { @@ -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 diff --git a/Code/Mantid/Framework/API/src/WorkspaceHistory.cpp b/Code/Mantid/Framework/API/src/WorkspaceHistory.cpp index 3c0db0ce7a83..f5ca43887e6b 100644 --- a/Code/Mantid/Framework/API/src/WorkspaceHistory.cpp +++ b/Code/Mantid/Framework/API/src/WorkspaceHistory.cpp @@ -187,33 +187,14 @@ void WorkspaceHistory::saveNexus(::NeXus::File * file) const file->closeGroup(); // Algorithm History - typedef std::map orderedHistMap; - orderedHistMap ordMap; - for(std::size_t i=0;isize();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 ::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(); }