diff --git a/Framework/DataHandling/src/LoadISISNexus2.cpp b/Framework/DataHandling/src/LoadISISNexus2.cpp index 2800ee1e42ac7ec35cacff735e631e1ce16e10e2..aed6773ba2464ea2b73a8d13e8d85c42d86a23e1 100644 --- a/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -38,6 +38,52 @@ namespace Mantid { namespace DataHandling { + +namespace { + +/** + * @brief loadAndApplyMeasurementInfo + * @param file : Nexus::File pointer + * @param workspace : Pointer to the workspace to set logs on + * @return True only if reading and execution successful. + */ +bool loadAndApplyMeasurementInfo(::NeXus::File *const file, + DataObjects::Workspace2D &workspace) { + + bool successfullyApplied = false; + try { + file->openGroup("measurement", "NXcollection"); + + //If we can open the measurement group. We assume that the following will be avaliable. + file->openData("id"); + workspace.mutableRun().addLogData( + new Mantid::Kernel::PropertyWithValue<std::string>( + "measurement_id", file->getStrData())); + file->closeData(); + file->openData("label"); + workspace.mutableRun().addLogData( + new Mantid::Kernel::PropertyWithValue<std::string>( + "measurement_label", file->getStrData())); + file->closeData(); + file->openData("subid"); + workspace.mutableRun().addLogData( + new Mantid::Kernel::PropertyWithValue<std::string>( + "measurement_subid", file->getStrData())); + file->closeData(); + file->openData("type"); + workspace.mutableRun().addLogData( + new Mantid::Kernel::PropertyWithValue<std::string>( + "measurement_type", file->getStrData())); + file->closeData(); + file->closeGroup(); + successfullyApplied = true; + } catch (::NeXus::Exception &) { + successfullyApplied = false; + } + return successfullyApplied; +} +} + DECLARE_NEXUS_FILELOADER_ALGORITHM(LoadISISNexus2) using namespace Kernel; @@ -251,6 +297,8 @@ void LoadISISNexus2::exec() { m_cppFile->openPath(entry.path()); local_workspace->loadSampleAndLogInfoNexus(m_cppFile.get()); + loadAndApplyMeasurementInfo(m_cppFile.get(), *local_workspace); + // Load logs and sample information further information... See maintenance // ticket #8697 loadSampleData(local_workspace, entry); @@ -426,8 +474,8 @@ private: Check for a set of synthetic logs associated with multi-period log data. Raise warnings where necessary. */ -void LoadISISNexus2::validateMultiPeriodLogs( - Mantid::API::MatrixWorkspace_sptr ws) { +void +LoadISISNexus2::validateMultiPeriodLogs(Mantid::API::MatrixWorkspace_sptr ws) { const Run &run = ws->run(); if (!run.hasProperty("current_period")) { g_log.warning("Workspace has no current_period log."); @@ -738,10 +786,10 @@ size_t LoadISISNexus2::prepareSpectraBlocks( * @param update_spectra2det_mapping :: reset spectra-detector map to the one * calculated earlier. (Warning! -- this map has to be calculated correctly!) */ -void LoadISISNexus2::loadPeriodData( - int64_t period, NXEntry &entry, - DataObjects::Workspace2D_sptr &local_workspace, - bool update_spectra2det_mapping) { +void +LoadISISNexus2::loadPeriodData(int64_t period, NXEntry &entry, + DataObjects::Workspace2D_sptr &local_workspace, + bool update_spectra2det_mapping) { int64_t hist_index = 0; int64_t period_index(period - 1); // int64_t first_monitor_spectrum = 0; @@ -930,8 +978,9 @@ void LoadISISNexus2::runLoadInstrument( * @param local_workspace :: The workspace to load the run information in to * @param entry :: The Nexus entry */ -void LoadISISNexus2::loadRunDetails( - DataObjects::Workspace2D_sptr &local_workspace, NXEntry &entry) { +void +LoadISISNexus2::loadRunDetails(DataObjects::Workspace2D_sptr &local_workspace, + NXEntry &entry) { API::Run &runDetails = local_workspace->mutableRun(); // Charge is stored as a float m_proton_charge = static_cast<double>(entry.getFloat("proton_charge")); @@ -1063,8 +1112,9 @@ void LoadISISNexus2::parseISODateTime(const std::string &datetime_iso, * @param local_workspace :: The workspace to load the logs to. * @param entry :: The Nexus entry */ -void LoadISISNexus2::loadSampleData( - DataObjects::Workspace2D_sptr &local_workspace, NXEntry &entry) { +void +LoadISISNexus2::loadSampleData(DataObjects::Workspace2D_sptr &local_workspace, + NXEntry &entry) { /// Sample geometry NXInt spb = entry.openNXInt("isis_vms_compat/SPB"); // Just load the index we need, not the whole block. The flag is the third diff --git a/Framework/DataHandling/test/LoadISISNexusTest.h b/Framework/DataHandling/test/LoadISISNexusTest.h index 3b29024c82fc17221611aff7926c9ca8d84a6479..0d5eeb8b5435d3516b656ca43430593dfaf1c121 100644 --- a/Framework/DataHandling/test/LoadISISNexusTest.h +++ b/Framework/DataHandling/test/LoadISISNexusTest.h @@ -726,6 +726,37 @@ public: TS_ASSERT(monPeriod1Run.hasProperty("period 1")) TS_ASSERT(monPeriod2Run.hasProperty("period 2")) } + + std::string extractStringLog(const MatrixWorkspace& matrixWS, const std::string& logName) + { + auto run = matrixWS.run(); + PropertyWithValue<std::string>* log = + dynamic_cast<PropertyWithValue<std::string>*>(run.getLogData(logName)); + return log->value(); + } + + void testExecExtractMeasurmentData(){ + LoadISISNexus2 ld; + ld.setChild(true); + ld.initialize(); + ld.setPropertyValue("Filename", "POLREF00014966.nxs"); + ld.setPropertyValue("OutputWorkspace", "__unused_for_child"); + ld.setPropertyValue("LoadMonitors", "Separate"); + ld.execute(); + + Workspace_sptr detWS = ld.getProperty("OutputWorkspace"); + + auto groupWS = boost::dynamic_pointer_cast<WorkspaceGroup>(detWS); + TSM_ASSERT("Should have got back a workspace group", groupWS); + + auto firstMatrixWS = + boost::dynamic_pointer_cast<MatrixWorkspace>(groupWS->getItem(0)); + + TS_ASSERT_EQUALS("34", extractStringLog(*firstMatrixWS, "measurement_id")); + TS_ASSERT_EQUALS("0", extractStringLog(*firstMatrixWS, "measurement_subid")); + TS_ASSERT_EQUALS("", extractStringLog(*firstMatrixWS, "measurement_label")); + TS_ASSERT_EQUALS("PNR", extractStringLog(*firstMatrixWS, "measurement_type")); + } }; //------------------------------------------------------------------------------