Skip to content
Snippets Groups Projects
Commit fb0baecd authored by William F Godoy's avatar William F Godoy
Browse files

Working on LoadNexusLogs refactoring

parent c1ffd6ec
No related merge requests found
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
// SPDX - License - Identifier: GPL - 3.0 + // SPDX - License - Identifier: GPL - 3.0 +
#pragma once #pragma once
#include "MantidAPI/NexusFileLoader.h" #include "MantidAPI/NexusFileLoader.h"
#include <nexus/NeXusFile.hpp> #include <nexus/NeXusFile.hpp>
......
...@@ -424,27 +424,63 @@ void LoadNexusLogs::execLoader() { ...@@ -424,27 +424,63 @@ void LoadNexusLogs::execLoader() {
readStartAndEndTime(file, workspace->mutableRun()); readStartAndEndTime(file, workspace->mutableRun());
// print out the entry level fields const std::map<std::string, std::set<std::string>> &allEntries =
std::map<std::string, std::string> entries = file.getEntries(); getFileInfo()->getAllEntries();
std::map<std::string, std::string>::const_iterator iend = entries.end();
for (std::map<std::string, std::string>::const_iterator it = entries.begin(); auto lf_LoadLogsByClass = [&](const std::string &group_class,
it != iend; ++it) { const bool isLog) {
std::string group_name(it->first); auto itGroupClass = allEntries.find(group_class);
std::string group_class(it->second); if (itGroupClass == allEntries.end()) {
if (group_name == "DASlogs" || group_class == "IXrunlog" || return;
group_class == "IXselog" || group_name == "framelog") { }
loadLogs(file, group_name, group_class, workspace); const std::set<std::string> &entries = itGroupClass->second;
// still a linear search
for (const std::string &entry : entries) {
// match for 2nd level entry /a/b
if (std::count(entry.begin(), entry.end(), '/') == 2) {
if (isLog) {
const std::string group_name =
entry.substr(entry.find_last_of("/") + 1);
loadLogs(file, group_name, group_class, workspace);
// loadLogs(file, entry, group_class, workspace);
} else {
loadNPeriods(file, workspace);
}
}
} }
if (group_class == "IXperiods") { };
loadNPeriods(file, workspace); lf_LoadLogsByClass("IXselog", true);
lf_LoadLogsByClass("IXrunlog", true);
lf_LoadLogsByClass("IXperiods", false);
auto lf_LoadLogsByName = [&](const std::string &group_name) {
for (auto itGroupClass = allEntries.begin();
itGroupClass != allEntries.end(); ++itGroupClass) {
const std::string &group_class = itGroupClass->first;
const std::set<std::string> &entries = itGroupClass->second;
const std::string absoluteGroupName = "/" + entry_name + "/" + group_name;
auto itGroupName = entries.find(absoluteGroupName);
if (itGroupName == entries.end()) {
continue;
}
// here we must search only in NxLogs and NXpositioner sets
loadLogs(file, group_name, group_class, workspace);
// loadLogs(file, absoluteGroupName, group_class, workspace);
} }
} };
lf_LoadLogsByName("DASlogs");
lf_LoadLogsByName("framelog");
// If there's measurement information, load that info as logs. // If there's measurement information, load that info as logs.
loadAndApplyMeasurementInfo(&file, *workspace); loadAndApplyMeasurementInfo(&file, *workspace);
// If there's title information, load that info as logs. // If there's title information, load that info as logs.
loadAndApplyRunTitle(&file, *workspace); loadAndApplyRunTitle(&file, *workspace);
// TODO: remove
std::map<std::string, std::string> entries = file.getEntries();
// Freddie Akeroyd 12/10/2011 // Freddie Akeroyd 12/10/2011
// current ISIS implementation contains an additional indirection between // current ISIS implementation contains an additional indirection between
// collected frames via an // collected frames via an
...@@ -463,22 +499,22 @@ void LoadNexusLogs::execLoader() { ...@@ -463,22 +499,22 @@ void LoadNexusLogs::execLoader() {
// Find the bank/name corresponding to the first event data entry, i.e. // Find the bank/name corresponding to the first event data entry, i.e.
// one with type NXevent_data. // one with type NXevent_data.
file.openPath("/" + entry_name); file.openPath("/" + entry_name);
entries = file.getEntries(); auto itEventData = allEntries.find("NXevent_data");
std::string eventEntry; if (itEventData != allEntries.end()) {
const auto found = const std::set<std::string> &events = itEventData->second;
std::find_if(entries.cbegin(), entries.cend(), [](const auto &entry) { for (const std::string &event : events) {
return entry.second == "NXevent_data"; const std::string eventEntry =
}); event.substr(event.find_last_of("/") + 1);
if (found != entries.cend()) {
eventEntry = found->first; this->getLogger().debug()
<< "Opening"
<< " /" + entry_name + "/" + eventEntry + "/event_frame_number"
<< " to find the event_frame_number\n";
file.openPath("/" + entry_name + "/" + eventEntry +
"/event_frame_number");
file.getData(event_frame_number);
}
} }
this->getLogger().debug()
<< "Opening"
<< " /" + entry_name + "/" + eventEntry + "/event_frame_number"
<< " to find the event_frame_number\n";
file.openPath("/" + entry_name + "/" + eventEntry +
"/event_frame_number");
file.getData(event_frame_number);
} catch (const ::NeXus::Exception &) { } catch (const ::NeXus::Exception &) {
this->getLogger().warning() this->getLogger().warning()
<< "Unable to load event_frame_number - " << "Unable to load event_frame_number - "
......
...@@ -87,7 +87,7 @@ private: ...@@ -87,7 +87,7 @@ private:
* (e.g. /entry/log) * (e.g. /entry/log)
* </pre> * </pre>
*/ */
std::map<std::string, std::set<std::string>> m_allEntries; const std::map<std::string, std::set<std::string>> m_allEntries;
}; };
} // namespace Mantid::Kernel } // namespace Mantid::Kernel
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