From ef138db203892c0877ae9a9c53fce5403829af56 Mon Sep 17 00:00:00 2001 From: Gagik Vardanyan <vardanyan@ill.fr> Date: Wed, 1 Mar 2017 16:49:58 +0100 Subject: [PATCH] Re #18868 better way of reading data from raw array --- .../MantidDataHandling/LoadILLDiffraction.h | 4 +-- .../DataHandling/src/LoadILLDiffraction.cpp | 34 +++++-------------- .../Nexus/inc/MantidNexus/NexusClasses.h | 6 ++++ 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h b/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h index 2482073366b..fdb225b61ba 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadILLDiffraction.h @@ -46,9 +46,7 @@ private: void init() override; void exec() override; - void loadDataDetails(NeXus::NXEntry&); - void loadDataScan(NeXus::NXEntry&); - void loadDetectorScan(NeXus::NXEntry&); + void loadDataScan(); void loadStaticInstrument(); void loadMovingInstrument(); void loadMetadata(); diff --git a/Framework/DataHandling/src/LoadILLDiffraction.cpp b/Framework/DataHandling/src/LoadILLDiffraction.cpp index a48eac03f64..d844dfbdef6 100644 --- a/Framework/DataHandling/src/LoadILLDiffraction.cpp +++ b/Framework/DataHandling/src/LoadILLDiffraction.cpp @@ -73,11 +73,7 @@ void LoadILLDiffraction::exec() { m_fileName = getPropertyValue("Filename"); - // open the root node - NXRoot dataRoot(m_fileName); - NXEntry firstEntry = dataRoot.openFirstEntry(); - - loadDataScan(firstEntry); + loadDataScan(); m_progress->report("Loaded data scan"); //loadMetadata(); @@ -90,20 +86,22 @@ void LoadILLDiffraction::exec() { /** * Load the data scan */ -void LoadILLDiffraction::loadDataScan(NXEntry &firstEntry) { +void LoadILLDiffraction::loadDataScan() { - std::string instName = firstEntry.getString("instrument/name"); + // open the root node + NXRoot dataRoot(m_fileName); + NXEntry firstEntry = dataRoot.openFirstEntry(); m_numberScanPoints = firstEntry.getInt("data_scan/total_steps"); // read in the actual data NXData dataGroup = firstEntry.openNXData("data_scan/detector_data"); - NXInt data = dataGroup.openIntData(); + NXUInt data = dataGroup.openUIntData(); data.load(); m_numberDetectorsRead = data.dim1(); - resolveInstrument(instName); + resolveInstrument(firstEntry.getString("instrument/name")); // read the scanned variables NXInt scannedVar = firstEntry.openNXInt( @@ -145,13 +143,14 @@ void LoadILLDiffraction::loadDataScan(NXEntry &firstEntry) { // Assign detector counts for (int i = 1; i <= data.dim1(); ++i) { for (int j = 0; j < data.dim0(); ++j) { - double y = double(data()[j * data.dim1() + i - 1]); + unsigned int y = data(j, i - 1); m_outWorkspace->mutableY(i)[j] = y; m_outWorkspace->mutableE(i)[j] = sqrt(y); } m_outWorkspace->mutableX(i) = xAxis; } + dataRoot.close(); loadStaticInstrument(); } @@ -185,21 +184,6 @@ void LoadILLDiffraction::resolveInstrument(const std::string &inst) { throw std::runtime_error("Unknown resolution mode for instrument " + inst); } - } else if (inst == "D4") { - switch (m_numberDetectorsRead) { - m_numberDetectorsActual = m_numberDetectorsRead; - case 576: { - m_instName = "D4a"; - break; - } - case 1152: { - m_instName = "D4b"; - break; - } - default: - throw std::runtime_error("Unknown resolution mode for instrument " + - inst); - } } else { m_instName = inst; m_numberDetectorsActual = m_numberDetectorsRead; diff --git a/Framework/Nexus/inc/MantidNexus/NexusClasses.h b/Framework/Nexus/inc/MantidNexus/NexusClasses.h index 4a32c98b6b2..63b836eb72e 100644 --- a/Framework/Nexus/inc/MantidNexus/NexusClasses.h +++ b/Framework/Nexus/inc/MantidNexus/NexusClasses.h @@ -480,6 +480,8 @@ typedef NXDataSetTyped<double> NXDouble; typedef NXDataSetTyped<char> NXChar; /// The size_t dataset type typedef NXDataSetTyped<std::size_t> NXSize; +/// The size_t dataset type +typedef NXDataSetTyped<unsigned int> NXUInt; //-------------------- classes --------------------------// @@ -866,6 +868,10 @@ public: NXFloat openFloatData() { return openData<float>(); } /// Opens data of int type NXInt openIntData() { return openData<int>(); } + /// Opens data of size type + NXSize openSizeData() { return openData<std::size_t>(); } + /// Opens data of unsigned int type + NXUInt openUIntData() { return openData<unsigned int>(); } }; /** Implements NXdetector Nexus class. -- GitLab