Commit 71343c18 authored by Stephen's avatar Stephen
Browse files

Add LoadMuonNexusV2 to load algorithm choices in LoadMuonNexus

parent 6156c52c
......@@ -32,6 +32,7 @@
#include <cmath>
#include <numeric>
#include <MantidDataHandling\LoadMuonNexusV2.h>
using Mantid::Types::Core::DateAndTime;
......@@ -50,41 +51,56 @@ using Mantid::HistogramData::Histogram;
using namespace Mantid::NeXus;
using Mantid::Types::Core::DateAndTime;
namespace {
inline std::string getLoadAlgName(int confidence1, int confidenceV2) {
return confidence1 > confidenceV2 ? "LoadMuonNexus" : "LoadMuonNexusV2";
}
} // namespace
/// Empty default constructor
LoadMuonNexus2::LoadMuonNexus2() : LoadMuonNexus() {}
/** Executes the right version of the muon nexus loader: versions 1 or 2.
*
/** Executes the right version of the Muon nexus loader
* @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 LoadMuonNexus2::exec() {
std::string filePath = getPropertyValue("Filename");
LoadMuonNexus1 load1;
LoadMuonNexusV2 loadV2;
load1.initialize();
loadV2.initialize();
std::string filePath = getPropertyValue("Filename");
Kernel::NexusDescriptor descriptor(filePath);
int confidence1 = load1.confidence(descriptor);
int confidence2 = this->confidence(descriptor);
int confidenceV2 = 0;
// If the file is hdf5 then we can possibly use LoadMuonNexusV2
// To check this we'll have to create an HDF5 descriptor for the file.
if (Kernel::NexusDescriptor::isReadable(filePath,
Kernel::NexusDescriptor::Version5)) {
Kernel::NexusHDF5Descriptor descriptorHDF5(filePath);
confidenceV2 = loadV2.confidence(descriptorHDF5);
};
// if none can load the file throw
if (confidence1 < 80 && confidence2 < 80) {
if (confidence1 < 80 && confidence2 < 80 && confidenceV2 < 80) {
throw Kernel::Exception::FileError("Cannot open the file ", filePath);
}
if (confidence2 > confidence1) {
// this loader
// Now pick the correct alg
if (confidence2 > std::max(confidence1, confidenceV2)) {
// Use this loader
doExec();
} else {
// version 1 loader
IAlgorithm_sptr childAlg =
createChildAlgorithm("LoadMuonNexus", 0, 1, true, 1);
auto version1Loader = std::dynamic_pointer_cast<API::Algorithm>(childAlg);
version1Loader->copyPropertiesFrom(*this);
version1Loader->executeAsChildAlg();
this->copyPropertiesFrom(*version1Loader);
API::Workspace_sptr outWS = version1Loader->getProperty("OutputWorkspace");
// Version 1 or V2
IAlgorithm_sptr childAlg = createChildAlgorithm(
getLoadAlgName(confidence1, confidenceV2), 0, 1, true, 1);
auto loader = std::dynamic_pointer_cast<API::Algorithm>(childAlg);
loader->copyPropertiesFrom(*this);
loader->executeAsChildAlg();
this->copyPropertiesFrom(*loader);
API::Workspace_sptr outWS = loader->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", outWS);
}
}
......
......@@ -89,12 +89,14 @@ void LoadMuonNexusV2::init() {
"algorithm. For multiperiod files, one workspace will be\n"
"generated for each period");
auto mustBePositiveSpectra = std::make_shared<BoundedValidator<specnum_t>>();
mustBePositiveSpectra->setLower(0);
declareProperty("SpectrumMin", static_cast<specnum_t>(0), mustBePositiveSpectra);
declareProperty("SpectrumMax", static_cast<specnum_t>(EMPTY_INT()),
mustBePositiveSpectra);
declareProperty(std::make_unique<ArrayProperty<specnum_t>>("SpectrumList"));
auto mustBePositive = std::make_shared<BoundedValidator<int64_t>>();
mustBePositive->setLower(0);
declareProperty("SpectrumMin", static_cast<int64_t>(0), mustBePositive);
declareProperty("SpectrumMax", static_cast<int64_t>(EMPTY_INT()),
mustBePositive);
declareProperty(std::make_unique<ArrayProperty<int64_t>>("SpectrumList"));
declareProperty("EntryNumber", static_cast<int64_t>(0), mustBePositive,
"0 indicates that every entry is loaded, into a separate "
"workspace within a group. "
......@@ -127,7 +129,6 @@ void LoadMuonNexusV2::init() {
"detector grouping.");
}
void LoadMuonNexusV2::execLoader() {
// this->setRethrows(true);
// prepare nexus entry
m_entrynumber = getProperty("EntryNumber");
m_filename = getPropertyValue("Filename");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment