From 3eaa46e0cf16c5b684d227ee98a16ecd4c8a0c9c Mon Sep 17 00:00:00 2001 From: Raquel Alvarez <raquel.alvarez-banos@stfc.ac.uk> Date: Mon, 14 Nov 2016 13:27:31 +0000 Subject: [PATCH] Re #17817 Make LoadNexusLogs read run title --- Framework/DataHandling/src/LoadNexusLogs.cpp | 25 +++++++++++++++++++ .../DataHandling/test/LoadNexusLogsTest.h | 21 ++++++++++++++++ docs/source/algorithms/LoadNexusLogs-v1.rst | 2 ++ 3 files changed, 48 insertions(+) diff --git a/Framework/DataHandling/src/LoadNexusLogs.cpp b/Framework/DataHandling/src/LoadNexusLogs.cpp index 60b408c9c49..de96a1ff276 100644 --- a/Framework/DataHandling/src/LoadNexusLogs.cpp +++ b/Framework/DataHandling/src/LoadNexusLogs.cpp @@ -69,6 +69,29 @@ bool loadAndApplyMeasurementInfo(::NeXus::File *const file, } return successfullyApplied; } + +/** +* @brief loadAndApplyRunTitle +* @param file : Nexus::File pointer +* @param workspace : Pointer to the workspace to set logs on +* @return True only if reading and execution successful. +*/ +bool loadAndApplyRunTitle(::NeXus::File *const file, + API::MatrixWorkspace &workspace) { + + bool successfullyApplied = false; + try { + file->openData("title"); + workspace.mutableRun().addLogData( + new Mantid::Kernel::PropertyWithValue<std::string>("run_title", + file->getStrData())); + file->closeData(); + successfullyApplied = true; + } catch (::NeXus::Exception &) { + successfullyApplied = false; + } + return successfullyApplied; +} } /// Empty default constructor @@ -175,6 +198,8 @@ void LoadNexusLogs::exec() { // If there's measurement information, load that info as logs. loadAndApplyMeasurementInfo(&file, *workspace); + // If there's title information, load that info as logs. + loadAndApplyRunTitle(&file, *workspace); // Freddie Akeroyd 12/10/2011 // current ISIS implementation contains an additional indirection between diff --git a/Framework/DataHandling/test/LoadNexusLogsTest.h b/Framework/DataHandling/test/LoadNexusLogsTest.h index 38b10895647..88035f355ec 100644 --- a/Framework/DataHandling/test/LoadNexusLogsTest.h +++ b/Framework/DataHandling/test/LoadNexusLogsTest.h @@ -170,6 +170,27 @@ public: uniquePeriods.size()); } + void test_extract_run_title_from_event_nexus() { + + auto testWS = createTestWorkspace(); + auto run = testWS->run(); + + LoadNexusLogs loader; + loader.setChild(true); + loader.initialize(); + loader.setProperty("Workspace", testWS); + loader.setPropertyValue("Filename", "LARMOR00003368.nxs"); + loader.execute(); + run = testWS->run(); + + const bool hasTitle = run.hasProperty("run_title"); + TSM_ASSERT("Should have run_title now we have run LoadNexusLogs", hasTitle); + + std::string title = run.getPropertyValueAsType<std::string>("run_title"); + TSM_ASSERT_EQUALS("Run title is not correct", + "3He polariser test 0.9bar Long Polariser 0.75A", title); + } + void test_log_non_default_entry() { auto testWS = createTestWorkspace(); LoadNexusLogs loader; diff --git a/docs/source/algorithms/LoadNexusLogs-v1.rst b/docs/source/algorithms/LoadNexusLogs-v1.rst index 85b036c6cb2..a598f177480 100644 --- a/docs/source/algorithms/LoadNexusLogs-v1.rst +++ b/docs/source/algorithms/LoadNexusLogs-v1.rst @@ -60,6 +60,8 @@ Items missing from the Nexus file are simply not loaded. | | | *Existing values are always | | | | overwritten.* | +----------------------------------+----------------------------------------------------+---------------------------------------+ +| Run title | Entry ``"title"`` | Title in run object if it exists | ++----------------------------------+----------------------------------------------------+---------------------------------------+ If the nexus file has a ``"proton_log"`` group, then this algorithm will do some event filtering to allow SANS2D files to load. -- GitLab