From 20647320956c7b8121098dbb8c9041d631c693da Mon Sep 17 00:00:00 2001 From: William F Godoy <williamfgc@yahoo.com> Date: Wed, 26 Feb 2020 12:44:01 -0500 Subject: [PATCH] Modified Metadata handling in LoadEventNexus Reuse map from NeXus file getEntries prevents creation and destruction of std::map addressing clang-format --- .../inc/MantidDataHandling/LoadEventNexus.h | 18 ++++++++++++------ Framework/DataHandling/src/LoadEventNexus.cpp | 7 ++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h b/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h index e4b73786615..502500ffdf9 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadEventNexus.h @@ -53,6 +53,9 @@ public: bool exists(::NeXus::File &file, const std::string &name); +bool exists(const std::map<std::string, std::string> &entries, + const std::string &name); + /** @class LoadEventNexus LoadEventNexus.h Nexus/LoadEventNexus.h Load Event Nexus files. @@ -599,8 +602,11 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, ::NeXus::File file(nexusfilename); file.openGroup(entry_name, "NXentry"); + // only generating the entriesMap once + const std::map<std::string, std::string> entriesNxentry = file.getEntries(); + // get the title - if (exists(file, "title")) { + if (exists(entriesNxentry, "title")) { file.openData("title"); if (file.getInfo().type == ::NeXus::CHAR) { std::string title = file.getStrData(); @@ -611,7 +617,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // get the notes - if (exists(file, "notes")) { + if (exists(entriesNxentry, "notes")) { file.openData("notes"); if (file.getInfo().type == ::NeXus::CHAR) { std::string notes = file.getStrData(); @@ -622,7 +628,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // Get the run number - if (exists(file, "run_number")) { + if (exists(entriesNxentry, "run_number")) { file.openData("run_number"); std::string run; if (file.getInfo().type == ::NeXus::CHAR) { @@ -641,7 +647,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // get the experiment identifier - if (exists(file, "experiment_identifier")) { + if (exists(entriesNxentry, "experiment_identifier")) { file.openData("experiment_identifier"); std::string expId; if (file.getInfo().type == ::NeXus::CHAR) { @@ -655,7 +661,7 @@ 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(file, "sample")) { + if (exists(entriesNxentry, "sample")) { file.openGroup("sample", "NXsample"); try { if (exists(file, "name")) { @@ -686,7 +692,7 @@ void LoadEventNexus::loadEntryMetadata(const std::string &nexusfilename, T WS, } // get the duration - if (exists(file, "duration")) { + if (exists(entriesNxentry, "duration")) { file.openData("duration"); std::vector<double> duration; file.getDataCoerce(duration); diff --git a/Framework/DataHandling/src/LoadEventNexus.cpp b/Framework/DataHandling/src/LoadEventNexus.cpp index f1859a51506..1c458f0242c 100644 --- a/Framework/DataHandling/src/LoadEventNexus.cpp +++ b/Framework/DataHandling/src/LoadEventNexus.cpp @@ -62,7 +62,12 @@ const std::string NULL_STR("NULL"); * @return true only if it exists */ bool exists(::NeXus::File &file, const std::string &name) { - auto entries = file.getEntries(); + const auto entries = file.getEntries(); + return exists(entries, name); +} + +bool exists(const std::map<std::string, std::string> &entries, + const std::string &name) { return entries.find(name) != entries.end(); } -- GitLab