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: ...@@ -43,9 +43,6 @@ public:
void setPropertyValue(const std::string &name, void setPropertyValue(const std::string &name,
const std::string &value) override; const std::string &value) override;
/// Free function to find first file property
static std::string findFilenamePropertyName(const IAlgorithm *loader);
protected: protected:
Parallel::ExecutionMode getParallelExecutionMode( Parallel::ExecutionMode getParallelExecutionMode(
const std::map<std::string, Parallel::StorageMode> &storageModes) const std::map<std::string, Parallel::StorageMode> &storageModes)
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IWorkspaceProperty.h" #include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/MultipleFileProperty.h" #include "MantidAPI/MultipleFileProperty.h"
#include "MantidAPI/NexusFileLoader.h"
#include "MantidAPI/WorkspaceGroup.h" #include "MantidAPI/WorkspaceGroup.h"
#include "MantidKernel/ArrayProperty.h" #include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/FacilityInfo.h" #include "MantidKernel/FacilityInfo.h"
...@@ -214,44 +215,39 @@ API::IAlgorithm_sptr Load::getFileLoader(const std::string &filePath) { ...@@ -214,44 +215,39 @@ API::IAlgorithm_sptr Load::getFileLoader(const std::string &filePath) {
return winningLoader; return winningLoader;
} }
std::string Load::findFilenamePropertyName(const IAlgorithm *loader) { void Load::findFilenameProperty(const API::IAlgorithm_sptr &loader) {
std::string propertyName; // default is empty string const auto nxsLoader = boost::dynamic_pointer_cast<NexusFileLoader>(loader);
if (nxsLoader) {
// Use the first file property as the main Filename // NexusFileLoader has a method for giving back the name directly
const auto &props = loader->getProperties(); m_filenamePropName = nxsLoader->getFilenamePropertyName();
for (auto prop : props) { } else {
auto *multiprop = dynamic_cast<API::MultipleFileProperty *>(prop); // Use the first file property as the main Filename
auto *singleprop = dynamic_cast<API::FileProperty *>(prop); const auto &props = loader->getProperties();
if (multiprop) { for (auto prop : props) {
propertyName = multiprop->name(); auto *multiprop = dynamic_cast<API::MultipleFileProperty *>(prop);
break; auto *singleprop = dynamic_cast<API::FileProperty *>(prop);
} if (multiprop) {
if (singleprop) { m_filenamePropName = multiprop->name();
propertyName = singleprop->name(); break;
break; }
if (singleprop) {
m_filenamePropName = singleprop->name();
break;
}
} }
} }
// throw an exception if somehting nothing was found // 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; std::stringstream msg;
msg << "Cannot find FileProperty on \"" << loader->name() << "\" v" msg << "Cannot find FileProperty on \"" << loader->name() << "\" v"
<< loader->version() << " algorithm."; << loader->version() << " algorithm.";
throw std::runtime_error(msg.str()); 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