diff --git a/Framework/DataHandling/src/LoadISISNexus2.cpp b/Framework/DataHandling/src/LoadISISNexus2.cpp index 1317fd97dc695f35a9b5d4146bf5ee8cbbfb14d6..35607007f104888cf9c142dc61cb081f4a681dc1 100644 --- a/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -1131,23 +1131,7 @@ void LoadISISNexus2::loadLogs(DataObjects::Workspace2D_sptr &ws, << "data associated with this workspace\n"; return; } - // For ISIS Nexus only, fabricate an additional log containing an array of - // proton charge information from the periods group. - try { - NXClass protonChargeClass = entry.openNXGroup("periods"); - NXFloat periodsCharge = protonChargeClass.openNXFloat("proton_charge"); - periodsCharge.load(); - size_t nperiods = periodsCharge.dim0(); - std::vector<double> chargesVector(nperiods); - std::copy(periodsCharge(), periodsCharge() + nperiods, - chargesVector.begin()); - ArrayProperty<double> *protonLogData = - new ArrayProperty<double>("proton_charge_by_period", chargesVector); - ws->mutableRun().addProperty(protonLogData); - } catch (std::runtime_error &) { - this->g_log.debug("Cannot read periods information from the nexus file. " - "This group may be absent."); - } + // Populate the instrument parameters. ws->populateInstrumentParameters(); diff --git a/Framework/DataHandling/src/LoadNexusLogs.cpp b/Framework/DataHandling/src/LoadNexusLogs.cpp index 339c3b467ca006a7ea9b5a34f3e3e38ab3e4814e..7cbdbc6e0072621bb0da94df04ae151cf41be647 100644 --- a/Framework/DataHandling/src/LoadNexusLogs.cpp +++ b/Framework/DataHandling/src/LoadNexusLogs.cpp @@ -1,6 +1,7 @@ #include "MantidDataHandling/LoadNexusLogs.h" #include <nexus/NeXusException.hpp> #include "MantidKernel/TimeSeriesProperty.h" +#include "MantidKernel/ArrayProperty.h" #include "MantidAPI/FileProperty.h" #include "MantidAPI/Run.h" #include <cctype> @@ -367,6 +368,40 @@ void LoadNexusLogs::loadNPeriods( if (!run.hasProperty(nPeriodsLabel)) { run.addProperty(new PropertyWithValue<int>(nPeriodsLabel, value)); } + + // For ISIS Nexus only, fabricate an additional log containing an array of + // proton charge information from the periods group. + try { + file.openGroup("periods", "IXperiods"); + + // Get the number of periods again + file.openData("number"); + int numberOfPeriods = 0; + file.getData(&numberOfPeriods); + file.closeData(); + + // Get the proton charge vector + std::vector<double> protonChargeByPeriod(numberOfPeriods); + file.openData("proton_charge"); + file.getDataCoerce(protonChargeByPeriod); + file.closeData(); + + // Add the proton charge vector + API::Run &run = workspace->mutableRun(); + const std::string protonChargeByPeriodLabel = "proton_charge_by_period"; + if (!run.hasProperty(protonChargeByPeriodLabel)) { + run.addProperty(new ArrayProperty<double>(protonChargeByPeriodLabel, protonChargeByPeriod)); + } + file.closeGroup(); + } catch (::NeXus::Exception &) { + this->g_log.debug("Cannot read periods information from the nexus file. " + "This group may be absent."); + file.closeGroup(); + } catch (std::runtime_error &) { + this->g_log.debug("Cannot read periods information from the nexus file. " + "This group may be absent."); + file.closeGroup(); + } } /** diff --git a/Framework/DataHandling/test/LoadNexusLogsTest.h b/Framework/DataHandling/test/LoadNexusLogsTest.h index d530d8e5641b8fb849eca30ab54267d71eaa8e2a..02680ca3917a18d1c39101dbc53a79931aa82881 100644 --- a/Framework/DataHandling/test/LoadNexusLogsTest.h +++ b/Framework/DataHandling/test/LoadNexusLogsTest.h @@ -12,6 +12,7 @@ #include "MantidDataObjects/Workspace2D.h" #include "MantidKernel/PhysicalConstants.h" + using namespace Mantid; using namespace Mantid::Geometry; using namespace Mantid::API; @@ -168,6 +169,12 @@ public: periodValues.end()); TSM_ASSERT_EQUALS("Should have 4 periods in total", 4, uniquePeriods.size()); + + const bool hasProtonChargeByPeriod = run.hasProperty("run_title"); + TSM_ASSERT("Should have extracted proton_charge_by_period log.", hasProtonChargeByPeriod); + + std::vector<double> protonChargeByPeriod = run.getPropertyValueAsType<std::vector<double>>("proton_charge_by_period"); + TSM_ASSERT_EQUALS("Should have four proton charge entries", 4, protonChargeByPeriod.size()); } void test_extract_run_title_from_event_nexus() {