Skip to content

Commit

Permalink
Add instrument property and test it re #7617
Browse files Browse the repository at this point in the history
Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Oct 2, 2013
1 parent ccae6fe commit f050bcd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
37 changes: 25 additions & 12 deletions Code/Mantid/Framework/DataHandling/src/ConvertFullprofToXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ namespace DataHandling
declareProperty(new FileProperty("InputFilename", "", FileProperty::Load, exts),
"Path to an Fullprof file to load.");

// Instrument name
declareProperty("InstrumentName", "", "Name of instrument for the input file" );

// Output file
std::vector<std::string> extso;
extso.push_back(".xml");
Expand All @@ -75,14 +78,24 @@ namespace DataHandling

//----------------------------------------------------------------------------------------------
/** Implement abstract Algorithm methods
*/
*/
void ConvertFullprofToXML::exec()
{
// Get input
std::string datafile = getProperty("InputFilename");

// Get instrument
std::string instrumentName = getProperty("InstrumentName");

// Get Output
std::string paramfile = getProperty("OutputFilename");


// We need the instrument name because it is not extracted by LoadFullprofResolution and is
// needed by fitting despite also being available in the IDF.
if ( instrumentName.empty() )
throw std::runtime_error("The InstrumentName property must be set.");

// Load with LoadFullprofResolution
auto loader = createChildAlgorithm("LoadFullprofResolution");
loader->setProperty("Filename",datafile);
Expand Down Expand Up @@ -121,7 +134,7 @@ namespace DataHandling

// Add instrument
Element* instrumentElem = mDoc->createElement("component-link");
instrumentElem->setAttribute("name","GEM"); // We only support GEM at the present time
instrumentElem->setAttribute("name",instrumentName);
rootElem->appendChild(instrumentElem);
addALFBEParameter( paramTable, mDoc, instrumentElem, "Alph0");
addALFBEParameter( paramTable, mDoc, instrumentElem, "Beta0");
Expand Down Expand Up @@ -160,19 +173,19 @@ namespace DataHandling
*/
void ConvertFullprofToXML::addALFBEParameter(const API::ITableWorkspace_sptr & tablews, Poco::XML::Document* mDoc, Element* parent, const std::string& paramName)
{
Element* parameterElem = mDoc->createElement("parameter");
parameterElem->setAttribute("name", getXMLParameterName(paramName));
parameterElem->setAttribute("type","fitting");
Element* parameterElem = mDoc->createElement("parameter");
parameterElem->setAttribute("name", getXMLParameterName(paramName));
parameterElem->setAttribute("type","fitting");

Element *formulaElem = mDoc->createElement("formula");
formulaElem->setAttribute("eq",getXMLEqValue(tablews, paramName, 1));
if(paramName != "Beta1") formulaElem->setAttribute("result-unit","TOF");
parameterElem->appendChild(formulaElem);
Element *formulaElem = mDoc->createElement("formula");
formulaElem->setAttribute("eq",getXMLEqValue(tablews, paramName, 1));
if(paramName != "Beta1") formulaElem->setAttribute("result-unit","TOF");
parameterElem->appendChild(formulaElem);

Element* fixedElem = mDoc->createElement("fixed");
parameterElem->appendChild(fixedElem);
Element* fixedElem = mDoc->createElement("fixed");
parameterElem->appendChild(fixedElem);

parent->appendChild(parameterElem);
parent->appendChild(parameterElem);
}

/* Add a set of SIGMA paraters to the XML document according to the table workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ConvertFullprofToXMLTest : public CxxTest::TestSuite

// Set up
alg.setProperty("InputFilename", inputFilename);
alg.setProperty("InstrumentName","POWGEN");
alg.setProperty("OutputFileName", outputFilename);

// Execute
Expand Down Expand Up @@ -87,7 +88,7 @@ class ConvertFullprofToXMLTest : public CxxTest::TestSuite
TS_ASSERT(componentLinkElem1);
if(componentLinkElem1)
{
TS_ASSERT_EQUALS(componentLinkElem1->getAttribute("name"),"GEM");
TS_ASSERT_EQUALS(componentLinkElem1->getAttribute("name"),"POWGEN");

Poco::XML::NodeList* parameterNodeList = componentLinkElem1->getElementsByTagName("parameter"); // get parameter elements
size_t numParameters = parameterNodeList->length();
Expand Down Expand Up @@ -169,6 +170,36 @@ class ConvertFullprofToXMLTest : public CxxTest::TestSuite
return;
}

//---------------------------------------------------------------------------------------------
/** Test missing instrument parameter
*/
void testMissingInstrument()
{
// Generate file
string inputFilename("TestConvertFullprofToXMLInput.irf");
string outputFilename("TestConvertFullprofToXMLMissingInstrumentOutput.xml");
generate2BankIrfFile(inputFilename);

// Init LoadFullprofResolution
ConvertFullprofToXML alg;
alg.initialize();

// Set up
alg.setProperty("InputFilename", inputFilename);
alg.setProperty("InstrumentName","");
alg.setProperty("OutputFileName", outputFilename);

// Execute
TS_ASSERT(! alg.execute());

// Not only should algorithm fail, but also writes nothing to file.
outputFilename = alg.getPropertyValue("outputFilename"); //Get absolute path
TS_ASSERT( !Poco::File(outputFilename).exists() );

//Clean up
Poco::File(inputFilename).remove();
}

//----------------------------------------------------------------------------------------------
/** Do test on a parameter element
** parameElem: parameter element to be tested
Expand Down

0 comments on commit f050bcd

Please sign in to comment.