Skip to content

Commit

Permalink
Implemented change to Parameter File Selection re #5635
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 Dec 13, 2012
1 parent 9420245 commit 6d454d2
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions Code/Mantid/Framework/DataHandling/src/LoadInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,34 @@ namespace Mantid
// Remove the path from the filename
const std::string::size_type stripPath = m_filename.find_last_of("\\/");
std::string instrumentFile = m_filename.substr(stripPath+1,m_filename.size());
// the ID is the bit in front of _Definition
const std::string::size_type getID(instrumentFile.find("_Definition"));
std::string instrumentID = instrumentFile.substr(0,getID);

// force ID to upper case
std::transform(instrumentID.begin(), instrumentID.end(), instrumentID.begin(), toupper);
std::string fullPathIDF = directoryName + "/" + instrumentID + "_Parameters.xml";
// First check whether there is a parameter file whose name is the same as the IDF file,
// but with 'Parameters' instead of 'Definition'.
std::string definitionPart("_Definition");
const std::string::size_type prefix_end(instrumentFile.find(definitionPart));
const std::string::size_type suffix_start = prefix_end + definitionPart.length();
// Make prefix and force it to be upper case
std::string prefix = instrumentFile.substr(0, prefix_end);
std::transform(prefix.begin(), prefix.end(), prefix.begin(), toupper);
// Make suffix ensuring it has positive length
std::string suffix = ".xml";
if( suffix_start < instrumentFile.length() )
{
suffix = instrumentFile.substr(suffix_start, std::string::npos );
}
// Assemble parameter file name
std::string fullPathParamIDF = directoryName + "/" + prefix + "_Parameters" + suffix;
if( Poco::File(fullPathParamIDF).exists() == false)
{ // No such file exists, so look for file based on instrument ID given by the prefix
fullPathParamIDF = directoryName + "/" + prefix + "_Parameters.xml";
}

g_log.debug() << "Parameter file: " << fullPathIDF << std::endl;
g_log.debug() << "Parameter file: " << fullPathParamIDF << std::endl;
// Now execute the sub-algorithm. Catch and log any error, but don't stop.
try
{
// To allow the use of ExperimentInfo instead of workspace, we call it manually
LoadParameterFile::execManually(fullPathIDF, m_workspace);
LoadParameterFile::execManually(fullPathParamIDF, m_workspace);
g_log.debug("Parameters loaded successfully.");
} catch (std::invalid_argument& e)
{
Expand Down

0 comments on commit 6d454d2

Please sign in to comment.