Skip to content
Snippets Groups Projects
Commit 52b99020 authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Take advantage of new method in NexusFileLoader

parent ab22cd70
No related branches found
No related tags found
No related merge requests found
......@@ -43,9 +43,6 @@ public:
void setPropertyValue(const std::string &name,
const std::string &value) override;
/// Free function to find first file property
static std::string findFilenamePropertyName(const IAlgorithm *loader);
protected:
Parallel::ExecutionMode getParallelExecutionMode(
const std::map<std::string, Parallel::StorageMode> &storageModes)
......
......@@ -13,6 +13,7 @@
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/MultipleFileProperty.h"
#include "MantidAPI/NexusFileLoader.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/FacilityInfo.h"
......@@ -214,44 +215,39 @@ API::IAlgorithm_sptr Load::getFileLoader(const std::string &filePath) {
return winningLoader;
}
std::string Load::findFilenamePropertyName(const IAlgorithm *loader) {
std::string propertyName; // default is empty string
// Use the first file property as the main Filename
const auto &props = loader->getProperties();
for (auto prop : props) {
auto *multiprop = dynamic_cast<API::MultipleFileProperty *>(prop);
auto *singleprop = dynamic_cast<API::FileProperty *>(prop);
if (multiprop) {
propertyName = multiprop->name();
break;
}
if (singleprop) {
propertyName = singleprop->name();
break;
void Load::findFilenameProperty(const API::IAlgorithm_sptr &loader) {
const auto nxsLoader = boost::dynamic_pointer_cast<NexusFileLoader>(loader);
if (nxsLoader) {
// NexusFileLoader has a method for giving back the name directly
m_filenamePropName = nxsLoader->getFilenamePropertyName();
} else {
// Use the first file property as the main Filename
const auto &props = loader->getProperties();
for (auto prop : props) {
auto *multiprop = dynamic_cast<API::MultipleFileProperty *>(prop);
auto *singleprop = dynamic_cast<API::FileProperty *>(prop);
if (multiprop) {
m_filenamePropName = multiprop->name();
break;
}
if (singleprop) {
m_filenamePropName = singleprop->name();
break;
}
}
}
// throw an exception if somehting nothing was found
if (propertyName.empty()) {
if (m_filenamePropName.empty()) {
// unset member variables
setPropertyValue("LoaderName", "");
setProperty("LoaderVersion", -1);
std::stringstream msg;
msg << "Cannot find FileProperty on \"" << loader->name() << "\" v"
<< loader->version() << " algorithm.";
throw std::runtime_error(msg.str());
}
return propertyName;
}
void Load::findFilenameProperty(const API::IAlgorithm_sptr &loader) {
try {
m_filenamePropName = findFilenamePropertyName(loader.get());
} catch (std::runtime_error &) {
// unset member variables
setPropertyValue("LoaderName", "");
setProperty("LoaderVersion", -1);
throw;
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment