diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h b/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h index 422783ccdf6ad9adfbd6a6c039a89ecce8b218fe..4bf34e5222127759008977f4c3bee8333f0db666 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h @@ -107,7 +107,8 @@ public: template <typename T> static void loadEntryMetadata(const std::string &nexusfilename, T WS, - const std::string &entry_name); + const std::string &entry_name, + const Kernel::NexusHDF5Descriptor &descriptor); /// Load instrument from Nexus file if possible, else from IDF spacified by /// Nexus file @@ -595,8 +596,9 @@ bool LoadEventNexus::runLoadInstrument(const std::string &nexusfilename, //----------------------------------------------------------------------------- /** Load the run number and other meta data from the given bank */ template <typename T> -void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, - const std::string &entry_name) { +void LoadEventNexus::loadEntryMetadata( + const std::string &nexusfilename, T WS, const std::string &entry_name, + const Kernel::NexusHDF5Descriptor &descriptor) { // Open the file ::NeXus::File file(nexusfilename); file.openGroup(entry_name, "NXentry"); @@ -605,7 +607,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, const std::map<std::string, std::string> entriesNxentry = file.getEntries(); // get the title - if (exists(entriesNxentry, "title")) { + if (descriptor.isEntry("/" + entry_name + "/title", "NXentry")) { file.openData("title"); if (file.getInfo().type == ::NeXus::CHAR) { std::string title = file.getStrData(); @@ -616,7 +618,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // get the notes - if (exists(entriesNxentry, "notes")) { + if (descriptor.isEntry("/" + entry_name + "/title", "NXentry")) { file.openData("notes"); if (file.getInfo().type == ::NeXus::CHAR) { std::string notes = file.getStrData(); @@ -627,7 +629,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // Get the run number - if (exists(entriesNxentry, "run_number")) { + if (descriptor.isEntry("/" + entry_name + "/run_number", "NXentry")) { file.openData("run_number"); std::string run; if (file.getInfo().type == ::NeXus::CHAR) { @@ -646,7 +648,8 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // get the experiment identifier - if (exists(entriesNxentry, "experiment_identifier")) { + if (descriptor.isEntry("/" + entry_name + "/experiment_identifier", + "NXentry")) { file.openData("experiment_identifier"); std::string expId; if (file.getInfo().type == ::NeXus::CHAR) { @@ -660,10 +663,11 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, // get the sample name - nested try/catch to leave the handle in an // appropriate state - if (exists(entriesNxentry, "sample")) { + if (descriptor.isEntry("/" + entry_name + "/sample", "NXentry")) { file.openGroup("sample", "NXsample"); try { - if (exists(file, "name")) { + + if (descriptor.isEntry("/" + entry_name + "/sample/name")) { file.openData("name"); const auto info = file.getInfo(); std::string name; @@ -691,7 +695,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // get the duration - if (exists(entriesNxentry, "duration")) { + if (descriptor.isEntry("/" + entry_name + "/duration", "NXentry")) { file.openData("duration"); std::vector<double> duration; file.getDataCoerce(duration); diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadTOFRawNexus.h b/Framework/DataHandling/inc/MantidDataHandling/LoadTOFRawNexus.h index 2bced73be98aa817733b6259fb46fee170cabd58..8650e09b1c417b0f6607911ad7fcdbd283f330de 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadTOFRawNexus.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadTOFRawNexus.h @@ -10,6 +10,7 @@ // Includes //---------------------------------------------------------------------- #include "MantidAPI/IFileLoader.h" +#include "MantidAPI/NexusFileLoader.h" #include "MantidAPI/Sample.h" #include "MantidAPI/SpectraDetectorTypes.h" #include "MantidDataObjects/Workspace2D.h" @@ -26,8 +27,7 @@ namespace DataHandling { Loads a NeXus file that conforms to the TOFRaw instrument definition format and stores it in a 2D workspace. */ -class DLLExport LoadTOFRawNexus - : public API::IFileLoader<Kernel::NexusDescriptor> { +class DLLExport LoadTOFRawNexus : public API::NexusFileLoader { public: /// Default Constructor LoadTOFRawNexus(); @@ -52,7 +52,7 @@ public: static std::string getEntryName(const std::string &filename); /// Returns a confidence value that this algorithm can load a file - int confidence(Kernel::NexusDescriptor &descriptor) const override; + int confidence(Kernel::NexusHDF5Descriptor &descriptor) const override; void countPixels(const std::string &nexusfilename, const std::string &entry_name, @@ -66,7 +66,7 @@ public: protected: void init() override; - void exec() override; + void execLoader() override; /// Validate the optional input properties void checkOptionalProperties(); diff --git a/Framework/DataHandling/src/LoadTOFRawNexus.cpp b/Framework/DataHandling/src/LoadTOFRawNexus.cpp index 2f8d9d0c143c8cbc60a2e918c93f8b355c90d014..145c929c9cb6bbc624aef92dfb87c645c7f362c6 100644 --- a/Framework/DataHandling/src/LoadTOFRawNexus.cpp +++ b/Framework/DataHandling/src/LoadTOFRawNexus.cpp @@ -73,21 +73,28 @@ void LoadTOFRawNexus::init() { * @returns An integer specifying the confidence level. 0 indicates it will not * be used */ -int LoadTOFRawNexus::confidence(Kernel::NexusDescriptor &descriptor) const { +int LoadTOFRawNexus::confidence(Kernel::NexusHDF5Descriptor &descriptor) const { int confidence(0); - if (descriptor.pathOfTypeExists("/entry", "NXentry") || - descriptor.pathOfTypeExists("/entry-state0", "NXentry")) { - const bool hasEventData = descriptor.classTypeExists("NXevent_data"); - const bool hasData = descriptor.classTypeExists("NXdata"); - if (hasData && hasEventData) + + const std::map<std::string, std::set<std::string>> &allEntries = + descriptor.getAllEntries(); + + if (descriptor.isEntry("/entry", "NXentry") || + descriptor.isEntry("/entry-state0", "NXentry")) { + + const bool hasEventData = + (allEntries.count("NXevent_data") == 1) ? true : false; + const bool hasData = (allEntries.count("NXdata") == 1) ? true : false; + if (hasData && hasEventData) { // Event data = this is event NXS confidence = 20; - else if (hasData && !hasEventData) + } else if (hasData && !hasEventData) { // No event data = this is the one confidence = 80; - else + } else { // No data ? confidence = 10; + } } return confidence; } @@ -475,7 +482,7 @@ std::string LoadTOFRawNexus::getEntryName(const std::string &filename) { * @throw std::invalid_argument If the optional properties are set to invalid *values */ -void LoadTOFRawNexus::exec() { +void LoadTOFRawNexus::execLoader() { // The input properties std::string filename = getPropertyValue("Filename"); m_signalNo = getProperty("Signal"); @@ -520,7 +527,8 @@ void LoadTOFRawNexus::exec() { prog->report("Loading metadata"); g_log.debug() << "Loading metadata\n"; try { - LoadEventNexus::loadEntryMetadata(filename, WS, entry_name); + + LoadEventNexus::loadEntryMetadata(filename, WS, entry_name, *m_fileInfo); } catch (std::exception &e) { g_log.warning() << "Error while loading meta data: " << e.what() << '\n'; }