Newer
Older
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidDataHandling/LoadISISNexus2.h"
#include "MantidDataHandling/LoadEventNexus.h"
#include "MantidDataHandling/LoadRawHelper.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/LogParser.h"
#include "MantidKernel/LogFilter.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidKernel/UnitFactory.h"
Gigg, Martyn Anthony
committed
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/RegisterFileLoader.h"
Gigg, Martyn Anthony
committed
#include "MantidGeometry/Instrument/Detector.h"
Gigg, Martyn Anthony
committed
#include <nexus/NeXusFile.hpp>
#include <nexus/NeXusException.hpp>
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
#include <Poco/Path.h>
#include <Poco/DateTimeFormatter.h>
#include <Poco/DateTimeParser.h>
#include <Poco/DateTimeFormat.h>
Steve Williams
committed
#include <boost/lexical_cast.hpp>
#include <climits>
#include <sstream>
#include <cctype>
Gigg, Martyn Anthony
committed
#include <functional>
#include <algorithm>
namespace DataHandling
Russell Taylor
committed
{
DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadISISNexus2);
Gigg, Martyn Anthony
committed
using namespace Kernel;
using namespace API;
using namespace NeXus;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Empty default constructor
LoadISISNexus2::LoadISISNexus2() :
m_filename(), m_instrument_name(), m_samplename(),
m_detBlockInfo(),m_monBlockInfo(),m_loadBlockInfo(),
m_have_detector(false),
m_load_selected_spectra(false),m_specInd2specNum_map(),m_spec2det_map(),
m_entrynumber(0), m_tof_data(), m_proton_charge(0.),
m_spec(), m_monitors(), m_logCreator(), m_progress()
Gigg, Martyn Anthony
committed
{}
* Return the confidence criteria for this algorithm can load the file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not be used
*/
int LoadISISNexus2::confidence(Kernel::NexusDescriptor & descriptor) const
{
if(descriptor.pathOfTypeExists("/raw_data_1","NXentry")) return 80;
return 0;
}
Gigg, Martyn Anthony
committed
void LoadISISNexus2::init()
Gigg, Martyn Anthony
committed
{
Gigg, Martyn Anthony
committed
std::vector<std::string> exts;
Peterson, Peter
committed
exts.push_back(".nxs");
exts.push_back(".n*");
Gigg, Martyn Anthony
committed
declareProperty(new FileProperty("Filename", "", FileProperty::Load, exts),
"The name of the Nexus file to load" );
declareProperty(new WorkspaceProperty<Workspace>("OutputWorkspace","",Direction::Output));
auto mustBePositive = boost::make_shared<BoundedValidator<int64_t> >();
Gigg, Martyn Anthony
committed
mustBePositive->setLower(0);
Gigg, Martyn Anthony
committed
declareProperty("SpectrumMin",(int64_t)0, mustBePositive);
declareProperty("SpectrumMax",(int64_t)EMPTY_INT(), mustBePositive);
Gigg, Martyn Anthony
committed
declareProperty(new ArrayProperty<int64_t>("SpectrumList"));
declareProperty("EntryNumber", (int64_t)0, mustBePositive,
Gigg, Martyn Anthony
committed
"The particular entry number to read (default: Load all workspaces and creates a workspace group)");
std::vector<std::string> monitorOptions;
monitorOptions.push_back("Include");
monitorOptions.push_back("Exclude");
monitorOptions.push_back("Separate");
std::map<std::string,std::string> monitorOptionsAliases;
monitorOptionsAliases["1"] = "Separate";
monitorOptionsAliases["0"] = "Exclude";
declareProperty("LoadMonitors","Include", boost::make_shared<Kernel::StringListValidator>(monitorOptions,monitorOptionsAliases),
"Option to control the loading of monitors.\n"
"Allowed options are Include,Exclude, Separate.\n"
"Include:The default is Include option would load monitors with the workspace if monitors spectra are within the range of loaded detectors.\n"
"If the time binning for the monitors is different from the\n"
"binning of the detectors this option is equivalent to the Separate option\n"
"Exclude:Exclude option excludes monitors from the output workspace.\n"
"Separate:Separate option loads monitors into a separate workspace called: OutputWorkspace_monitors.\n"
"Defined aliases:\n"
"1: Equivalent to Separate.\n"
"0: Equivalent to Exclude.\n");
Gigg, Martyn Anthony
committed
}
Sofia Antony
committed
Gigg, Martyn Anthony
committed
/** Executes the algorithm. Reading in the file and creating and populating
* the output workspace
*
* @throw Exception::FileError If the Nexus file cannot be found/opened
* @throw std::invalid_argument If the optional properties are set to invalid values
*/
void LoadISISNexus2::exec()
Gigg, Martyn Anthony
committed
{
//**********************************************************************
// process load monitor options request
bool bincludeMonitors,bseparateMonitors, bexcludeMonitors;
LoadRawHelper::ProcessLoadMonitorOptions(bincludeMonitors,bseparateMonitors, bexcludeMonitors,this);
//**********************************************************************
Gigg, Martyn Anthony
committed
m_filename = getPropertyValue("Filename");
// Create the root Nexus class
NXRoot root(m_filename);
// "Open" the same file but with the C++ interface
m_cppFile.reset( new ::NeXus::File(root.m_fileID));
// Open the raw data group 'raw_data_1'
NXEntry entry = root.openEntry("raw_data_1");
Gigg, Martyn Anthony
committed
// Read in the instrument name from the Nexus file
m_instrument_name = entry.getString("name");
//Test if we have a detector block
Gigg, Martyn Anthony
committed
try
Gigg, Martyn Anthony
committed
{
NXClass det_class = entry.openNXGroup("detector_1");
NXInt spectrum_index = det_class.openNXInt("spectrum_index");
Gigg, Martyn Anthony
committed
spectrum_index.load();
ndets = spectrum_index.dim0();
Russell Taylor
committed
// We assume that this spectrum list increases monotonically
m_spec = spectrum_index.sharedBuffer();
m_spec_end = m_spec.get() + ndets;
Gigg, Martyn Anthony
committed
m_have_detector = true;
}
catch(std::runtime_error &)
{
ndets = 0;
Gigg, Martyn Anthony
committed
}
NXInt nsp1 = entry.openNXInt("isis_vms_compat/NSP1");
Gigg, Martyn Anthony
committed
nsp1.load();
NXInt udet = entry.openNXInt("isis_vms_compat/UDET");
Gigg, Martyn Anthony
committed
udet.load();
NXInt spec = entry.openNXInt("isis_vms_compat/SPEC");
Gigg, Martyn Anthony
committed
spec.load();
//Pull out the monitor blocks, if any exist
for(std::vector<NXClassInfo>::const_iterator it = entry.groups().begin();
it != entry.groups().end(); ++it)
Gigg, Martyn Anthony
committed
{
if (it->nxclass == "NXmonitor") // Count monitors
Gigg, Martyn Anthony
committed
{
NXInt index = entry.openNXInt(std::string(it->nxname) + "/spectrum_index");
index.load();
int64_t ind = *index();
m_monitors[ind ] = it->nxname;
++nmons;
Gigg, Martyn Anthony
committed
}
}
Gigg, Martyn Anthony
committed
if( ndets == 0 && nmons == 0 )
{
Gigg, Martyn Anthony
committed
{
g_log.warning() << "Nothing to do. No detectors found and no monitor loading requested";
return;
}
else
{
g_log.error() << "Invalid NeXus structure, cannot find detector or monitor blocks.";
throw std::runtime_error("Inconsistent NeXus file structure.");
Gigg, Martyn Anthony
committed
}
}
std::set<specid_t> ExcluedMonitorsSpectra;
bseparateMonitors=findSpectraDetRangeInFile(entry,m_spec,ndets,nsp1[0],m_monitors,bexcludeMonitors,bseparateMonitors,ExcluedMonitorsSpectra);
const size_t x_length = m_detBlockInfo.numberOfChannels + 1;
// Check input is consistent with the file, throwing if not, exclude spectra selected at findSpectraDetRangeInFile;
Loading
Loading full blame...