Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Framework/API/inc/MantidAPI/FileLoaderRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/IFileLoader.h"
#include "MantidKernel/FileDescriptor.h"
#include "MantidKernel/NexusDescriptor.h"
#include "MantidKernel/LegacyNexusDescriptor.h"
#include "MantidKernel/NexusHDF5Descriptor.h"
#include "MantidKernel/SingletonHolder.h"

Expand Down Expand Up @@ -90,7 +90,7 @@ class MANTID_API_DLL FileLoaderRegistryImpl {
static void check(LoaderFormat format) {
switch (format) {
case Nexus:
if (!std::is_base_of<IFileLoader<Kernel::NexusDescriptor>, T>::value) {
if (!std::is_base_of<IFileLoader<Kernel::LegacyNexusDescriptor>, T>::value) {
throw std::runtime_error(std::string("FileLoaderRegistryImpl::subscribe - Class '") + typeid(T).name() +
"' registered as Nexus loader but it does not "
"inherit from "
Expand Down
11 changes: 6 additions & 5 deletions Framework/API/src/FileLoaderRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void FileLoaderRegistryImpl::unsubscribe(const std::string &name, const int vers
*/
const std::shared_ptr<IAlgorithm> FileLoaderRegistryImpl::chooseLoader(const std::string &filename) const {
using Kernel::FileDescriptor;
using Kernel::NexusDescriptor;
using Kernel::LegacyNexusDescriptor;
using Kernel::NexusHDF5Descriptor;
m_log.debug() << "Trying to find loader for '" << filename << "'\n";

Expand All @@ -125,7 +125,7 @@ const std::shared_ptr<IAlgorithm> FileLoaderRegistryImpl::chooseLoader(const std

// must also try NexusDescriptor algorithms because LoadMuonNexus can load both HDF4 and HDF5 files
std::pair<IAlgorithm_sptr, int> HDF4result =
searchForLoader<NexusDescriptor, IFileLoader<NexusDescriptor>>(filename, m_names[Nexus], m_log);
searchForLoader<LegacyNexusDescriptor, IFileLoader<LegacyNexusDescriptor>>(filename, m_names[Nexus], m_log);

if (HDF5result.second > HDF4result.second)
bestLoader = HDF5result.first;
Expand All @@ -134,7 +134,8 @@ const std::shared_ptr<IAlgorithm> FileLoaderRegistryImpl::chooseLoader(const std
} else {
try {
bestLoader =
searchForLoader<NexusDescriptor, IFileLoader<NexusDescriptor>>(filename, m_names[Nexus], m_log).first;
searchForLoader<LegacyNexusDescriptor, IFileLoader<LegacyNexusDescriptor>>(filename, m_names[Nexus], m_log)
.first;
} catch (std::exception const &e) {
m_log.debug() << "Error in looking for NeXus files: " << e.what() << '\n';
}
Expand All @@ -159,7 +160,7 @@ const std::shared_ptr<IAlgorithm> FileLoaderRegistryImpl::chooseLoader(const std
*/
bool FileLoaderRegistryImpl::canLoad(const std::string &algorithmName, const std::string &filename) const {
using Kernel::FileDescriptor;
using Kernel::NexusDescriptor;
using Kernel::LegacyNexusDescriptor;
using Kernel::NexusHDF5Descriptor;

// Check if it is in one of our lists
Expand All @@ -175,7 +176,7 @@ bool FileLoaderRegistryImpl::canLoad(const std::string &algorithmName, const std
IAlgorithm_sptr loader;
if (nexus) {
try {
loader = searchForLoader<NexusDescriptor, IFileLoader<NexusDescriptor>>(filename, names, m_log).first;
loader = searchForLoader<LegacyNexusDescriptor, IFileLoader<LegacyNexusDescriptor>>(filename, names, m_log).first;
} catch (std::exception const &e) {
m_log.debug() << "Error in looking for NeXus files: " << e.what() << '\n';
}
Expand Down
7 changes: 4 additions & 3 deletions Framework/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ set(SRC_FILES
src/MultiFileValidator.cpp
src/NDRandomNumberGenerator.cpp
src/NeutronAtom.cpp
src/NexusDescriptor.cpp
src/LegacyNexusDescriptor.cpp
src/NexusHDF5Descriptor.cpp
src/NullValidator.cpp
src/OptionalBool.cpp
Expand Down Expand Up @@ -232,7 +232,7 @@ set(INC_FILES
inc/MantidKernel/NearestNeighbours.h
inc/MantidKernel/NetworkProxy.h
inc/MantidKernel/NeutronAtom.h
inc/MantidKernel/NexusDescriptor.h
inc/MantidKernel/LegacyNexusDescriptor.h
inc/MantidKernel/NexusHDF5Descriptor.h
inc/MantidKernel/NullValidator.h
inc/MantidKernel/OptionalBool.h
Expand Down Expand Up @@ -388,7 +388,7 @@ set(TEST_FILES
NDRandomNumberGeneratorTest.h
NearestNeighboursTest.h
NeutronAtomTest.h
NexusDescriptorTest.h
LegacyNexusDescriptorTest.h
NexusHDF5DescriptorTest.h
NullValidatorTest.h
OptionalBoolTest.h
Expand Down Expand Up @@ -488,6 +488,7 @@ target_link_libraries(
PUBLIC Mantid::Types
Mantid::Json
Mantid::NexusCpp
Mantid::LegacyNexus
Eigen3::Eigen
TBB::tbb
Poco::Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <utility>
#include <vector>

namespace NeXus {
namespace Mantid::LegacyNexus {
class File;
}

Expand All @@ -29,22 +29,22 @@ namespace Kernel {
On construction the simple details about the layout of the file are cached
for faster querying later.
*/
class MANTID_KERNEL_DLL NexusDescriptor {
class MANTID_KERNEL_DLL LegacyNexusDescriptor {

public:
/// Constructor accepting a filename
NexusDescriptor(const std::string &filename);
LegacyNexusDescriptor(const std::string &filename);
/// Destructor
~NexusDescriptor();
~LegacyNexusDescriptor();

/// Disable default constructor
NexusDescriptor() = delete;
LegacyNexusDescriptor() = delete;

/// Disable copy operator
NexusDescriptor(const NexusDescriptor &) = delete;
LegacyNexusDescriptor(const LegacyNexusDescriptor &) = delete;

/// Disable assignment operator
NexusDescriptor &operator=(const NexusDescriptor &) = delete;
LegacyNexusDescriptor &operator=(const LegacyNexusDescriptor &) = delete;

/**
* Access the filename
Expand All @@ -61,7 +61,7 @@ class MANTID_KERNEL_DLL NexusDescriptor {
* Access the open NeXus File object
* @returns A reference to the open ::NeXus file object
*/
inline ::NeXus::File &data() { return *m_file; }
inline Mantid::LegacyNexus::File &data() { return *m_file; }

/// Returns the name & type of the first entry in the file
const std::pair<std::string, std::string> &firstEntryNameType() const;
Expand All @@ -72,7 +72,7 @@ class MANTID_KERNEL_DLL NexusDescriptor {
/// Initialize object with filename
void initialize(const std::string &filename);
/// Walk the tree and cache the structure
void walkFile(::NeXus::File &file, const std::string &rootPath, const std::string &className,
void walkFile(Mantid::LegacyNexus::File &file, const std::string &rootPath, const std::string &className,
std::map<std::string, std::string> &pmap, int level);

/// Full filename
Expand All @@ -87,7 +87,7 @@ class MANTID_KERNEL_DLL NexusDescriptor {
std::map<std::string, std::string> m_pathsToTypes;

/// Open NeXus handle
std::unique_ptr<::NeXus::File> m_file;
std::unique_ptr<Mantid::LegacyNexus::File> m_file;
};

} // namespace Kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidKernel/NexusDescriptor.h"
#include "MantidNexusCpp/NeXusException.hpp"
#include "MantidNexusCpp/NeXusFile.hpp"
#include "MantidKernel/LegacyNexusDescriptor.h"
#include "MantidLegacyNexus/NeXusException.hpp"
#include "MantidLegacyNexus/NeXusFile.hpp"

#include <algorithm>
#include <cstring>
Expand All @@ -26,7 +26,7 @@ namespace Mantid::Kernel {
* involves simply checking for the signature if a HDF file at the start of the
* file
*/
NexusDescriptor::NexusDescriptor(const std::string &filename)
LegacyNexusDescriptor::LegacyNexusDescriptor(const std::string &filename)
: m_filename(), m_extension(), m_firstEntryNameType(), m_rootAttrs(), m_pathsToTypes(), m_file(nullptr) {
if (filename.empty()) {
throw std::invalid_argument("NexusDescriptor() - Empty filename '" + filename + "'");
Expand All @@ -37,23 +37,25 @@ NexusDescriptor::NexusDescriptor(const std::string &filename)
try {
// this is very expesive as it walk the entire file
initialize(filename);
} catch (::NeXus::Exception &e) {
} catch (Mantid::LegacyNexus::Exception &e) {
throw std::invalid_argument("NexusDescriptor::initialize - File '" + filename +
"' does not look like a HDF file.\n Error was: " + e.what());
}
}

NexusDescriptor::~NexusDescriptor() = default;
LegacyNexusDescriptor::~LegacyNexusDescriptor() = default;

/// Returns the name & type of the first entry in the file
const std::pair<std::string, std::string> &NexusDescriptor::firstEntryNameType() const { return m_firstEntryNameType; }
const std::pair<std::string, std::string> &LegacyNexusDescriptor::firstEntryNameType() const {
return m_firstEntryNameType;
}

/**
* @param path A string giving a path using UNIX-style path separators (/), e.g.
* /raw_data_1, /entry/bank1
* @return True if the path exists in the file, false otherwise
*/
bool NexusDescriptor::pathExists(const std::string &path) const {
bool LegacyNexusDescriptor::pathExists(const std::string &path) const {
return (m_pathsToTypes.find(path) != m_pathsToTypes.end());
}

Expand All @@ -64,11 +66,11 @@ bool NexusDescriptor::pathExists(const std::string &path) const {
/**
* Creates the internal cached structure of the file as a tree of nodes
*/
void NexusDescriptor::initialize(const std::string &filename) {
void LegacyNexusDescriptor::initialize(const std::string &filename) {
m_filename = filename;
m_extension = std::filesystem::path(filename).extension().string();

m_file = std::make_unique<::NeXus::File>(this->filename());
m_file = std::make_unique<Mantid::LegacyNexus::File>(this->filename());

m_file->openPath("/");
m_rootAttrs.clear();
Expand All @@ -84,8 +86,9 @@ void NexusDescriptor::initialize(const std::string &filename) {
* @param pmap [Out] An output map filled with mappings of path->type
* @param level An integer defining the current level in the file
*/
void NexusDescriptor::walkFile(::NeXus::File &file, const std::string &rootPath, const std::string &className,
std::map<std::string, std::string> &pmap, int level) {
void LegacyNexusDescriptor::walkFile(Mantid::LegacyNexus::File &file, const std::string &rootPath,
const std::string &className, std::map<std::string, std::string> &pmap,
int level) {
if (!rootPath.empty()) {
pmap.emplace(rootPath, className);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@
#pragma once

#include "MantidKernel/ConfigService.h"
#include "MantidKernel/NexusDescriptor.h"
#include "MantidNexusCpp/NeXusFile.hpp"
#include "MantidKernel/LegacyNexusDescriptor.h"
#include "MantidLegacyNexus/NeXusFile.hpp"
#include <cxxtest/TestSuite.h>

#include <filesystem>
#include <memory>

#include <cstdio>

using Mantid::Kernel::NexusDescriptor;
using Mantid::Kernel::LegacyNexusDescriptor;

class NexusDescriptorTest : public CxxTest::TestSuite {
class LegacyNexusDescriptorTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static NexusDescriptorTest *createSuite() { return new NexusDescriptorTest(); }
static void destroySuite(NexusDescriptorTest *suite) { delete suite; }
static LegacyNexusDescriptorTest *createSuite() { return new LegacyNexusDescriptorTest(); }
static void destroySuite(LegacyNexusDescriptorTest *suite) { delete suite; }

NexusDescriptorTest() {
LegacyNexusDescriptorTest() {
using Mantid::Kernel::ConfigService;
auto dataPaths = ConfigService::Instance().getDataSearchDirs();
for (auto &dataPath : dataPaths) {
Expand All @@ -45,10 +45,10 @@ class NexusDescriptorTest : public CxxTest::TestSuite {
"The AutoTestData directory needs to be in the search path");
}

m_testHDF5 = std::make_shared<NexusDescriptor>(m_testHDF5Path);
m_testHDF5 = std::make_shared<LegacyNexusDescriptor>(m_testHDF5Path);
}

//=================================== NexusDescriptor methods
//=================================== LegacyNexusDescriptor methods
//==================================

void test_Constructor_Initializes_Object_Correctly_Given_HDF_File() {
Expand All @@ -57,15 +57,15 @@ class NexusDescriptorTest : public CxxTest::TestSuite {
}

void test_Constructor_Throws_With_Empty_filename() {
TS_ASSERT_THROWS(NexusDescriptor(""), const std::invalid_argument &);
TS_ASSERT_THROWS(LegacyNexusDescriptor(""), const std::invalid_argument &);
}

void test_Constructor_Throws_With_NonExistant_filename() {
TS_ASSERT_THROWS(NexusDescriptor("__ThisShouldBeANonExistantFile.txt"), const std::invalid_argument &);
TS_ASSERT_THROWS(LegacyNexusDescriptor("__ThisShouldBeANonExistantFile.txt"), const std::invalid_argument &);
}

void test_Constructor_Throws_When_Given_File_Not_Identified_As_HDF() {
TS_ASSERT_THROWS(NexusDescriptor fd(m_testNonHDFPath), const std::invalid_argument &);
TS_ASSERT_THROWS(LegacyNexusDescriptor fd(m_testNonHDFPath), const std::invalid_argument &);
}

void test_File_Handle_Returned_By_Data_Is_Valid() {
Expand Down Expand Up @@ -95,5 +95,5 @@ class NexusDescriptorTest : public CxxTest::TestSuite {
private:
std::string m_testHDF5Path;
std::string m_testNonHDFPath;
std::shared_ptr<NexusDescriptor> m_testHDF5;
std::shared_ptr<LegacyNexusDescriptor> m_testHDF5;
};
Loading