From 0e064a7ff78427df06094f3ae56603f09a58247f Mon Sep 17 00:00:00 2001
From: Nick Draper <nick.draper@stfc.ac.uk>
Date: Wed, 27 May 2015 17:19:43 +0100
Subject: [PATCH] Further steps as defined below

 1. Change the filename reported for nexus files if xml contained within
 1. Stop saving the filename to nexus processed files
 1. removed some unused includes

Still to do:
 1. cache SHA1 checksum if needed
 1. Manually test
 1. update documentation
 1. investigate this error:

ctest -C Debug -J 4 -R LoadEventNexusTest -V

 548: LoadParameterFile-[Error] Bad path syntax: C:\Mantid\Code\Mantid\instrument
\C:\Users\rrc79113\AppData\Roaming\mantidproject\mantid\instrument\HYSPECA_Param
eters.xml. Unable to parse File: in C:/Mantid/Code/Mantid/instrument//C:\Users\r
rc79113\AppData\Roaming\mantidproject\mantid\instrument\HYSPECA_Parameters.xml
548: LoadIDFFromNexus-[Notice] Instrument parameter file: C:\Users\rrc79113\AppD
ata\Roaming\mantidproject\mantid\instrument\HYSPECA_Parameters.xml not found or
un-parsable. Instrument parameter file: C:/Mantid/Code/Mantid/instrument/HYSPECA
_Parameters.xml has been loaded

re #11818
---
 .../API/inc/MantidAPI/ExperimentInfo.h        |  4 ++--
 .../Framework/API/src/ExperimentInfo.cpp      | 15 +++++++++------
 .../API/src/FileBackedExperimentInfo.cpp      |  2 +-
 .../Framework/API/test/ExperimentInfoTest.h   | 19 ++++++++++---------
 .../API/test/FileBackedExperimentInfoTest.h   |  4 +---
 .../Algorithms/src/CreateDummyCalFile.cpp     |  2 --
 .../DataHandling/src/LoadEmptyInstrument.cpp  |  2 --
 .../DataHandling/src/LoadIDFFromNexus.cpp     |  2 +-
 .../DataHandling/src/LoadNexusProcessed.cpp   | 14 ++++----------
 .../DataHandling/src/SaveNexusProcessed.cpp   |  3 ---
 .../DataHandling/test/LoadEventNexusTest.h    |  1 -
 .../DataObjects/src/MDBoxFlatTree.cpp         |  4 +---
 .../Framework/Geometry/src/Instrument.cpp     |  3 ---
 .../Geometry/src/Instrument/IDFObject.cpp     |  1 -
 14 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h b/Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
index bd0d1c05f9d..22b9f68afef 100644
--- a/Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
+++ b/Code/Mantid/Framework/API/inc/MantidAPI/ExperimentInfo.h
@@ -118,9 +118,9 @@ public:
   /// Saves this experiment description to the open NeXus file
   virtual void saveExperimentInfoNexus(::NeXus::File *file) const;
   /// Loads an experiment description from the open NeXus file
-  virtual void loadExperimentInfoNexus(::NeXus::File *file, std::string &parameterStr);
+  virtual void loadExperimentInfoNexus(const std::string& nxFilename, ::NeXus::File *file, std::string &parameterStr);
   /// Load the instrument from an open NeXus file.
-  virtual void loadInstrumentInfoNexus(::NeXus::File *file, std::string &parameterStr);
+  virtual void loadInstrumentInfoNexus(const std::string& nxFilename, ::NeXus::File *file, std::string &parameterStr);
 
   /// Load the sample and log info from an open NeXus file.
   virtual void loadSampleAndLogInfoNexus(::NeXus::File *file);
diff --git a/Code/Mantid/Framework/API/src/ExperimentInfo.cpp b/Code/Mantid/Framework/API/src/ExperimentInfo.cpp
index a2d400489c0..ee9718586f7 100644
--- a/Code/Mantid/Framework/API/src/ExperimentInfo.cpp
+++ b/Code/Mantid/Framework/API/src/ExperimentInfo.cpp
@@ -15,7 +15,6 @@
 #include "MantidKernel/InstrumentInfo.h"
 #include "MantidKernel/Property.h"
 #include "MantidKernel/Strings.h"
-#include "MantidKernel/TimeSeriesProperty.h"
 
 #include <boost/algorithm/string.hpp>
 #include <boost/make_shared.hpp>
