From eafc0ad37364a57e0e910e328ae9b1573df71df2 Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@stfc.ac.uk>
Date: Tue, 8 Feb 2011 13:11:47 +0000
Subject: [PATCH] Fix for test problems with WorkspaceProperty types. Re #2329

---
 .../inc/MantidDataHandling/Load.h             |  5 +++-
 .../Framework/DataHandling/src/Load.cpp       | 27 ++++++++++++++++++-
 .../DataHandling/src/LoadRawHelper.cpp        |  4 +--
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h
index 05b7b30d111..cc7b3954402 100644
--- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h
+++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/Load.h
@@ -63,7 +63,7 @@ namespace Mantid
       API::IAlgorithm_sptr getFileLoader(const std::string& filePath);
       /// Declare any additional input properties from the concrete loader
       void declareLoaderProperties(const API::IAlgorithm_sptr loader);
-
+      
       /// Initialize the static base properties
       void init();
       /// Execute
@@ -73,6 +73,9 @@ namespace Mantid
 					const double endProgress=-1.0, const bool logging = true) const;
       /// Set the output workspace(s)
       void setOutputWorkspace(const API::IAlgorithm_sptr loader);
+      /// Retrieve a pointer to the output workspace from the sub algorithm
+      API::Workspace_sptr getOutputWorkspace(const API::IAlgorithm_sptr loader) const;
+      
 
     private:
       /// The base properties
diff --git a/Code/Mantid/Framework/DataHandling/src/Load.cpp b/Code/Mantid/Framework/DataHandling/src/Load.cpp
index f8d12fd54bc..b16b0aa9951 100644
--- a/Code/Mantid/Framework/DataHandling/src/Load.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/Load.cpp
@@ -303,7 +303,7 @@ namespace Mantid
      */
     void Load::setOutputWorkspace(const API::IAlgorithm_sptr load)
     {
-      Workspace_sptr childWS = load->getProperty("OutputWorkspace");
+      Workspace_sptr childWS = getOutputWorkspace(load);
       if( WorkspaceGroup_sptr wsGroup = boost::dynamic_pointer_cast<WorkspaceGroup>(childWS) )
       {
 	std::vector<std::string> names = wsGroup->getNames();
@@ -322,5 +322,30 @@ namespace Mantid
       setProperty("OutputWorkspace", childWS);
     }
 
+    /**
+     * Return the top-level workspace property
+     * @returns A pointer to the OutputWorkspace property of the sub algorithm
+     */
+    API::Workspace_sptr Load::getOutputWorkspace(const API::IAlgorithm_sptr loader) const
+    {
+      try
+      {
+	return loader->getProperty("OutputWorkspace");
+      }
+      catch(std::runtime_error&)
+      {
+      }
+      // Try a MatrixWorkspace
+      try
+      {
+	MatrixWorkspace_sptr childWS = loader->getProperty("OutputWorkspace");
+	return childWS;
+      }
+      catch(std::runtime_error&)
+      {
+      }
+      return Workspace_sptr();
+    }
+
   } // namespace DataHandling
 } // namespace Mantid
diff --git a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
index c0faa778aa1..ab3b1464509 100644
--- a/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
+++ b/Code/Mantid/Framework/DataHandling/src/LoadRawHelper.cpp
@@ -343,9 +343,9 @@ namespace Mantid
         outputWorkspace = "OutputWorkspace";
       }
       outws = outputWorkspace + "_" + suffix.str();
-      declareProperty(new WorkspaceProperty<DataObjects::Workspace2D> (outws, wsName, Direction::Output));
+      declareProperty(new WorkspaceProperty<Workspace> (outws, wsName, Direction::Output));
       grpws_sptr->add(wsName);
-      setProperty(outws, boost::dynamic_pointer_cast<DataObjects::Workspace2D>(ws_sptr));
+      setProperty(outws, boost::static_pointer_cast<Workspace>(ws_sptr));
     }
 
     /** This method sets the workspace property
-- 
GitLab