Skip to content

Commit

Permalink
Re #11096 Merge branch '11096/SumFilesAndDiagMultipleRuns'into develop
Browse files Browse the repository at this point in the history
Conflicts:
	Code/Mantid/scripts/Inelastic/Direct/DirectEnergyConversion.py
	Code/Mantid/scripts/Inelastic/Direct/PropertiesDescriptors.py
	Code/Mantid/scripts/Inelastic/Direct/PropertyManager.py
	Code/Mantid/scripts/Inelastic/Direct/ReductionHelpers.py
	Code/Mantid/scripts/Inelastic/Direct/ReductionWrapper.py
	Code/Mantid/scripts/Inelastic/Direct/RunDescriptor.py
	Code/Mantid/scripts/Inelastic/Direct/diagnostics.py
  • Loading branch information
abuts committed Feb 22, 2015
2 parents 6104c55 + 7958418 commit 692a654
Show file tree
Hide file tree
Showing 321 changed files with 2,528 additions and 1,616 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Build/CMake/CppCheck_Suppressions.txt
Expand Up @@ -4,6 +4,6 @@

// suppress in all files - BE CAREFULL not to leave trailing spaces after the rule id. or empty lines
// For a library this is not a problem per se
unusedFunction
// unusedFunction
// cppcheck has problems handling the number of pre-processor definitions used in the DLL_EXPORTs
class_X_Y
class_X_Y
26 changes: 25 additions & 1 deletion Code/Mantid/Framework/API/src/ScriptBuilder.cpp
Expand Up @@ -4,6 +4,8 @@
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/HistoryItem.h"
#include "MantidAPI/ScriptBuilder.h"
#include "MantidKernel/Property.h"
#include "MantidKernel/Logger.h"

#include <boost/utility.hpp>