@@ -928,6 +927,7 @@ void ExperimentInfo::loadSampleAndLogInfoNexus(::NeXus::File *file) {
 //--------------------------------------------------------------------------------------------
 /** Load the object from an open NeXus file.
  * @param file :: open NeXus file
+ * @param nxFilename :: the filename of the nexus file
  * @param[out] parameterStr :: special string for all the parameters.
  *             Feed that to ExperimentInfo::readParameterMap() after the
  * instrument is done.
@@ -935,17 +935,19 @@ void ExperimentInfo::loadSampleAndLogInfoNexus(::NeXus::File *file) {
  * file and cannot
  *                                  be loaded from the IDF.
  */
-void ExperimentInfo::loadExperimentInfoNexus(::NeXus::File *file,
+void ExperimentInfo::loadExperimentInfoNexus(const std::string& nxFilename, 
+                                             ::NeXus::File *file,
                                              std::string &parameterStr) {
   // load sample and log info
   loadSampleAndLogInfoNexus(file);
 
-  loadInstrumentInfoNexus(file, parameterStr);
+  loadInstrumentInfoNexus(nxFilename, file, parameterStr);
 }
 
 //--------------------------------------------------------------------------------------------
 /** Load the instrument from an open NeXus file.
  * @param file :: open NeXus file
+ * @param nxFilename :: the filename of the nexus file
  * @param[out] parameterStr :: special string for all the parameters.
  *             Feed that to ExperimentInfo::readParameterMap() after the
  * instrument is done.
@@ -953,7 +955,8 @@ void ExperimentInfo::loadExperimentInfoNexus(::NeXus::File *file,
  * file and cannot
  *                                  be loaded from the IDF.
  */
-void ExperimentInfo::loadInstrumentInfoNexus(::NeXus::File *file,
+void ExperimentInfo::loadInstrumentInfoNexus(const std::string& nxFilename,
+                                             ::NeXus::File *file,
                                              std::string &parameterStr) {
   std::string instrumentName;
   std::string instrumentXml;
@@ -1003,13 +1006,13 @@ void ExperimentInfo::loadInstrumentInfoNexus(::NeXus::File *file,
     file->closeGroup();
   }
 
-  instrumentFilename = Strings::strip(instrumentFilename);
+  instrumentFilename = Strings::strip(instrumentFilename);;
   instrumentXml = Strings::strip(instrumentXml);
   instrumentName = Strings::strip(instrumentName);
   if (!instrumentXml.empty()) {
     // instrument xml is being loaded from the nxs file, set the instrumentFilename
     // to identify the Nexus file as the source of the data
-    instrumentFilename = instrumentFilename;
+    instrumentFilename = nxFilename;
     g_log.debug() << "Using instrument IDF XML text contained in nexus file.\n";
   }
   else
diff --git a/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp b/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp
index 64c7084fdff..46b48f0cba0 100644
--- a/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp
+++ b/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp
@@ -301,7 +301,7 @@ void FileBackedExperimentInfo::populateFromFile() const {
 
     std::string parameterStr;
     const_cast<FileBackedExperimentInfo *>(this)
-        ->loadExperimentInfoNexus(&nxFile, parameterStr);
+        ->loadExperimentInfoNexus(m_filename, &nxFile, parameterStr);
     const_cast<FileBackedExperimentInfo *>(this)
         ->readParameterMap(parameterStr);
   } catch (::NeXus::Exception &exc) {
diff --git a/Code/Mantid/Framework/API/test/ExperimentInfoTest.h b/Code/Mantid/Framework/API/test/ExperimentInfoTest.h
index 80592866959..54dff4064b7 100644
--- a/Code/Mantid/Framework/API/test/ExperimentInfoTest.h
+++ b/Code/Mantid/Framework/API/test/ExperimentInfoTest.h
@@ -18,8 +18,6 @@
 #include <boost/regex.hpp>
 #include <Poco/DirectoryIterator.h>
 
-#include <iomanip>
-#include <iostream>
 #include <set>
 
 using namespace Mantid::API;
@@ -593,22 +591,23 @@ public:
 
   void test_nexus()
   {
+    std::string filename = "ExperimentInfoTest1.nxs";
     NexusTestHelper th(true);
-    th.createFile("ExperimentInfoTest1.nxs");
+    th.createFile(filename);
     ExperimentInfo ws;
     boost::shared_ptr<Instrument> inst1(new Instrument());
     inst1->setName("GEM");
     inst1->setFilename("GEM_Definition.xml");
     inst1->setXmlText("");
     ws.setInstrument(inst1);
-
+    
     TS_ASSERT_THROWS_NOTHING( ws.saveExperimentInfoNexus(th.file); );
 
     // ------------------------ Re-load the contents ----------------------
     ExperimentInfo ws2;
     std::string parameterStr;
     th.reopenFile();
-    TS_ASSERT_THROWS_NOTHING( ws2.loadExperimentInfoNexus(th.file, parameterStr) );
+    TS_ASSERT_THROWS_NOTHING( ws2.loadExperimentInfoNexus(filename, th.file, parameterStr) );
     Instrument_const_sptr inst = ws2.getInstrument();
     TS_ASSERT_EQUALS( inst->getName(), "GEM" );
     TS_ASSERT( inst->getFilename().find("GEM_Definition.xml",0) != std::string::npos );
@@ -618,8 +617,9 @@ public:
 
   void test_nexus_empty_instrument()
   {
+    std::string filename = "ExperimentInfoTest2.nxs";
     NexusTestHelper th(true);
-    th.createFile("ExperimentInfoTest2.nxs");
+    th.createFile(filename);
     ExperimentInfo ws;
     boost::shared_ptr<Instrument> inst1(new Instrument());
     inst1->setName("");
@@ -633,7 +633,7 @@ public:
     ExperimentInfo ws2;
     std::string parameterStr;
     th.reopenFile();
-    TS_ASSERT_THROWS_NOTHING( ws2.loadExperimentInfoNexus(th.file, parameterStr) );
+    TS_ASSERT_THROWS_NOTHING( ws2.loadExperimentInfoNexus(filename, th.file, parameterStr) );
     Instrument_const_sptr inst = ws2.getInstrument();
     TS_ASSERT_EQUALS( inst->getName(), "" );
     TS_ASSERT_EQUALS( parameterStr, "" );
@@ -641,8 +641,9 @@ public:
 
   void testNexus_W_matrix()
   {
+      std::string filename = "ExperimentInfoWMatrixTest.nxs";
       NexusTestHelper th(true);
-      th.createFile("ExperimentInfoWMatrixTest.nxs");
+      th.createFile(filename);
       ExperimentInfo ei;
 
       DblMatrix WTransf(3,3,true);
@@ -665,7 +666,7 @@ public:
 
       ExperimentInfo other;
       std::string InstrParameters;
-      TS_ASSERT_THROWS_NOTHING(other.loadExperimentInfoNexus(th.file,InstrParameters));
+      TS_ASSERT_THROWS_NOTHING(other.loadExperimentInfoNexus(filename, th.file,InstrParameters));
 
       std::vector<double> wMatrRestored=other.run().getPropertyValueAsType<std::vector<double> >("W_MATRIX");
 
diff --git a/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h b/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h
index f3fa9eb6c62..2f367c924d4 100644
--- a/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h
+++ b/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h
@@ -36,7 +36,7 @@ public:
     ::NeXus::File nxFile(m_filename, NXACC_READ);
     nxFile.openGroup("mantid_workspace_1", "NXentry");
     std::string paramString;
-    m_inMemoryExptInfo->loadExperimentInfoNexus(&nxFile, paramString);
+    m_inMemoryExptInfo->loadExperimentInfoNexus(m_filename, &nxFile, paramString);
     m_inMemoryExptInfo->readParameterMap(paramString);
   }
 
@@ -56,8 +56,6 @@ public:
 
   void test_getInstrument_populates_object() {
     auto fileBacked = createTestObject();
-    auto fileBackedInstrument = fileBacked->getInstrument();
-    auto inMemoryInstrument = m_inMemoryExptInfo->getInstrument();
 
     TS_ASSERT_EQUALS(fileBacked->constInstrumentParameters(),
                      m_inMemoryExptInfo->constInstrumentParameters());
diff --git a/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp b/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
index 74917185765..a52545be047 100644
--- a/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/CreateDummyCalFile.cpp
@@ -14,8 +14,6 @@
 #include <Poco/DOM/DOMParser.h>
 #include <Poco/DOM/Document.h>
 #include <Poco/DOM/Element.h>
-#include <Poco/File.h>
-#include <Poco/Path.h>
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/detail/classification.hpp>
 
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadEmptyInstrument.cpp b/Code/Mantid/Framework/DataHandling/src/LoadEmptyInstrument.cpp
index dd0048791d0..ea0be927b4d 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadEmptyInstrument.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadEmptyInstrument.cpp
@@ -5,8 +5,6 @@
 #include "MantidKernel/ConfigService.h"
 #include "MantidKernel/BoundedValidator.h"
 #include "MantidAPI/RegisterFileLoader.h"
-#include <cmath>
-#include <Poco/Path.h>
 
 namespace Mantid {
 namespace DataHandling {
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadIDFFromNexus.cpp b/Code/Mantid/Framework/DataHandling/src/LoadIDFFromNexus.cpp
index 41c64c2b9c1..de2bebdd7de 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadIDFFromNexus.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadIDFFromNexus.cpp
@@ -67,7 +67,7 @@ void LoadIDFFromNexus::exec() {
   // If the nexus file also contains a instrument parameter map entry this
   // is returned as parameterString
   std::string parameterString;
-  localWorkspace->loadInstrumentInfoNexus(&nxfile, parameterString);
+  localWorkspace->loadInstrumentInfoNexus(filename, &nxfile, parameterString);
   // at present loadInstrumentInfoNexus does not populate any instrument params
   // into the workspace including those that are defined in the IDF.
   // Here populate inst params defined in IDF
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp b/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
index 59d6ac822dc..bea9fc80876 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadNexusProcessed.cpp
@@ -15,8 +15,8 @@
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidDataObjects/PeakNoShapeFactory.h"
 #include "MantidDataObjects/PeakShapeSphericalFactory.h"
+#include "MantidDataObjects/PeakShapeEllipsoidFactory.h"
 #include "MantidKernel/ArrayProperty.h"
-#include "MantidKernel/ConfigService.h"
 #include "MantidKernel/DateAndTime.h"
 #include "MantidKernel/UnitFactory.h"
 #include "MantidKernel/BoundedValidator.h"
@@ -28,14 +28,8 @@
 #include <boost/regex.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/shared_array.hpp>
-#include <cmath>
-#include <Poco/Path.h>
+
 #include <Poco/StringTokenizer.h>
-#include "MantidDataObjects/PeaksWorkspace.h"
-#include "MantidKernel/MultiThreaded.h"
-#include "MantidDataObjects/PeakNoShapeFactory.h"
-#include "MantidDataObjects/PeakShapeSphericalFactory.h"
-#include "MantidDataObjects/PeakShapeEllipsoidFactory.h"
 
 #include <nexus/NeXusException.hpp>
 
@@ -1033,7 +1027,7 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
   m_cppFile->openPath(entry.path()); // This is
   try {
     // This loads logs, sample, and instrument.
-    peakWS->loadExperimentInfoNexus(m_cppFile, parameterStr);
+    peakWS->loadExperimentInfoNexus(getPropertyValue("Filename"), m_cppFile, parameterStr);
   } catch (std::exception &e) {
     g_log.information("Error loading Instrument section of nxs file");
     g_log.information(e.what());
@@ -1557,7 +1551,7 @@ API::Workspace_sptr LoadNexusProcessed::loadEntry(NXRoot &root,
   m_cppFile->openPath(mtd_entry.path());
   try {
     // This loads logs, sample, and instrument.
-    local_workspace->loadExperimentInfoNexus(
+    local_workspace->loadExperimentInfoNexus(getPropertyValue("Filename"), 
         m_cppFile, parameterStr); // REQUIRED PER PERIOD
   } catch (std::exception &e) {
     g_log.information("Error loading Instrument section of nxs file");
diff --git a/Code/Mantid/Framework/DataHandling/src/SaveNexusProcessed.cpp b/Code/Mantid/Framework/DataHandling/src/SaveNexusProcessed.cpp
index 7f0833ecbf6..920cb2deb2f 100644
--- a/Code/Mantid/Framework/DataHandling/src/SaveNexusProcessed.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/SaveNexusProcessed.cpp
@@ -10,15 +10,12 @@
 #include "MantidDataObjects/PeaksWorkspace.h"
 #include "MantidDataObjects/OffsetsWorkspace.h"
 #include "MantidKernel/ArrayProperty.h"
-#include "MantidKernel/ConfigService.h"
 #include "MantidKernel/BoundedValidator.h"
 #include "MantidNexus/NexusFileIO.h"
 #include <nexus/NeXusFile.hpp>
 #include <boost/regex.hpp>
 #include <boost/shared_ptr.hpp>
-#include <cmath>
 #include <Poco/File.h>
-#include <Poco/Path.h>
 
 using namespace Mantid::API;
 
diff --git a/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h b/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h
index b5dccfdd468..d90f0121239 100644
--- a/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h
+++ b/Code/Mantid/Framework/DataHandling/test/LoadEventNexusTest.h
@@ -490,7 +490,6 @@ public:
 
     auto ws = AnalysisDataService::Instance().retrieveWS<EventWorkspace>(outws);
     auto inst = ws->getInstrument();
-    TS_ASSERT( inst->getFilename().empty() ); // This is how we know we got it from inside the nexus file
     TS_ASSERT_EQUALS( inst->getName(), "HYSPECA" );
     TS_ASSERT_EQUALS( inst->getValidFromDate(), std::string("2011-Jul-20 17:02:48.437294000") );
     TS_ASSERT_EQUALS( inst->getNumberDetectors(), 20483 );
diff --git a/Code/Mantid/Framework/DataObjects/src/MDBoxFlatTree.cpp b/Code/Mantid/Framework/DataObjects/src/MDBoxFlatTree.cpp
index 4bbb537e1cd..19117d593b5 100644
--- a/Code/Mantid/Framework/DataObjects/src/MDBoxFlatTree.cpp
+++ b/Code/Mantid/Framework/DataObjects/src/MDBoxFlatTree.cpp
@@ -1,7 +1,5 @@
 #include "MantidKernel/Strings.h"
 #include "MantidDataObjects/MDBoxFlatTree.h"
-#include "MantidDataObjects/MDEvent.h"
-#include "MantidDataObjects/MDLeanEvent.h"
 #include "MantidAPI/BoxController.h"
 #include "MantidAPI/FileBackedExperimentInfo.h"
 #include "MantidDataObjects/MDEventFactory.h"
@@ -461,7 +459,7 @@ void MDBoxFlatTree::loadExperimentInfos(::NeXus::File *const file, const std::st
       std::string parameterStr;
       try {
         // Get the sample, logs, instrument
-        ei->loadExperimentInfoNexus(file, parameterStr);
+        ei->loadExperimentInfoNexus(filename, file, parameterStr);
         // Now do the parameter map
         ei->readParameterMap(parameterStr);
         // And add it to the mutliple experiment info.
diff --git a/Code/Mantid/Framework/Geometry/src/Instrument.cpp b/Code/Mantid/Framework/Geometry/src/Instrument.cpp
index 368d093b6b6..5607adc721d 100644
--- a/Code/Mantid/Framework/Geometry/src/Instrument.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Instrument.cpp
@@ -4,7 +4,6 @@
 #include "MantidGeometry/Instrument/ReferenceFrame.h"
 #include "MantidGeometry/Instrument/RectangularDetector.h"
 
-#include <Poco/Path.h>
 #include <queue>
 
 using namespace Mantid::Kernel;
@@ -1071,8 +1070,6 @@ void Instrument::saveNexus(::NeXus::File *file,
   file->writeData("description", "XML contents of the instrument IDF file.");
   file->closeGroup();
 
-  file->writeData("instrument_source", Poco::Path(getFilename()).getFileName());
-
   // Now the parameter map, as a NXnote via its saveNexus method
   if (isParametrized()) {
     const Geometry::ParameterMap &params = *getParameterMap();
diff --git a/Code/Mantid/Framework/Geometry/src/Instrument/IDFObject.cpp b/Code/Mantid/Framework/Geometry/src/Instrument/IDFObject.cpp
index 150a84be6b9..b12a725e861 100644
--- a/Code/Mantid/Framework/Geometry/src/Instrument/IDFObject.cpp
+++ b/Code/Mantid/Framework/Geometry/src/Instrument/IDFObject.cpp
@@ -1,6 +1,5 @@
 #include "MantidGeometry/Instrument/IDFObject.h"
 #include "MantidKernel/ChecksumHelper.h"
-#include <Poco/DateTimeFormatter.h>
 #include <Poco/String.h>
 
 namespace Mantid {
-- 
GitLab