Skip to content

Commit

Permalink
Re #8108. Add loading of the parameter file to LoadIDFFromNexus.
Browse files Browse the repository at this point in the history
However, the algorithm doesn't fail if the parameter file is missing.
  • Loading branch information
RussellTaylor committed Oct 16, 2013
1 parent 8d799fa commit f36487f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
Expand Up @@ -8,14 +8,6 @@

namespace Mantid
{

namespace Geometry
{
class CompAssembly;
class Component;
class Instrument;
}

namespace DataHandling
{
/** @class LoadIDFFromNexus LoadInstrumentFromNexus.h DataHandling/LoadIDFFromNexus.h
Expand All @@ -36,10 +28,7 @@ namespace Mantid
<LI> Workspace - The name of the workspace in which to use as a basis for any data to be added.</LI>
</UL>
@author Karl Palmen, ISIS, RAL (LoadInstrumentFromRaw)
Copyright &copy; 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Expand Down Expand Up @@ -68,26 +57,23 @@ namespace Mantid
virtual ~LoadIDFFromNexus() {}

/// Algorithm's name for identification overriding a virtual method
virtual const std::string name() const { return "LoadIDFFromNexus";};
virtual const std::string name() const { return "LoadIDFFromNexus";}

/// Algorithm's version for identification overriding a virtual method
virtual int version() const { return 1;};
virtual int version() const { return 1;}

/// Algorithm's category for identification overriding a virtual method
virtual const std::string category() const { return "DataHandling\\Instrument";}

private:
/// Sets documentation strings for this algorithm
virtual void initDocs();

/// Overwrites Algorithm method. Does nothing at present
void init();

/// Overwrites Algorithm method
void exec();

/// The name and path of the input file
std::string m_filename;
void runLoadParameterFile(API::MatrixWorkspace_sptr workspace);
};

} // namespace DataHandling
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/DataHandling/src/LoadEventNexus.cpp
Expand Up @@ -1820,7 +1820,7 @@ bool LoadEventNexus::loadInstrument(const std::string & nexusfilename, MatrixWor
bool LoadEventNexus::runLoadIDFFromNexus(const std::string & nexusfilename, API::MatrixWorkspace_sptr localWorkspace,
const std::string & top_entry_name, Algorithm * alg)
{
IAlgorithm_sptr loadInst= alg->createChildAlgorithm("LoadIDFFromNexus",-1,-1,false);
IAlgorithm_sptr loadInst= alg->createChildAlgorithm("LoadIDFFromNexus");

// Now execute the Child Algorithm. Catch and log any error, but don't stop.
try
Expand Down
30 changes: 20 additions & 10 deletions Code/Mantid/Framework/DataHandling/src/LoadIDFFromNexus.cpp
Expand Up @@ -6,17 +6,10 @@
// Includes
//----------------------------------------------------------------------
#include "MantidDataHandling/LoadIDFFromNexus.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Detector.h"
#include "MantidGeometry/Instrument/CompAssembly.h"
#include "MantidGeometry/Instrument/Component.h"
#include "MantidNexus/MuonNexusReader.h"
#include "MantidDataHandling/LoadParameterFile.h"
#include "MantidKernel/ConfigService.h"
#include "MantidAPI/FileProperty.h"

#include <fstream>


namespace Mantid
{
namespace DataHandling
Expand Down Expand Up @@ -68,7 +61,7 @@ void LoadIDFFromNexus::init()
void LoadIDFFromNexus::exec()
{
// Retrieve the filename from the properties
m_filename = getPropertyValue("Filename");
const std::string filename = getPropertyValue("Filename");

// Get the input workspace
const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
Expand All @@ -77,17 +70,34 @@ void LoadIDFFromNexus::exec()
std::string instrumentParentPath = getPropertyValue("InstrumentParentPath");

// Get the instrument group in the Nexus file
::NeXus::File nxfile(m_filename);
::NeXus::File nxfile(filename);
// Assume one level in instrument path
nxfile.openPath(instrumentParentPath);

std::string parameterString;
localWorkspace->loadExperimentInfoNexus( &nxfile, parameterString );
localWorkspace->readParameterMap(parameterString);

runLoadParameterFile(localWorkspace);

return;
}

void LoadIDFFromNexus::runLoadParameterFile(MatrixWorkspace_sptr workspace)
{
const std::string directory = ConfigService::Instance().getString("parameterDefinition.directory");
const std::string instrumentName = workspace->getInstrument()->getName();
const std::string paramFile = directory + instrumentName + "_Parameters.xml";

try {
LoadParameterFile::execManually(paramFile, workspace);
} catch ( std::runtime_error& ex) {
g_log.notice() << "File " << paramFile << " not found or un-parsable. "
"However, the instrument has been loaded successfully.\n";
}

}


} // namespace DataHandling
} // namespace Mantid

0 comments on commit f36487f

Please sign in to comment.