Expand All @@ -13,6 +15,10 @@ namespace API {
using Mantid::Kernel::PropertyHistory_sptr;
using Mantid::Kernel::PropertyHistory_const_sptr;

namespace {
Mantid::Kernel::Logger g_log("ScriptBuilder");
}

ScriptBuilder::ScriptBuilder(boost::shared_ptr<HistoryView> view,
std::string versionSpecificity)
: m_historyItems(view->getAlgorithmsList()), m_output(),
Expand Down Expand Up @@ -156,13 +162,31 @@ ScriptBuilder::buildAlgorithmString(AlgorithmHistory_const_sptr algHistory) {
*/
const std::string
ScriptBuilder::buildPropertyString(PropertyHistory_const_sptr propHistory) {
using Mantid::Kernel::Direction;

// Create a vector of all non workspace property type names
std::vector<std::string> nonWorkspaceTypes;
nonWorkspaceTypes.push_back("number");
nonWorkspaceTypes.push_back("boolean");
nonWorkspaceTypes.push_back("string");

std::string prop = "";
// No need to specify value for default properties
if (!propHistory->isDefault()) {
if (propHistory->type() == "number") {
// Do not give values to output properties other than workspace properties
if (find(nonWorkspaceTypes.begin(), nonWorkspaceTypes.end(),
propHistory->type()) != nonWorkspaceTypes.end() &&
propHistory->direction() == Direction::Output) {
g_log.debug() << "Ignoring property " << propHistory->name()
<< " of type " << propHistory->type() << std::endl;
// Handle numerical properties
} else if (propHistory->type() == "number") {
prop = propHistory->name() + "=" + propHistory->value();
// Handle boolean properties
} else if (propHistory->type() == "boolean") {
std::string value = (propHistory->value() == "1" ? "True" : "False");
prop = propHistory->name() + "=" + value;
// Handle all other property types
} else {
std::string opener = "='";
if (propHistory->value().find('\\') != std::string::npos) {
Expand Down
20 changes: 11 additions & 9 deletions Code/Mantid/Framework/API/test/ScriptBuilderTest.h
Expand Up @@ -27,7 +27,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
const std::string workspaceMethodName() const { return "methodname"; }
const std::string workspaceMethodOnTypes() const { return "MatrixWorkspace;ITableWorkspace"; }
const std::string workspaceMethodInputProperty() const { return "InputWorkspace"; }

void init()
{
declareProperty("PropertyA", "Hello");
Expand All @@ -52,11 +52,12 @@ class ScriptBuilderTest : public CxxTest::TestSuite
const std::string workspaceMethodName() const { return "methodname"; }
const std::string workspaceMethodOnTypes() const { return "MatrixWorkspace;ITableWorkspace"; }
const std::string workspaceMethodInputProperty() const { return "InputWorkspace"; }

void init()
{
declareProperty("PropertyA", "Hello");
declareProperty("PropertyB", "World");
declareProperty("PropertyC", "", Direction::Output);
}
void exec()
{
Expand All @@ -65,6 +66,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
alg->initialize();
alg->setProperty("PropertyA", "I Don't exist!");
alg->execute();
setProperty("PropertyC", "I have been set!");
}
};

Expand All @@ -81,7 +83,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
const std::string workspaceMethodName() const { return "methodname"; }
const std::string workspaceMethodOnTypes() const { return "MatrixWorkspace;ITableWorkspace"; }
const std::string workspaceMethodInputProperty() const { return "InputWorkspace"; }

void init()
{
declareProperty("PropertyA", 13);
Expand Down Expand Up @@ -115,7 +117,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
const std::string workspaceMethodName() const { return "methodname"; }
const std::string workspaceMethodOnTypes() const { return "Workspace;MatrixWorkspace;ITableWorkspace"; }
const std::string workspaceMethodInputProperty() const { return "InputWorkspace"; }

void init()
{
declareProperty(new WorkspaceProperty<MatrixWorkspace>("InputWorkspace", "", Direction::Input));
Expand All @@ -137,7 +139,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
};

private:

public:

void setUp()
Expand All @@ -155,7 +157,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
Mantid::API::AlgorithmFactory::Instance().unsubscribe("BasicAlgorithm",1);
Mantid::API::AlgorithmFactory::Instance().unsubscribe("SubAlgorithm",1);
}

void test_Build_Simple()
{
std::string result[] = {
Expand Down Expand Up @@ -220,7 +222,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
alg->setRethrows(true);
alg->setProperty("InputWorkspace", input);
alg->setPropertyValue("OutputWorkspace", "test_output_workspace");
alg->execute();
alg->execute();

auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("test_output_workspace");
auto wsHist = ws->getHistory();
Expand Down Expand Up @@ -280,7 +282,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
alg->setProperty("InputWorkspace", "test_output_workspace");
alg->setPropertyValue("OutputWorkspace", "test_output_workspace");
alg->execute();

auto ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("test_output_workspace");
auto wsHist = ws->getHistory();
auto view = wsHist.createView();
Expand All @@ -305,7 +307,7 @@ class ScriptBuilderTest : public CxxTest::TestSuite
AnalysisDataService::Instance().remove("test_input_workspace");
}


void test_Build_Simple_with_backslash()
{
//checks that property values with \ get prefixed with r, eg. filename=r'c:\test\data.txt'
Expand Down
111 changes: 28 additions & 83 deletions Code/Mantid/Framework/Algorithms/test/RemoveExpDecayTest.h
Expand Up @@ -3,124 +3,69 @@

#include <cxxtest/TestSuite.h>

#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/Workspace.h"
#include "MantidAlgorithms/RemoveExpDecay.h"
#include "MantidDataHandling/LoadInstrument.h"
#include "MantidDataHandling/LoadMuonNexus2.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"

#include <stdexcept>

using namespace Mantid::Algorithms;
using namespace Mantid::API;

const std::string outputName = "MuonRemoveExpDecay_Output";

class RemoveExpDecayTest : public CxxTest::TestSuite
{
public:

void testName()
{
TS_ASSERT_EQUALS( alg.name(), "RemoveExpDecay" )
}

void testCategory()
{
TS_ASSERT_EQUALS( alg.category(), "Muon" )
}

void testInit()
{
MuonRemoveExpDecay alg;
alg.initialize();
TS_ASSERT( alg.isInitialized() )
}

void testLoadNexusAndSetProperties()
{
//This test does not run on Windows64 as is does not support HDF4 files

loader.initialize();
loader.setPropertyValue("Filename", "emu00006473.nxs");
loader.setPropertyValue("OutputWorkspace", "EMU6473");
TS_ASSERT_THROWS_NOTHING( loader.execute() );
TS_ASSERT_EQUALS(loader.isExecuted(),true);

alg.setPropertyValue("InputWorkspace", "EMU6473");
alg.setPropertyValue("OutputWorkspace", "Result");
alg.setPropertyValue("Spectra", "0");
}

void testProperties()
{
//This test does not run on Windows64 as is does not support HDF4 files
TS_ASSERT_EQUALS( alg.getPropertyValue("Spectra"), "0");
TS_ASSERT(alg.isInitialized())
}

void testExecute()
{
//This test does not run on Windows64 as is does not support HDF4 files
try
{
TS_ASSERT_EQUALS(alg.execute(),true);
}
catch(std::runtime_error & e)
{
TS_FAIL(e.what());
}
auto ws = WorkspaceCreationHelper::Create2DWorkspace(1,1);

Workspace_const_sptr outputWS = AnalysisDataService::Instance().retrieve("Result");
MuonRemoveExpDecay alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
alg.setChild(true);
alg.setProperty("InputWorkspace", ws);
alg.setPropertyValue("OutputWorkspace", outputName);
alg.setPropertyValue("Spectra", "0");
TS_ASSERT_THROWS_NOTHING(alg.execute());
TS_ASSERT(alg.isExecuted())
}

void testWhereOptional3rdArgNotSet()
void testExecuteWhereSepctraNotSet()
{
//This test does not run on Windows64 as is does not support HDF4 files

MuonRemoveExpDecay alg2;
alg2.initialize();

alg2.setPropertyValue("InputWorkspace", "EMU6473");
alg2.setPropertyValue("OutputWorkspace", "MuonRemoveExpDecayResult");
auto ws = WorkspaceCreationHelper::Create2DWorkspace(1,1);

try
{
TS_ASSERT_EQUALS(alg2.execute(),true);
}
catch(std::runtime_error & e)
{
TS_FAIL(e.what());
}
MuonRemoveExpDecay alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
alg.setChild(true);
alg.setProperty("InputWorkspace", ws);
alg.setPropertyValue("OutputWorkspace", outputName);
TS_ASSERT_THROWS_NOTHING(alg.execute());
TS_ASSERT(alg.isExecuted())
}

void test_yUnitLabel()
{
const std::string outputWSName = "RemoveExpDecayTest_yUnitLabel_OutputWS";

auto ws = WorkspaceCreationHelper::Create2DWorkspace(1,1);

MuonRemoveExpDecay alg;
alg.initialize();
alg.setChild(true);
alg.setProperty("InputWorkspace", ws);
alg.setProperty("OutputWorkspace", outputWSName);
alg.setProperty("OutputWorkspace", outputName);
alg.execute();

auto result = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(outputWSName);

MatrixWorkspace_sptr result = alg.getProperty("OutputWorkspace");
TS_ASSERT(result);

if( result )
{
TS_ASSERT_EQUALS( result->YUnitLabel(), "Asymmetry" );
}

AnalysisDataService::Instance().remove(outputWSName);
TS_ASSERT_EQUALS(result->YUnitLabel(), "Asymmetry");
}


private:
MuonRemoveExpDecay alg;
Mantid::DataHandling::LoadMuonNexus2 loader;

};

#endif /*MUONREMOVEEXPDECAYTEST_H_*/
@@ -1,8 +1,8 @@
#pylint: disable=no-init
import mantid.simpleapi as api
from mantid.api import *
from mantid.kernel import *
from mantid import config
import os

MICROEV_TO_MILLIEV = 1000.0
DEFAULT_BINS = [0., 0., 0.]
Expand Down Expand Up @@ -60,7 +60,7 @@ def PyExec(self):
self._groupDetOpt = self.getProperty("GroupDetectors").value

datasearch = config["datasearch.searcharchive"]
if (datasearch != "On"):
if datasearch != "On":
config["datasearch.searcharchive"] = "On"

# Handle masking file override if necessary
Expand Down Expand Up @@ -217,7 +217,7 @@ def _calibData(self, sam_ws, mon_ws):
api.MaskDetectors(Workspace=sam_ws,
DetectorList=self._dMask)
#MaskedWorkspace='BASIS_MASK')
api.ModeratorTzeroLinear(InputWorkspace=sam_ws,
api.ModeratorTzeroLinear(InputWorkspace=sam_ws,\
OutputWorkspace=sam_ws)
api.LoadParameterFile(Workspace=sam_ws,
Filename=config.getInstrumentDirectory() + 'BASIS_silicon_111_Parameters.xml')
Expand All @@ -226,7 +226,7 @@ def _calibData(self, sam_ws, mon_ws):
Target='Wavelength', EMode='Indirect')

if not self._noMonNorm:
api.ModeratorTzeroLinear(InputWorkspace=mon_ws,
api.ModeratorTzeroLinear(InputWorkspace=mon_ws,\
OutputWorkspace=mon_ws)
api.Rebin(InputWorkspace=mon_ws,
OutputWorkspace=mon_ws, Params='10')
Expand Down

0 comments on commit 692a654

Please sign in to comment.