Skip to content
Snippets Groups Projects
LoadMappingTable.cpp 1.88 KiB
Newer Older
Laurent Chapon's avatar
Laurent Chapon committed
#include "MantidKernel/Exception.h"
Nick Draper's avatar
Nick Draper committed
#include "LoadRaw/isisraw2.h"
Laurent Chapon's avatar
Laurent Chapon committed
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidAPI/SpectraDetectorMap.h"
Laurent Chapon's avatar
Laurent Chapon committed
#include "MantidDataHandling/LoadMappingTable.h"
Laurent Chapon's avatar
Laurent Chapon committed

namespace Mantid
{
namespace DataHandling
{

using namespace Kernel;
using namespace API;

DECLARE_ALGORITHM(LoadMappingTable)

LoadMappingTable::LoadMappingTable()
{
}
Laurent Chapon's avatar
Laurent Chapon committed
void LoadMappingTable::init()
{
  declareProperty(new FileProperty("Filename","", FileProperty::Load),
		  "The name of the RAW file from which to obtain the mapping information,\n"
		  "including its full or relative path" );
  declareProperty(
    new WorkspaceProperty<MatrixWorkspace>("Workspace","Anonymous",Direction::InOut),
    "The name of the input and output workspace on which to perform the\n"
    "algorithm" );
Laurent Chapon's avatar
Laurent Chapon committed
}
Laurent Chapon's avatar
Laurent Chapon committed
void LoadMappingTable::exec()
{
  //Get the raw file name
  m_filename = getPropertyValue("Filename");
  // Get the input workspace
  const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
Nick Draper's avatar
Nick Draper committed
        
  /// ISISRAW class instance which does raw file reading. Shared pointer to prevent memory leak when an exception is thrown.
  boost::shared_ptr<ISISRAW2> iraw(new ISISRAW2);

  if (iraw->readFromFile(m_filename.c_str(),0) != 0) // ReadFrom File with no data
  {
    g_log.error("Unable to open file " + m_filename);
    throw Kernel::Exception::FileError("Unable to open File:" , m_filename);
  }
Nick Draper's avatar
Nick Draper committed
  const int number_spectra=iraw->i_det; // Number of entries in the spectra/udet table
  if ( number_spectra == 0 )
  {
    g_log.warning("The spectra to detector mapping table is empty");
  }
Nick Draper's avatar
Nick Draper committed
  localWorkspace->mutableSpectraMap().populate(iraw->spec,iraw->udet,number_spectra);
Nick Draper's avatar
Nick Draper committed
  iraw.reset();
Laurent Chapon's avatar
Laurent Chapon committed
}

} // Namespace DataHandling
} // Namespace Mantid