From 6ca216ac85d64d46855fb547e82c47ec87bdbbe9 Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Mon, 7 Oct 2013 09:01:04 +0100
Subject: [PATCH] UpdateInstrumentFromFile now accepts ISIS Event Nexus files.

Refs #8057
---
 .../UpdateInstrumentFromFile.h                |  3 +-
 .../src/UpdateInstrumentFromFile.cpp          | 39 +++++++------------
 2 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/UpdateInstrumentFromFile.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/UpdateInstrumentFromFile.h
index daf6e23cc60..8d80bc9c5bb 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/UpdateInstrumentFromFile.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/UpdateInstrumentFromFile.h
@@ -5,6 +5,7 @@
 // Includes
 //----------------------------------------------------------------------
 #include "MantidAPI/Algorithm.h"
+#include <nexus/NeXusFile.hpp>
 
 namespace Mantid
 {
@@ -85,7 +86,7 @@ namespace Mantid
       /// Assumes the file is a raw file
       void updateFromRaw(const std::string & filename);
       /// Assumes the file is an ISIS NeXus file
-      void updateFromNeXus(const std::string & filename);
+      void updateFromNeXus(::NeXus::File & nxFile);
       /// Updates from a more generic ascii file
       void updateFromAscii(const std::string & filename);
 
diff --git a/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp b/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp
index 866ae49f904..0936e932c14 100644
--- a/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/UpdateInstrumentFromFile.cpp
@@ -39,6 +39,7 @@ would tell the algorithm to interpret the columns as:
 //----------------------------------------------------------------------
 #include "MantidDataHandling/UpdateInstrumentFromFile.h"
 #include "MantidDataHandling/LoadAscii.h"
+#include "MantidDataHandling/LoadEventNexus.h"
 #include "MantidDataHandling/LoadISISNexus2.h"
 #include "MantidDataHandling/LoadRawHelper.h"
 #include "MantidAPI/FileProperty.h"
@@ -46,12 +47,11 @@ would tell the algorithm to interpret the columns as:
 #include "MantidGeometry/Instrument.h"
 #include "MantidGeometry/Instrument/ComponentHelper.h"
 #include "MantidKernel/NexusDescriptor.h"
-#include <nexus/NeXusFile.hpp>
-#include <nexus/NeXusException.hpp>
 #include "LoadRaw/isisraw2.h"
 
 #include <boost/scoped_ptr.hpp>
 #include <boost/algorithm/string/predicate.hpp>
+#include <nexus/NeXusException.hpp>
 #include <Poco/StringTokenizer.h>
 
 #include <fstream>
@@ -136,11 +136,14 @@ namespace Mantid
       if(NexusDescriptor::isHDF(filename))
       {
         LoadISISNexus2 isisNexus;
-        auto *descriptor = new Kernel::NexusDescriptor(filename);
-        if(isisNexus.confidence(*descriptor) > 0)
+        LoadEventNexus eventNexus;
+        boost::scoped_ptr<Kernel::NexusDescriptor> descriptor(new Kernel::NexusDescriptor(filename));
+        if(isisNexus.confidence(*descriptor) > 0 || eventNexus.confidence(*descriptor) > 0)
         {
-          delete descriptor;
-          updateFromNeXus(filename);
+          auto & nxFile = descriptor->data();
+          const auto & rootEntry = descriptor->firstEntryNameType();
+          nxFile.openGroup(rootEntry.first, rootEntry.second);
+          updateFromNeXus(nxFile);
           return;
         }
       }
@@ -207,33 +210,17 @@ namespace Mantid
 
     /**
     * Update the detector information from a NeXus file
-    * @param filename :: The input filename
+    * @param nxFile :: Handle to a NeXus file where the root group has been opened
     */
-    void UpdateInstrumentFromFile::updateFromNeXus(const std::string & filename)
+    void UpdateInstrumentFromFile::updateFromNeXus(::NeXus::File & nxFile)
     {
       try
       {
-        ::NeXus::File file(filename);
-      }
-      catch(::NeXus::Exception&)
-      {
-        throw std::runtime_error("Input file does not look like an ISIS NeXus file.");
-      }
-      ::NeXus::File nxFile(filename);
-      try
-      {
-        nxFile.openPath("raw_data_1/isis_vms_compat");
+        nxFile.openGroup("isis_vms_compat","IXvms");
       }
       catch(::NeXus::Exception&)
       {
-        try
-        {
-          nxFile.openPath("entry/isis_vms_compat"); // Could be original event file.
-        }
-        catch(::NeXus::Exception&)
-        {
-          throw std::runtime_error("Unknown NeXus flavour. Cannot update instrument positions.");
-        }
+        throw std::runtime_error("Unknown NeXus flavour. Cannot update instrument positions using this type of file");
       }
       // Det ID
       std::vector<int32_t> detID;
-- 
GitLab