Skip to content

Commit

Permalink
Re #9261 Put parameters into workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelalvarezbanos committed Jan 26, 2015
1 parent 72a0bd8 commit 90046a9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 18 deletions.
Expand Up @@ -113,6 +113,12 @@ class DLLExport LoadFullprofResolution : public API::Algorithm {
// name in the XML file
static std::string getXMLParameterName(const std::string &name);

/// Create Bank to Workspace Correspondence
static void createBankToWorkspaceMap ( const std::vector<int>& banks, const std::vector<int>& workspaces, std::map< int, size_t>& WorkpsaceOfBank );

/// Place to store the row numbers
static std::map<std::string, size_t> m_rowNumbers;

private:
/// Implement abstract Algorithm methods
void init();
Expand Down Expand Up @@ -152,17 +158,11 @@ class DLLExport LoadFullprofResolution : public API::Algorithm {
DataObjects::TableWorkspace_sptr
genTableWorkspace(std::map<int, std::map<std::string, double>> bankparammap);

/// Generate bank information workspace
DataObjects::TableWorkspace_sptr
genInfoTableWorkspace(std::vector<int> banks);

/// Create Bank to Workspace Correspondence
void createBankToWorkspaceMap(const std::vector<int> &banks,
const std::vector<int> &workspaces,
std::map<int, size_t> &WorkpsaceOfBank);

/// Place to store the row numbers
static std::map<std::string, size_t> m_rowNumbers;
///// Generate bank information workspace
//DataObjects::TableWorkspace_sptr
//genInfoTableWorkspace(std::vector<int> banks);
// const std::vector<int> &workspaces,
// std::map<int, size_t> &WorkpsaceOfBank);
};

} // namespace DataHandling
Expand Down
@@ -1,5 +1,5 @@
#ifndef MANTID_DATAHANDLING_LOADFULLPROFRESOLUTION_H_
#define MANTID_DATAHANDLING_LOADFULLPROFRESOLUTION_H_
#ifndef MANTID_DATAHANDLING_LOADGSASINSTRUMENTFILE_H_
#define MANTID_DATAHANDLING_LOADGSASINSTRUMENTFILE_H_

#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
Expand Down Expand Up @@ -89,4 +89,4 @@ class DLLExport LoadGSASInstrumentFile : public API::Algorithm {
} // namespace DataHandling
} // namespace Mantid

#endif /* MANTID_DATAHANDLING_LOADFULLPROFRESOLUTION_H_ */
#endif /* MANTID_DATAHANDLING_LOADGSASINSTRUMENTFILE_H_ */
80 changes: 76 additions & 4 deletions Code/Mantid/Framework/DataHandling/src/LoadGSASInstrumentFile.cpp
Expand Up @@ -7,6 +7,7 @@
#include "MantidAPI/InstrumentDataService.h"
#include "MantidGeometry/Instrument/InstrumentDefinitionParser.h"
#include "MantidDataHandling/LoadParameterFile.h"
#include "MantidDataHandling/LoadFullprofResolution.h"

