Skip to content

Commit

Permalink
Improve XML and other changes re #7617
Browse files Browse the repository at this point in the history
Use component-link format for banks and whole instrument
Tidy up includes
Prepare for use of table workspace columns.

Signed-off-by: Karl Palmen <karl.palmen@stfc.ac.uk>
  • Loading branch information
KarlPalmen committed Sep 17, 2013
1 parent 6847cd0 commit 1c17fa2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MANTID_DATAHANDLING_CONVERTFULLPROFTOXML_H_
#define MANTID_DATAHANDLING_CONVERTFULLPROFTOXML_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/ITableWorkspace.h"

namespace Mantid
{
Expand Down Expand Up @@ -57,14 +57,8 @@ namespace DataHandling
/// Load file to a vector of strings
void loadFile(std::string filename, std::vector<std::string>& lines);

/// Scan imported file for bank information
void scanBanks(const std::vector<std::string>& lines, std::vector<int>& banks,
std::map<int, int> &bankstartindexmap, std::map<int, int> &bankendindexmap);

/// Parse .irf file to a map
void parseResolutionStrings(std::map<std::string, double>& parammap, const std::vector<std::string>& lines, int bankid, int startlineindex, int endlineindex);

void parseBankLine(std::string line, double& cwl, int& bankid);
/// Get row numbers of the parameters in the table workspace
void getTableRowNumbers(const API::ITableWorkspace_sptr & tablews, std::map<std::string, size_t>& parammap);

};

Expand Down
59 changes: 34 additions & 25 deletions Code/Mantid/Framework/DataHandling/src/ConvertFullprofToXML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,28 @@ Convert the initial fitting parameters in a Fullprof file to XML format in an [[
#include "MantidDataHandling/ConvertFullprofToXML.h"
#include "MantidDataHandling/LoadFullprofResolution.h"
#include "MantidAPI/FileProperty.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/TableRow.h"

#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/iter_find.hpp>
#include <boost/algorithm/string/finder.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <fstream>

// Needed for writing the XML file (will be moved to a child algorithm)
#include <Poco/DOM/Document.h>
#include <Poco/DOM/DOMWriter.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/Text.h>

using namespace Poco::XML;

#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeList.h>
#include <Poco/DOM/NodeIterator.h>
#include <Poco/DOM/NodeFilter.h>


using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
using namespace std;

namespace Mantid
{
namespace DataHandling
{
using namespace API;
using namespace Poco::XML;

DECLARE_ALGORITHM(ConvertFullprofToXML)

Expand Down Expand Up @@ -78,14 +62,14 @@ namespace DataHandling
void ConvertFullprofToXML::init()
{
// Input file name
vector<std::string> exts;
std::vector<std::string> exts;
exts.push_back(".irf");
exts.push_back(".prf");
declareProperty(new FileProperty("InputFilename", "", FileProperty::Load, exts),
"Path to an Fullprof file to load.");

// Output file
vector<std::string> extso;
std::vector<std::string> extso;
extso.push_back(".xml");
declareProperty(new FileProperty("OutputFilename", "", FileProperty::Save, extso),
"The name to give to the parameter file.");
Expand All @@ -99,15 +83,13 @@ namespace DataHandling
void ConvertFullprofToXML::exec()
{
// Get input
string datafile = getProperty("InputFilename");
std::string datafile = getProperty("InputFilename");
// Get Output
string paramfile = getProperty("OutputFilename");
std::string paramfile = getProperty("OutputFilename");

//vector<int> outputbankids = getProperty("Banks");

// Load with LoadFullprofResolution
//LoadFullprofResolution loader;
//loader.initialize();
auto loader = createChildAlgorithm("LoadFullprofResolution");
loader->setProperty("Filename",datafile);
loader->executeAsChildAlg();
Expand Down Expand Up @@ -142,6 +124,12 @@ namespace DataHandling
rootElem->setAttribute("date", ISOdateShort);
mDoc->appendChild(rootElem);

// Add instrument
Element* instrumentElem = mDoc->createElement("component-link");
instrumentElem->setAttribute("name","wholeInstrument");
rootElem->appendChild(instrumentElem);

// Add banks
if(paramTable->columnCount() < 2){
throw std::runtime_error("No banks found");
}
Expand All @@ -151,7 +139,8 @@ namespace DataHandling
{
std::ostringstream bankName;
bankName << "Bank" << (i+1);
Element* bankElem = mDoc->createElement(bankName.str());
Element* bankElem = mDoc->createElement("component-link");
bankElem->setAttribute("name",bankName.str());
rootElem->appendChild(bankElem);
}

Expand All @@ -162,6 +151,26 @@ namespace DataHandling
return;
}

/* This function fills in a list of the row numbers starting 0 of the parameters
in the table workspace, so one can find the position in a column of
the value of the given parameter.
*/
void getTableRowNumbers(const API::ITableWorkspace_sptr & tablews, std::map<std::string, size_t>& parammap)
{
parammap.clear();

size_t numrows = tablews->rowCount();
for (size_t i = 0; i < numrows; ++i)
{
TableRow row = tablews->getRow(i);
std::string name;
row >> name;
parammap.insert(std::make_pair(name, i));
}

return;
}

} // namespace DataHandling
} // namespace Mantid

Expand Down

0 comments on commit 1c17fa2

Please sign in to comment.