Skip to content

Commit

Permalink
Refs #8913 Pass history recording parameter as arg to createChildAlg.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Apr 30, 2014
1 parent 07c3148 commit 897f607
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/Algorithm.h
Expand Up @@ -207,7 +207,6 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
bool isChild() const;
void setChild(const bool isChild);
void enableHistoryRecordingForChild(const bool on);
bool isRecordingHistoryForChild();
void setAlwaysStoreInADS(const bool doStore);
void setRethrows(const bool rethrow);

Expand Down Expand Up @@ -272,7 +271,7 @@ class MANTID_API_DLL Algorithm : public IAlgorithm, public Kernel::PropertyManag
//@}

virtual boost::shared_ptr<Algorithm> createChildAlgorithm(const std::string& name, const double startProgress = -1.,
const double endProgress = -1., const bool enableLogging=true, const int& version = -1);
const double endProgress = -1., const bool enableLogging=true, const int& version = -1, const bool recordHistory = false);

/// set whether we wish to track the child algorithm's history and pass it the parent object to fill.
void trackAlgorithmHistory(boost::shared_ptr<AlgorithmHistory> parentHist);
Expand Down
Expand Up @@ -47,7 +47,7 @@ class DLLExport DataProcessorAlgorithm : public Algorithm

protected:
virtual boost::shared_ptr<Algorithm> createChildAlgorithm(const std::string& name, const double startProgress = -1.,
const double endProgress = -1., const bool enableLogging=true, const int& version = -1);
const double endProgress = -1., const bool enableLogging=true, const int& version = -1, const bool recordHistory = true);
void setLoadAlg(const std::string & alg);
void setLoadAlgFileProp(const std::string & filePropName);
void setAccumAlg(const std::string & alg);
Expand Down
13 changes: 2 additions & 11 deletions Code/Mantid/Framework/API/src/Algorithm.cpp
Expand Up @@ -163,16 +163,6 @@ namespace Mantid
m_recordHistoryForChild = on;
}

/**
* Get the state of the history recording flag. Only applicable for
* child algorithms.
* @return The state of the flag
*/
bool Algorithm::isRecordingHistoryForChild()
{
return m_recordHistoryForChild;
}

/** Do we ALWAYS store in the AnalysisDataService? This is set to true
* for python algorithms' child algorithms
*
Expand Down Expand Up @@ -811,9 +801,10 @@ namespace Mantid
* @return shared pointer to the newly created algorithm object
*/
Algorithm_sptr Algorithm::createChildAlgorithm(const std::string& name, const double startProgress, const double endProgress,
const bool enableLogging, const int& version)
const bool enableLogging, const int& version, const bool recordHistory)
{
Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged(name,version);
alg->enableHistoryRecordingForChild(recordHistory);
//set as a child
alg->setChild(true);
alg->setLogging(enableLogging);
Expand Down
7 changes: 3 additions & 4 deletions Code/Mantid/Framework/API/src/DataProcessorAlgorithm.cpp
Expand Up @@ -32,7 +32,6 @@ namespace API
m_accumulateAlg = "Plus";
m_loadAlgFileProp = "Filename";
m_useMPI = false;
enableHistoryRecordingForChild(true);
}

//----------------------------------------------------------------------------------------------
Expand All @@ -44,12 +43,12 @@ namespace API

//----------------------------------------------------------------------------------------------
boost::shared_ptr<Algorithm> DataProcessorAlgorithm::createChildAlgorithm(const std::string& name, const double startProgress,
const double endProgress, const bool enableLogging, const int& version)
const double endProgress, const bool enableLogging, const int& version, const bool recordHistory)
{

//call parent method to create the child algorithm
auto alg = Algorithm::createChildAlgorithm(name, startProgress, endProgress, enableLogging, version);
if (isRecordingHistoryForChild())
auto alg = Algorithm::createChildAlgorithm(name, startProgress, endProgress, enableLogging, version, recordHistory);
if (recordHistory)
{
//pass pointer to the history object created in Algorithm to the child
alg->trackAlgorithmHistory(m_history);
Expand Down
6 changes: 4 additions & 2 deletions Code/Mantid/Framework/API/test/DataProcessorAlgorithmTest.h
Expand Up @@ -112,10 +112,12 @@ class TopLevelAlgorithm : public DataProcessorAlgorithm
{
declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input));
declareProperty(new WorkspaceProperty<MatrixWorkspace>("OutputWorkspace","", Direction::Output));
declareProperty("RecordHistory", true, Direction::Input);
}
void exec()
{
auto alg = createChildAlgorithm("NestedAlgorithm");
const bool recordHistory = static_cast<bool>(getProperty("RecordHistory"));
auto alg = createChildAlgorithm("NestedAlgorithm", -1., -1., true, -1, recordHistory);
alg->initialize();
alg->execute();

Expand Down Expand Up @@ -186,8 +188,8 @@ class DataProcessorAlgorithmTest : public CxxTest::TestSuite
TopLevelAlgorithm alg;
alg.initialize();
alg.setRethrows(true);
alg.enableHistoryRecordingForChild(false);
alg.setProperty("InputWorkspace", input);
alg.setProperty("RecordHistory", false);
alg.setPropertyValue("OutputWorkspace", "test_output_workspace");

TS_ASSERT_THROWS_NOTHING( alg.execute() );
Expand Down
Expand Up @@ -54,7 +54,7 @@ void export_leaf_classes()
.def("setOptionalMessage", &Algorithm::setOptionalMessage)
.def("createChildAlgorithm", &Algorithm::createChildAlgorithm,
(arg("name"),arg("startProgress")=-1.0,arg("endProgress")=-1.0,
arg("enableLogging")=true,arg("version")=-1), "Creates and intializes a named child algorithm. Output workspaces are given a dummy name.")
arg("enableLogging")=true,arg("version")=-1,arg("recordHistory")=false), "Creates and intializes a named child algorithm. Output workspaces are given a dummy name.")

.def("declareProperty", (declarePropertyType1)&PythonAlgorithm::declarePyAlgProperty,
declarePropertyType1_Overload((arg("self"), arg("prop"), arg("doc") = "")))
Expand Down

0 comments on commit 897f607

Please sign in to comment.