diff --git a/Framework/API/inc/MantidAPI/ScriptBuilder.h b/Framework/API/inc/MantidAPI/ScriptBuilder.h index 2c73b0347b31bb4f58f39c72539ab34e7e821981..60c7e11efb5ddf9582aa751f507d73e82ba1ad26 100644 --- a/Framework/API/inc/MantidAPI/ScriptBuilder.h +++ b/Framework/API/inc/MantidAPI/ScriptBuilder.h @@ -60,6 +60,8 @@ private: void buildChildren(std::ostringstream &os, std::vector<HistoryItem>::const_iterator &iter, int depth = 1); + const std::string + buildCommentString(AlgorithmHistory_const_sptr algHistory); const std::string buildAlgorithmString(AlgorithmHistory_const_sptr algHistory); const std::string @@ -68,6 +70,8 @@ private: const std::vector<HistoryItem> m_historyItems; std::string m_output; std::string m_versionSpecificity; + + }; } // namespace API diff --git a/Framework/API/src/ScriptBuilder.cpp b/Framework/API/src/ScriptBuilder.cpp index ab65af2cc0326ab93f97bc12393eab96884864c5..f03a2e82cea07c43ac550dd0db7eff8df285ae3a 100644 --- a/Framework/API/src/ScriptBuilder.cpp +++ b/Framework/API/src/ScriptBuilder.cpp @@ -19,6 +19,8 @@ namespace { Mantid::Kernel::Logger g_log("ScriptBuilder"); } +const std::string COMMENT_ALG = "Comment"; + ScriptBuilder::ScriptBuilder(boost::shared_ptr<HistoryView> view, std::string versionSpecificity) : m_historyItems(view->getAlgorithmsList()), m_output(), @@ -99,6 +101,29 @@ void ScriptBuilder::buildChildren( } /** +* Build the script output for a single comment +* +* @param algHistory :: pointer to an algorithm history object +* @returns std::string to run this algorithm +*/ +const std::string ScriptBuilder::buildCommentString(AlgorithmHistory_const_sptr algHistory) +{ + std::ostringstream comment; + const std::string name = algHistory->name(); + if (name == COMMENT_ALG) + { + auto props = algHistory->getProperties(); + for (auto propIter = props.begin(); propIter != props.end(); ++propIter) { + if ((*propIter)->name() == "Note") + { + comment << "# " << (*propIter)->value(); + } + } + } + return comment.str(); +} + + /** * Build the script output for a single algorithm * * @param algHistory :: pointer to an algorithm history object @@ -110,6 +135,9 @@ ScriptBuilder::buildAlgorithmString(AlgorithmHistory_const_sptr algHistory) { const std::string name = algHistory->name(); std::string prop = ""; + if (name == COMMENT_ALG) + properties << buildCommentString(algHistory) << "\n"; + auto props = algHistory->getProperties(); for (auto propIter = props.begin(); propIter != props.end(); ++propIter) { prop = buildPropertyString(*propIter); diff --git a/Framework/Algorithms/CMakeLists.txt b/Framework/Algorithms/CMakeLists.txt index 7be05f6f589097731516390149bc062b038d7ed1..cdbb48f3d19afcc30d6a3ae0396d1a5bf2510085 100644 --- a/Framework/Algorithms/CMakeLists.txt +++ b/Framework/Algorithms/CMakeLists.txt @@ -3,7 +3,6 @@ set ( SRC_FILES # src/CountEventsInPulses.cpp # src/UpdatePeakParameterTable.cpp src/AbsorptionCorrection.cpp - src/AddHistoryNote.cpp src/AddLogDerivative.cpp src/AddNote.cpp src/AddPeak.cpp @@ -41,6 +40,7 @@ set ( SRC_FILES src/ClearInstrumentParameters.cpp src/ClearMaskFlag.cpp src/CloneWorkspace.cpp + src/Comment.cpp src/CommutativeBinaryOperation.cpp src/ConjoinWorkspaces.cpp src/ConvertAxesToRealSpace.cpp @@ -280,7 +280,6 @@ set ( INC_FILES # inc/MantidAlgorithms/CountEventsInPulses.h # inc/MantidAlgorithms/UpdatePeakParameterTable.h inc/MantidAlgorithms/AbsorptionCorrection.h - inc/MantidAlgorithms/AddHistoryNote.h inc/MantidAlgorithms/AddLogDerivative.h inc/MantidAlgorithms/AddNote.h inc/MantidAlgorithms/AddPeak.h @@ -318,6 +317,7 @@ set ( INC_FILES inc/MantidAlgorithms/ClearInstrumentParameters.h inc/MantidAlgorithms/ClearMaskFlag.h inc/MantidAlgorithms/CloneWorkspace.h + inc/MantidAlgorithms/Comment.h inc/MantidAlgorithms/CommutativeBinaryOperation.h inc/MantidAlgorithms/ConjoinWorkspaces.h inc/MantidAlgorithms/ConvertAxesToRealSpace.h @@ -569,7 +569,6 @@ endif(UNITY_BUILD) set ( TEST_FILES # CountEventsInPulsesTest.h # UpdatePeakParameterTableTest.h - AddHistoryNoteTest.h AddLogDerivativeTest.h AddNoteTest.h AddPeakTest.h @@ -607,6 +606,7 @@ set ( TEST_FILES ClearInstrumentParametersTest.h ClearMaskFlagTest.h CloneWorkspaceTest.h + CommentTest.h CommutativeBinaryOperationTest.h ConjoinWorkspacesTest.h ConvertAxesToRealSpaceTest.h diff --git a/Framework/Algorithms/inc/MantidAlgorithms/AddHistoryNote.h b/Framework/Algorithms/inc/MantidAlgorithms/Comment.h similarity index 80% rename from Framework/Algorithms/inc/MantidAlgorithms/AddHistoryNote.h rename to Framework/Algorithms/inc/MantidAlgorithms/Comment.h index d2cc0011a820bb1b9cd3382f182a0d01ab489d59..dfd4f5e81bbb9e8e2610c6adc10185cd7b2efb6c 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/AddHistoryNote.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/Comment.h @@ -1,12 +1,12 @@ -#ifndef MANTID_ALGORITHMS_ADDHISTORYNOTE_H_ -#define MANTID_ALGORITHMS_ADDHISTORYNOTE_H_ +#ifndef MANTID_ALGORITHMS_COMMENT_H_ +#define MANTID_ALGORITHMS_COMMENT_H_ #include "MantidAlgorithms/DllConfig.h" #include "MantidAPI/Algorithm.h" namespace Mantid { namespace Algorithms { -/** AddHistoryNote : Adds a note into the history record of a workspace +/** Comment : Adds a note into the history record of a workspace Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source @@ -29,10 +29,10 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport AddHistoryNote : public API::Algorithm { +class DLLExport Comment : public API::Algorithm { public: - AddHistoryNote(); - virtual ~AddHistoryNote(); + Comment(); + virtual ~Comment(); virtual const std::string name() const; virtual int version() const; @@ -47,4 +47,4 @@ private: } // namespace Algorithms } // namespace Mantid -#endif /* MANTID_ALGORITHMS_ADDHISTORYNOTE_H_ */ \ No newline at end of file +#endif /* MANTID_ALGORITHMS_COMMENT_H_ */ diff --git a/Framework/Algorithms/src/AddHistoryNote.cpp b/Framework/Algorithms/src/Comment.cpp similarity index 68% rename from Framework/Algorithms/src/AddHistoryNote.cpp rename to Framework/Algorithms/src/Comment.cpp index cb184023f8c170a01d70d37b150586ebaedf41a5..8be4da8c2f836b1568cca72bad36fbc00a7a927e 100644 --- a/Framework/Algorithms/src/AddHistoryNote.cpp +++ b/Framework/Algorithms/src/Comment.cpp @@ -1,4 +1,4 @@ -#include "MantidAlgorithms/AddHistoryNote.h" +#include "MantidAlgorithms/Comment.h" #include "MantidKernel/MandatoryValidator.h" namespace Mantid { @@ -10,47 +10,47 @@ using Mantid::API::WorkspaceProperty; using Mantid::API::Workspace; // Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(AddHistoryNote) +DECLARE_ALGORITHM(Comment) //---------------------------------------------------------------------------------------------- /** Constructor */ -AddHistoryNote::AddHistoryNote() {} +Comment::Comment() {} //---------------------------------------------------------------------------------------------- /** Destructor */ -AddHistoryNote::~AddHistoryNote() {} +Comment::~Comment() {} //---------------------------------------------------------------------------------------------- /// Algorithms name for identification. @see Algorithm::name -const std::string AddHistoryNote::name() const { return "AddHistoryNote"; } +const std::string Comment::name() const { return "Comment"; } /// Algorithm's version for identification. @see Algorithm::version -int AddHistoryNote::version() const { return 1; } +int Comment::version() const { return 1; } /// Algorithm's category for identification. @see Algorithm::category -const std::string AddHistoryNote::category() const { +const std::string Comment::category() const { return "DataHandling"; } /// Algorithm's summary for use in the GUI and help. @see Algorithm::summary -const std::string AddHistoryNote::summary() const { - return "Adds a note into the history record of a workspace"; +const std::string Comment::summary() const { + return "Adds a comment into the history record of a workspace"; } //---------------------------------------------------------------------------------------------- /** Initialize the algorithm's properties. */ -void AddHistoryNote::init() { +void Comment::init() { declareProperty( new WorkspaceProperty<Workspace>("Workspace", "", Direction::InOut), - "An InOut workspace that will store the new history record"); + "An InOut workspace that will store the new history comment"); declareProperty( - "Note", "", boost::make_shared<MandatoryValidator<std::string>>(), - "The note you want to store in the history of the workspace", Direction::Input); + "Text", "", boost::make_shared<MandatoryValidator<std::string>>(), + "The text you want to store in the history of the workspace", Direction::Input); //always record history for this algorithm enableHistoryRecordingForChild(true); @@ -59,7 +59,7 @@ void AddHistoryNote::init() { //---------------------------------------------------------------------------------------------- /** Execute the algorithm. */ -void AddHistoryNote::exec() { +void Comment::exec() { //do nothing } diff --git a/Framework/Algorithms/test/AddHistoryNoteTest.h b/Framework/Algorithms/test/CommentTest.h similarity index 63% rename from Framework/Algorithms/test/AddHistoryNoteTest.h rename to Framework/Algorithms/test/CommentTest.h index 6c67084cbb6fdc3f87d97fb664b5df13442ebc78..091fbe088d39dc1606682853bfe7e804a0b69c0c 100644 --- a/Framework/Algorithms/test/AddHistoryNoteTest.h +++ b/Framework/Algorithms/test/CommentTest.h @@ -1,44 +1,43 @@ -#ifndef MANTID_ALGORITHMS_ADDHISTORYNOTETEST_H_ -#define MANTID_ALGORITHMS_ADDHISTORYNOTETEST_H_ +#ifndef MANTID_ALGORITHMS_COMMENTTEST_H_ +#define MANTID_ALGORITHMS_COMMENTTEST_H_ #include <cxxtest/TestSuite.h> -#include "MantidAlgorithms/AddHistoryNote.h" +#include "MantidAlgorithms/Comment.h" #include "MantidAPI/Workspace.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" -using Mantid::Algorithms::AddHistoryNote; using namespace Mantid::API; -class AddHistoryNoteTest : public CxxTest::TestSuite { +class CommentTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically // This means the constructor isn't called when running other tests - static AddHistoryNoteTest *createSuite() { return new AddHistoryNoteTest(); } - static void destroySuite( AddHistoryNoteTest *suite ) { delete suite; } + static CommentTest *createSuite() { return new CommentTest(); } + static void destroySuite( CommentTest *suite ) { delete suite; } void test_Init() { - AddHistoryNote alg; + Mantid::Algorithms::Comment alg; TS_ASSERT_THROWS_NOTHING( alg.initialize() ) TS_ASSERT( alg.isInitialized() ) } void test_exec() { - std::string wsName = "AddHistoryNoteTest_Exec_workspace"; + std::string wsName = "CommentTest_Exec_workspace"; // Create test input auto ws = WorkspaceCreationHelper::Create2DWorkspace(10, 10); AnalysisDataService::Instance().add(wsName,ws); //and an identical ws for comparison later auto ws2 = WorkspaceCreationHelper::Create2DWorkspace(10, 10); - AddHistoryNote alg; + Mantid::Algorithms::Comment alg; TS_ASSERT_THROWS_NOTHING( alg.initialize() ) TS_ASSERT( alg.isInitialized() ) TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Workspace", wsName) ); - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Note", + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Text", "The next algorithm is doing ws equals 1/ws") ); TS_ASSERT_THROWS_NOTHING( alg.execute(); ); TS_ASSERT( alg.isExecuted() ); @@ -57,10 +56,9 @@ public: TS_ASSERT_EQUALS(lastAlgorithm->getPropertyValue("Workspace"), alg.getPropertyValue("Workspace")); - TS_ASSERT_EQUALS(lastAlgorithm->getPropertyValue("Note"), - alg.getPropertyValue("Note")); - std::cout << alg.getPropertyValue("Note") << std::endl; - TSM_ASSERT("The workspace has been altered by AddHistoryNote",Mantid::API::equals(ws, ws2)); + TS_ASSERT_EQUALS(lastAlgorithm->getPropertyValue("Text"), + alg.getPropertyValue("Text")); + TSM_ASSERT("The workspace has been altered by Comment",Mantid::API::equals(ws, ws2)); AnalysisDataService::Instance().remove(wsName); } @@ -71,4 +69,4 @@ public: }; -#endif /* MANTID_ALGORITHMS_ADDHISTORYNOTETEST_H_ */ \ No newline at end of file +#endif /* MANTID_ALGORITHMS_COMMENTTEST_H_ */ \ No newline at end of file diff --git a/docs/source/algorithms/AddHistoryNote-v1.rst b/docs/source/algorithms/AddHistoryNote-v1.rst deleted file mode 100644 index d937b524505a18202b1299f84f067bb869074ebc..0000000000000000000000000000000000000000 --- a/docs/source/algorithms/AddHistoryNote-v1.rst +++ /dev/null @@ -1,41 +0,0 @@ - -.. algorithm:: - -.. summary:: - -.. alias:: - -.. properties:: - -Description ------------ - -This simple algorithm just adds a record to the history of a workspace and is a simple way of annotating your workflow. - -It does not change the data within a workspace in any way. - - -Usage ------ - -**Example - AddHistoryNote** - -.. testcode:: AddHistoryNoteExample - - ws = CreateSampleWorkspace() - - AddHistoryNote(ws,"The next algorithm is doing 1/ws") - - # Print the result - print ws.getHistory().lastAlgorithm().getPropertyValue("Note") - -Output: - -.. testoutput:: AddHistoryNoteExample - - The next algorithm is doing 1/ws - -.. categories:: - -.. sourcelink:: - diff --git a/docs/source/algorithms/Comment-v1.rst b/docs/source/algorithms/Comment-v1.rst new file mode 100644 index 0000000000000000000000000000000000000000..db25302c889abb13ed459bc1a5c6ed580f12b571 --- /dev/null +++ b/docs/source/algorithms/Comment-v1.rst @@ -0,0 +1,41 @@ + +.. algorithm:: + +.. summary:: + +.. alias:: + +.. properties:: + +Description +----------- + +This simple algorithm just adds a comment record to the history of a workspace and is a simple way of annotating your workflow. + +It does not change the data within a workspace in any way. + + +Usage +----- + +**Example - Comment** + +.. testcode:: CommentExample + + ws = CreateSampleWorkspace() + + Comment(ws,"The next algorithm is doing 1/ws") + + # Print the result + print ws.getHistory().lastAlgorithm().getPropertyValue("Text") + +Output: + +.. testoutput:: CommentExample + + The next algorithm is doing 1/ws + +.. categories:: + +.. sourcelink:: +