#include <Poco/DOM/DOMWriter.h>
#include <Poco/DOM/Element.h>
Expand Down Expand Up @@ -37,6 +38,7 @@ namespace DataHandling {

DECLARE_ALGORITHM(LoadGSASInstrumentFile)


//----------------------------------------------------------------------------------------------
/** Constructor
*/
Expand All @@ -63,6 +65,29 @@ void LoadGSASInstrumentFile::init() {
declareProperty(wsprop, "Name of the output TableWorkspace containing "
"instrument parameter information read from file. ");

// Use bank numbers as given in file
declareProperty(
new PropertyWithValue<bool>("UseBankIDsInFile", true, Direction::Input),
"Use bank IDs as given in file rather than ordinal number of bank. "
"If the bank IDs in the file are not unique, it is advised to set this to false." );

// Bank to import
declareProperty(new ArrayProperty<int>("Banks"), "ID(s) of specified bank(s) to load, "
"The IDs are as specified by UseBankIDsInFile. "
"Default is all banks contained in input .prm file.");

// Workspace to put parameters into. It must be a workspace group with one worskpace per bank from the prm file
declareProperty(new WorkspaceProperty<WorkspaceGroup>("Workspace","",Direction::InOut, PropertyMode::Optional),
"A workspace group with the instrument to which we add the parameters from the GSAS instrument file, with one workspace for each bank of the .prm file");

// Workspaces for each bank
declareProperty(new ArrayProperty<int>("WorkspacesForBanks"), "For each bank,"
" the ID of the corresponding workspace in same order as the banks are specified. "
"ID=1 refers to the first workspace in the workspace group, "
"ID=2 refers to the second workspace and so on. "
"Default is all workspaces in numerical order. "
"If default banks are specified, they too are taken to be in numerical order" );

return;
}

Expand All @@ -89,6 +114,7 @@ void LoadGSASInstrumentFile::exec() {
}
}

int nProf = 2;
size_t numBanks = getNumberOfBanks(lines);
g_log.debug() << numBanks << "banks in file \n";

Expand Down Expand Up @@ -122,17 +148,63 @@ void LoadGSASInstrumentFile::exec() {
g_log.debug() << "Bank starts at line" << bankStartIndex[i] + 1 << "\n";
}

// Get Workspace property
WorkspaceGroup_sptr wsg = getProperty("Workspace");
// Generate output table workspace
API::ITableWorkspace_sptr outTabWs = genTableWorkspace(bankparammap);

if (getPropertyValue("OutputTableWorkspace") != "") {
// Output the output table workspace
setProperty("OutputTableWorkspace", outTabWs);
}
if ( wsg )
{
vector<int> bankIds = getProperty("Banks");
vector<int> workspaceIds = getProperty("WorkspacesForBanks");
map < int, size_t > workspaceOfBank;

// Deal with bankIds
if ( bankIds.size() )
{
// If user provided a list of banks, check that they exist in the .prm file
for (size_t i=0; i<bankIds.size(); i++)
{
if ( !bankparammap.count(bankIds[i]) )
{
std::stringstream errorString;
errorString << "Bank " << bankIds[i] << " not found in .prm file";
throw runtime_error(errorString.str());
}
}
}
else
{
// Else, use all available banks
for(map<size_t,map<string,double> >::iterator it=bankparammap.begin(); it!=bankparammap.end(); ++it)
{
bankIds.push_back(static_cast<int>(it->first));
}
}

if (getPropertyValue("OutputTableWorkspace") == "") {
// We don't know where to output
throw std::runtime_error("OutputTableWorkspace must be set.");
// Generate workspaceOfBank
LoadFullprofResolution::createBankToWorkspaceMap ( bankIds, workspaceIds, workspaceOfBank);
// Put parameters into workspace group
LoadFullprofResolution::getTableRowNumbers( outTabWs, LoadFullprofResolution::m_rowNumbers);
for (size_t i=0; i < bankIds.size(); ++i)
{
int bankId = bankIds[i];
size_t wsId = workspaceOfBank[bankId];
Workspace_sptr wsi = wsg->getItem(wsId-1);
auto workspace = boost::dynamic_pointer_cast<MatrixWorkspace>(wsi);
// Get column from table workspace
API::Column_const_sptr OutTabColumn = outTabWs->getColumn( i+1 );
std::string parameterXMLString;
LoadFullprofResolution::putParametersIntoWorkspace( OutTabColumn, workspace, static_cast<int>(bankparammap[i]["NPROF"]), parameterXMLString );
// Load the string into the workspace
Algorithm_sptr loadParamAlg = createChildAlgorithm("LoadParameterFile");
loadParamAlg->setProperty("ParameterXML", parameterXMLString);
loadParamAlg->setProperty("Workspace", workspace);
loadParamAlg->execute();
}
}

return;
Expand Down

0 comments on commit 90046a9

Please sign in to comment.