From a257b5a0ea60c1acc18ff3b11c53610ac1ef43e5 Mon Sep 17 00:00:00 2001
From: Sofia Antony <sofia.antony@stfc.ac.uk>
Date: Thu, 8 Jul 2010 10:11:19 +0000
Subject: [PATCH] re #1317 - Some improvements over ICat prototype code. Added
 new class MaskedProperty to mask some of the properties of ICat algorithms
 Added ICat download directory to Build/Tests/Mantid.Properties file

---
 Code/Mantid/Build/Tests/Mantid.properties     |   4 +
 .../inc/MantidDataObjects/TableWorkspace.h    |  31 +-
 Code/Mantid/ICat/ICat.vcproj                  |   4 +
 .../ICat/inc/MantidICat/DownloadDataFile.h    |  71 ++-
 Code/Mantid/ICat/inc/MantidICat/FileList.h    |   5 +-
 .../ICat/inc/MantidICat/GetInvestigation.h    |  52 +-
 Code/Mantid/ICat/inc/MantidICat/Login.h       |  40 +-
 .../ICat/inc/MantidICat/SearchByRunNumber.h   |  47 +-
 .../Mantid/ICat/inc/MantidICat/SearchHelper.h |  83 ++--
 Code/Mantid/ICat/inc/MantidICat/Session.h     |  45 +-
 Code/Mantid/ICat/src/DownloadDataFile.cpp     | 457 +++++++++++-------
 Code/Mantid/ICat/src/FileList.cpp             |  13 +-
 Code/Mantid/ICat/src/GetInvestigation.cpp     |  67 +--
 Code/Mantid/ICat/src/Login.cpp                |  44 +-
 Code/Mantid/ICat/src/SearchByRunNumber.cpp    |  68 +--
 Code/Mantid/ICat/src/SearchHelper.cpp         | 371 +++++++-------
 Code/Mantid/ICat/test/DownloadDataFileTest.h  | 146 ++++--
 Code/Mantid/ICat/test/FileListTest.h          |  25 +-
 Code/Mantid/ICat/test/LoginTest.h             |  46 +-
 Code/Mantid/ICat/test/SearchByRunNumberTest.h |  48 +-
 .../Kernel/inc/MantidKernel/MaskedProperty.h  |  96 ++++
 Code/Mantid/Kernel/src/ConfigService.cpp      |   1 +
 Code/Mantid/Kernel/src/MaskedProperty.cpp     |  12 +
 Code/Mantid/Kernel/test/MaskedPropertyTest.h  |  47 ++
 24 files changed, 1188 insertions(+), 635 deletions(-)
 create mode 100644 Code/Mantid/Kernel/inc/MantidKernel/MaskedProperty.h
 create mode 100644 Code/Mantid/Kernel/src/MaskedProperty.cpp
 create mode 100644 Code/Mantid/Kernel/test/MaskedPropertyTest.h

diff --git a/Code/Mantid/Build/Tests/Mantid.properties b/Code/Mantid/Build/Tests/Mantid.properties
index 224bc010bf7..e658d6188e8 100644
--- a/Code/Mantid/Build/Tests/Mantid.properties
+++ b/Code/Mantid/Build/Tests/Mantid.properties
@@ -33,6 +33,10 @@ datasearch.directories = ../../../../Test/Data
 # Default save directory
 defaultsave.directory = .
 
+# ICat downlaod directory
+icatDownload.directory = .
+
+
 # Uncommenting the line below will lead to all 2D workspaces being of the ManagedWorkspace2D variety
 #ManagedWorkspace.LowerMemoryLimit = 0
 ManagedWorkspace.LowerMemoryLimit = 80
diff --git a/Code/Mantid/DataObjects/inc/MantidDataObjects/TableWorkspace.h b/Code/Mantid/DataObjects/inc/MantidDataObjects/TableWorkspace.h
index b7d66074797..4e638c57cd1 100644
--- a/Code/Mantid/DataObjects/inc/MantidDataObjects/TableWorkspace.h
+++ b/Code/Mantid/DataObjects/inc/MantidDataObjects/TableWorkspace.h
@@ -195,7 +195,7 @@ private:
 			}
 			else
 			{
-				row=-1;
+				throw std::out_of_range("Search object not found in table workspace");
 			 }
 		}
 		catch(std::range_error&)
@@ -264,35 +264,6 @@ private:
     }
 
 
-    /// template method to find a given value in a table.
-    //template<typename  Type>
-    //void findValue(const Type value,int& row,int & col)
-    //{
-    //  int total_columns=columnCount();
-    //  for (int count=0;count<total_columns;++count)
-    //  {
-    //    TableColumn_ptr<Type> tc_sptr= getColumn(count);
-    //    std::vector<Type> dataVec=tc_sptr->data();
-    //    typename std::vector<Type>::iterator itr;
-    //    itr=std::find(dataVec.begin(),dataVec.end(),value);
-    //    if(itr!=dataVec.end())
-    //    {
-    //      std::vector<int>::difference_type pos;
-    //      pos=std::distance(dataVec.begin(),itr);
-    //      //int pos=static_cast<int>itr-dataVec.begin();
-    //      row=static_cast<int>(pos);
-    //      col=count;
-    //      break;
-    //    }
-    //    else
-    //    {
-    //      row=-1;
-    //      col=-1;
-    //    }
-    //  }
-
-    //}
-
 private:
     /// Used in std::find_if algorithm to find a Column with name \a name.
     class FindName
diff --git a/Code/Mantid/ICat/ICat.vcproj b/Code/Mantid/ICat/ICat.vcproj
index 68ab8fc2d41..97e0a129b79 100644
--- a/Code/Mantid/ICat/ICat.vcproj
+++ b/Code/Mantid/ICat/ICat.vcproj
@@ -190,6 +190,10 @@
 				RelativePath=".\src\FileList.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\src\GetDataSets.cpp"
+				>
+			</File>
 			<File
 				RelativePath=".\src\GetInvestigation.cpp"
 				>
diff --git a/Code/Mantid/ICat/inc/MantidICat/DownloadDataFile.h b/Code/Mantid/ICat/inc/MantidICat/DownloadDataFile.h
index 9f28dc04157..37a501fb8dc 100644
--- a/Code/Mantid/ICat/inc/MantidICat/DownloadDataFile.h
+++ b/Code/Mantid/ICat/inc/MantidICat/DownloadDataFile.h
@@ -5,6 +5,34 @@
 #include "MantidDataObjects/Workspace2D.h"
 #include "MantidICat/GSoapGenerated/soapICATPortBindingProxy.h"
 
+/** CDownloadDataFile class is responsible for GetDataFile algorithms.
+  * This algorithm  gets the location string for a given file from ISIS archive file using ICat API.
+  * If the file is not able to open from isis archive,it will call another ICat api to get the URL for the file.
+  * Then uses POCO http methods to download over internet.
+       
+    @author Sofia Antony, STFC Rutherford Appleton Laboratory
+    @date 07/07/2010
+    Copyright &copy; 2010 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    
+*/
 namespace Mantid
 {
 	namespace ICat
@@ -12,33 +40,58 @@ namespace Mantid
 		class DLLExport CDownloadDataFile: public API::Algorithm
 		{
 		public:
+			/// Constructor
 			CDownloadDataFile():API::Algorithm(){}
+			/// Destructor
 			~CDownloadDataFile(){}
 			/// Algorithm's name for identification overriding a virtual method
-			virtual const std::string name() const { return "DownloadDataFile"; }
+			virtual const std::string name() const { return "GetDataFile"; }
 			/// Algorithm's version for identification overriding a virtual method
 			virtual const int version() const { return 1; }
 			/// Algorithm's category for identification overriding a virtual method
 			virtual const std::string category() const { return "ICat"; }
+			
+		   /** This method is used for unit testing purpose.
+			 * as the Poco::Net library httpget throws an exception when the nd server n/w is slow 
+			 * I'm testing the download from mantid server.
+			 * as the downlaod method I've written is private I can't access that in unit testing.
+			 * so adding this public method to call the private downlaod method and testing.
+			*/
+			void testDownload(const std::string& URL,const std::string& fileName);
 
 		private:
 			/// Overwrites Algorithm method.
 			void init();
 			/// Overwrites Algorithm method
 			void exec();
-			/// login method
+			/// get location of data file  or download method
 			int doDownload( ICATPortBindingProxy & icat);
-			///
+			/// Setting the request parameters for getDataFile API
 			void setRequestParameters(const std::string fileName,API::ITableWorkspace_sptr ws_sptr,ns1__getDatafile& request);
-			///
+
+			/// Setting the request parameters for downloaddatafile api
 			void setRequestParameters(const std::string fileName,API::ITableWorkspace_sptr ws_sptr,ns1__downloadDatafile& request);
-			///
-			void getFileListtoDownLoad(const std::string & fileName,API::ITableWorkspace_sptr ws_sptr,
+
+			/// This method gives all the log files associated with the row file to download
+			void getFileListtoDownLoad(const std::string & fileName,const API::ITableWorkspace_sptr& ws_sptr,
 				                       std::vector<std::string>& downLoadList);
+
+			/// This method is used when the download is done over internet
 			void downloadFileOverInternet(ICATPortBindingProxy &icat,const std::vector<std::string>& fileList,API::ITableWorkspace_sptr ws_ptr);
-			///
-			boost::shared_ptr<std::string> m_sessionId_sptr;
-			boost::shared_ptr<LONG64> m_fileId_sptr;
+
+			///This method gives the run number associated to the file
+			void getRunNumberfromFileName(const std::string& fileName, std::string& runNumber);
+
+			/// If the extn of the file .raw it returns true
+			bool isBinaryFile(const std::string & fileName);
+
+			/// This method saves the downloaded file to disc
+			void saveFiletoDisk(std::istream& rs,const std::string &fileName);
+
+			/// This method saves downloaded file to local disk
+			void doDownloadandSavetoLocalDrive(const std::string& URL,const std::string& fileName);
+
+		   
 
 		};
 
diff --git a/Code/Mantid/ICat/inc/MantidICat/FileList.h b/Code/Mantid/ICat/inc/MantidICat/FileList.h
index c6c30a00a66..259ca5af345 100644
--- a/Code/Mantid/ICat/inc/MantidICat/FileList.h
+++ b/Code/Mantid/ICat/inc/MantidICat/FileList.h
@@ -11,7 +11,10 @@ namespace Mantid
 		class DLLExport CFileList:public API::Algorithm
 		{
 		public:
+
+			///conctructor
 			CFileList():API::Algorithm(){}
+			/// Destructor
 			~CFileList(){}
 
 		    /// Algorithm's name for identification overriding a virtual method
@@ -26,7 +29,7 @@ namespace Mantid
 			void init();
 			/// Overwrites Algorithm method
 			void exec();
-			///
+			/// search for files
 			API::ITableWorkspace_sptr doFileSearch();
 
 
diff --git a/Code/Mantid/ICat/inc/MantidICat/GetInvestigation.h b/Code/Mantid/ICat/inc/MantidICat/GetInvestigation.h
index b3256c4f152..2cfa4243a3c 100644
--- a/Code/Mantid/ICat/inc/MantidICat/GetInvestigation.h
+++ b/Code/Mantid/ICat/inc/MantidICat/GetInvestigation.h
@@ -1,18 +1,54 @@
-#ifndef MANTID_ICAT_GETINVESTIGATION_H
-#define MANTID_ICAT_GETINVESTIGATION_H
-
+#ifndef MANTID_ICAT_GETINVESTIGATION_H_
+#define MANTID_ICAT_GETINVESTIGATION_H_
 
 #include "MantidAPI/Algorithm.h"
 #include "MantidDataObjects/TableWorkspace.h"
+
+/** CGetDataFiles is a class responsible for GetInvestigation algorithm.
+  * This algorithm does the basic search and returns the investigations record
+
+    Required Properties:
+    <UL>
+    <LI> InvestigationId - The id of the investigation to display</LI>
+    <LI> InputWorkspace -  Input workspace which saved last search</LI>
+	<LI> OutputWorkspace - The putput workspace to store  </LI>
+    </UL>
+   
+    @author Sofia Antony, STFC Rutherford Appleton Laboratory
+    @date 07/07/2010
+    Copyright &copy; 2010 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    
+	*/	
 namespace Mantid
 {
 	namespace ICat
 	{
-		class DLLExport CGetInvestigation:public API::Algorithm
+		class DLLExport CGetDataFiles:public API::Algorithm
 		{
 		public:
-			CGetInvestigation():API::Algorithm(){}
-			~CGetInvestigation(){}
+
+			/// Constructor
+			CGetDataFiles():API::Algorithm(){}
+			/// Destructor
+			~CGetDataFiles(){}
 
 		    /// Algorithm's name for identification overriding a virtual method
 			virtual const std::string name() const { return "GetInvestigation"; }
@@ -26,8 +62,8 @@ namespace Mantid
 			void init();
 			/// Overwrites Algorithm method
 			void exec();
-			///
-			API::ITableWorkspace_sptr doInvestigationSearch();
+			/// do datafile search
+			API::ITableWorkspace_sptr doDataFilesSearch();
 
 
 		};
diff --git a/Code/Mantid/ICat/inc/MantidICat/Login.h b/Code/Mantid/ICat/inc/MantidICat/Login.h
index e2f93d7cf62..41e84814b77 100644
--- a/Code/Mantid/ICat/inc/MantidICat/Login.h
+++ b/Code/Mantid/ICat/inc/MantidICat/Login.h
@@ -1,10 +1,41 @@
-#ifndef MANTID_ICAT_LOGIN_H
-#define MANTID_ICAT_LOGIN_H
-
+#ifndef MANTID_ICAT_LOGIN_H_
+#define MANTID_ICAT_LOGIN_H_
 
 #include "MantidAPI/Algorithm.h"
 #include "MantidICat/GSoapGenerated/soapICATPortBindingProxy.h"
 
+
+/**  Login class for logging into ICat DB .This class written as a Mantid algorithm. 
+     This class uses Gsoap generated ProxyObject to connect to ICat and uses Login API .
+	 
+	Required Properties:
+    <UL>
+    <LI> Username - The logged in user name </LI>
+    <LI> Password - The password of the logged in user </LI>
+    </UL>
+   
+    @author Sofia Antony, STFC Rutherford Appleton Laboratory
+    @date 07/07/2010
+    Copyright &copy; 2010 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    */	
 namespace Mantid
 {
 	namespace ICat
@@ -13,8 +44,9 @@ namespace Mantid
 		class DLLExport Login: public API::Algorithm
 		{
 		public:
-			/// 
+			/// constructor
 			Login():API::Algorithm(){}
+			/// Destructor
 			~Login(){}
 			/// Algorithm's name for identification overriding a virtual method
 			virtual const std::string name() const { return "Login"; }
diff --git a/Code/Mantid/ICat/inc/MantidICat/SearchByRunNumber.h b/Code/Mantid/ICat/inc/MantidICat/SearchByRunNumber.h
index d5ab8eb134d..e886626fee4 100644
--- a/Code/Mantid/ICat/inc/MantidICat/SearchByRunNumber.h
+++ b/Code/Mantid/ICat/inc/MantidICat/SearchByRunNumber.h
@@ -1,8 +1,45 @@
-#ifndef MANTID_ICAT_CSEARCHBYRUNNUMBER_H
-#define MANTID_ICAT_CSEARCHBYRUNNUMBER_H
+#ifndef MANTID_ICAT_CSEARCHBYRUNNUMBER_H_
+#define MANTID_ICAT_CSEARCHBYRUNNUMBER_H_
 
 #include "MantidAPI/Algorithm.h"
 #include "MantidDataObjects/TableWorkspace.h"
+
+
+/** CSearchByRunNumber is a class responsible for SearchByRunNumber algorithm.
+  * This algorithm does the basic search and returns the investigations record
+
+    Required Properties:
+    <UL>
+    <LI> StartRun - The the start run number for search </LI>
+    <LI> EndRun - The end run number for search </LI>
+	<LI> Instruments - The list of instruments used for search </LI>
+    </UL>
+   
+    @author Sofia Antony, STFC Rutherford Appleton Laboratory
+    @date 07/07/2010
+    Copyright &copy; 2010 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    
+	*/	
+
+
 namespace Mantid
 {
 	namespace ICat
@@ -23,12 +60,12 @@ namespace Mantid
 			/// Algorithm's category for identification overriding a virtual method
 			virtual const std::string category() const { return "ICat"; }
 		private:
-			/// Overwrites Algorithm method.
+			/// Overwrites Algorithm init method.
 			void init();
-			/// Overwrites Algorithm method
+			/// Overwrites Algorithm exec method
 			void exec();
 			
-			/// search method 
+			/// Search method 
 			API::ITableWorkspace_sptr  doSearchByRunNumber();
 
 									
diff --git a/Code/Mantid/ICat/inc/MantidICat/SearchHelper.h b/Code/Mantid/ICat/inc/MantidICat/SearchHelper.h
index ec029b919d4..86be8528b69 100644
--- a/Code/Mantid/ICat/inc/MantidICat/SearchHelper.h
+++ b/Code/Mantid/ICat/inc/MantidICat/SearchHelper.h
@@ -1,10 +1,36 @@
-#ifndef MANTID_ICAT_SEARCHHELPER_H
-#define MANTID_ICAT_SEARCHHELPER_H
+#ifndef MANTID_ICAT_SEARCHHELPER_H_
+#define MANTID_ICAT_SEARCHHELPER_H_
 
 #include "MantidAPI/Algorithm.h"
 #include "MantidICat/GSoapGenerated/soapICATPortBindingProxy.h"
 #include "MantidDataObjects/TableWorkspace.h"
 #include "MantidAPI/TableRow.h"
+
+/**  CSearchHelper is a utility class used in Mantid-ICat algorithms to do ICat searching.
+     
+    @author Sofia Antony, STFC Rutherford Appleton Laboratory
+    @date 07/07/2010
+    Copyright &copy; 2010 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    */	
+
 namespace Mantid
 {
 	namespace ICat
@@ -12,42 +38,47 @@ namespace Mantid
 		class DLLExport CSearchHelper
 		{
 		public:
+			/// constructor
 			CSearchHelper(){}
+			/// destructor
 			~CSearchHelper(){}
 			
 			/// search method
 			int doSearch(ICATPortBindingProxy& icat,boost::shared_ptr<ns1__searchByAdvanced>& request,ns1__searchByAdvancedResponse& response);
-			int dotest(ICATPortBindingProxy& icat,ns1__searchByAdvanced* request,ns1__searchByAdvancedResponse& response);
-			///
-			int doSearchByRunNumber(const double& dstartRun,const double& dendRun,ns1__investigationInclude einclude,
+			
+			/// method to search by run number
+			int doSearchByRunNumber(const double& dstartRun,const double& dendRun,const std::string& instrName,ns1__investigationInclude einclude,
 				API::ITableWorkspace_sptr& responsews_sptr);
 
-			///
-			int dogetInvestigationIncludes(long long invId,ns1__investigationInclude inclide,API::ITableWorkspace_sptr& responsews_sptr);
+			/// calls getInvestigationIncludes api's
+			int getDataFiles(long long invId,ns1__investigationInclude inclide,API::ITableWorkspace_sptr& responsews_sptr);
+
+			/// this method calls Icat api getInvestigationIncludes and returns datasets for the given investigation id.
+			int doDataSetsSearch(long long invId,ns1__investigationInclude inclide,API::ITableWorkspace_sptr& responsews_sptr);
+
 		private:
-		
-			/// this method sets the request parametrs for serch by runnumber
-			void setRequestParameters(const double& dstart,const double& dend,ns1__investigationInclude einclude,
-				 ns1__searchByAdvanced& request);
+					
 
-			/// this method saves the response data to table workspace.
-			API::ITableWorkspace_sptr saveResponseDatatoTableWorkspace(ns1__investigationInclude einclude,const ns1__searchByAdvancedResponse& response);
+			/// This method sets the request parameters for investigation includes.
+			void setReqParamforInvestigationIncludes(long long invstId,ns1__investigationInclude include,ns1__getInvestigationIncludes& request);
 
-			///
+			/// set request param for investigation includes
+			void setReqParamforSearchByRunNumber(const double& dstart,const double& dend,ns1__investigationInclude einclude,
+				boost::shared_ptr<ns1__searchByAdvanced>& request);
+	
+
+			///This method saves the file search response to table workspace
 			API::ITableWorkspace_sptr saveFileSearchResponse(const ns1__searchByAdvancedResponse& response);
 
-			///
+			/// This method saves the response data of search by run number to table workspace
 			API::ITableWorkspace_sptr saveSearchByRunNumberResponse(const ns1__searchByAdvancedResponse& response);
 
-			///
-			void setReqParamforInvestigationIncludes(long long invstId,ns1__investigationInclude include,ns1__getInvestigationIncludes& request);
-			///
-			void setReqParamforSearchByRunNumber(const double& dstart,const double& dend,ns1__investigationInclude einclude,
-			                boost::shared_ptr<ns1__searchByAdvanced>& request);
-
-			///
+			/// this method saves investigation include response to a table workspace
 			API::ITableWorkspace_sptr saveInvestigationIncludesResponse(const ns1__getInvestigationIncludesResponse& response);
 
+			/// this method saves Datasets to a table workspace
+			API::ITableWorkspace_sptr saveDataSets(const ns1__getInvestigationIncludesResponse& response);
+
 
 			/* This is a template method to save data to table workspace
 			 * @param input pointer to input value
@@ -66,13 +97,7 @@ namespace Mantid
 					t<<"";
 				}
 			}
-			boost::shared_ptr<std::string> m_sessionId_sptr;
-			boost::shared_ptr<std::string> m_visitId_sptr;
-			boost::shared_ptr< ns1__investigationInclude> m_invstInculde_sptr;
-            boost::shared_ptr<double>m_runStart_sptr;
-			boost::shared_ptr<double>m_runEnd_sptr;
-			boost::shared_ptr<ns1__advancedSearchDetails>m_advanceDetails_sptr;
-			boost::shared_ptr<long long>m_invstId;
+			
 		};
 	}
 }
diff --git a/Code/Mantid/ICat/inc/MantidICat/Session.h b/Code/Mantid/ICat/inc/MantidICat/Session.h
index e7297eee683..cacb59e84ec 100644
--- a/Code/Mantid/ICat/inc/MantidICat/Session.h
+++ b/Code/Mantid/ICat/inc/MantidICat/Session.h
@@ -1,9 +1,35 @@
-#ifndef MANTID_ICAT_SESSION_H
-#define MANTID_ICAT_SESSION_H
+#ifndef MANTID_ICAT_SESSION_H_
+#define MANTID_ICAT_SESSION_H_
 
 #include "MantidKernel/SingletonHolder.h"
 #include "MantidICat/ICatExport.h"
 #include "MantidICat/GSoapGenerated/soapICATPortBindingProxy.h"
+
+/**  SessionImpl is a singleton class responsible for saving the session id. 
+     This class is used across all Mantid-ICat algorithms to get the session id 
+		
+    @author Sofia Antony, STFC Rutherford Appleton Laboratory
+    @date 07/07/2010
+    Copyright &copy; 2010 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    */	
 namespace Mantid
 {
 	namespace ICat
@@ -12,12 +38,21 @@ namespace Mantid
 		{
 		public:
 
+            ///get sessionId
 			const std::string& getSessionId()const{return m_sessionId;}
+			/// set session id
 			void setSessionId(const std::string& sessionId){m_sessionId=sessionId;}
-
+			/// get user name
+			const std::string & getUserName()const{return m_userName;}
+			///set username
+			void setUserName(const std::string& userName){m_userName=userName;}
+			
 		private:
+			/// used to craete singleton
 			friend struct Mantid::Kernel::CreateUsingNew<SessionImpl>;
+			/// private constructor for singleton
 			SessionImpl(){}
+			/// private destructor
 			virtual ~SessionImpl(){}
 			///private  copy constructor
 			SessionImpl(const SessionImpl&);
@@ -25,9 +60,9 @@ namespace Mantid
 			SessionImpl operator = (const SessionImpl&);
 			/// string to cache session id
 			std::string m_sessionId;
+			/// user name 
+			std::string m_userName;
 
-			///
-			ICATPortBindingProxy m_icat;
 
 		};
 #ifdef _WIN32
diff --git a/Code/Mantid/ICat/src/DownloadDataFile.cpp b/Code/Mantid/ICat/src/DownloadDataFile.cpp
index be40c47951a..e0e39b0f306 100644
--- a/Code/Mantid/ICat/src/DownloadDataFile.cpp
+++ b/Code/Mantid/ICat/src/DownloadDataFile.cpp
@@ -3,6 +3,8 @@
 #include "MantidKernel/PropertyWithValue.h"
 #include "MantidKernel/BoundedValidator.h"
 #include "MantidAPI/WorkspaceProperty.h"
+#include "MantidKernel/ConfigService.h"
+#include "MantidICat/ErrorHandling.h" 
 
 #include "Poco/Net/HTTPClientSession.h"
 #include "Poco/Net/HTTPRequest.h"
@@ -12,8 +14,7 @@
 #include "Poco/URI.h"
 #include <fstream>
 #include <iomanip>
-//
-//
+
 using Poco::Net::HTTPClientSession;
 using Poco::Net::HTTPRequest;
 using Poco::Net::HTTPResponse;
@@ -30,20 +31,26 @@ namespace Mantid
 		using namespace Kernel;
 		using namespace API;
 
-        DECLARE_ALGORITHM(CDownloadDataFile)
+		DECLARE_ALGORITHM(CDownloadDataFile)
 
+		/// declaring algorithm properties 
 		void CDownloadDataFile::init()
 		{
 			declareProperty("Filename","","Name of the file to download");
 			declareProperty(new WorkspaceProperty<API::ITableWorkspace> ("InputWorkspace","",Direction::Input),
-				"The name of the workspace which stored the last icat file search result");
-
+				"The name of the workspace which stored the last icat search result");
 		}
+		/// Execute the algorithm
 		void CDownloadDataFile::exec()
 		{
 			ICATPortBindingProxy icat;
 			int ret=doDownload(icat);
 		}
+
+	  /**This method gets the location string for the selected file from isis archive using Icat api.
+		* If the location string is not avalable,It calls another api to down load the file over internet.
+		* @param icat - reference to icatproxy object
+		*/
 		int CDownloadDataFile::doDownload(ICATPortBindingProxy &icat)
 		{
 			if (soap_ssl_client_context(&icat,
@@ -56,219 +63,188 @@ namespace Mantid
 							NULL      /* if randfile!=NULL: use a file with random data to seed randomness */
 							))
 			{
-				icat.soap_stream_fault(std::cerr);
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
 
 			}
 			//get file name
 			std::string inputfile=getPropertyValue("Filename");
 			//get input workspace
 			API::ITableWorkspace_sptr ws_sptr=getProperty("InputWorkspace");
-            ns1__getDatafile request;
+
+			//boolean flag used to identify the file opening permission from isis archive
+			bool isis_archive=true;
+
+			ns1__getDatafile request;
+
+			boost::shared_ptr<std::string >sessionId_sptr(new std::string);
+			request.sessionId=sessionId_sptr.get();
+
+			boost::shared_ptr<long long >fileId_sptr(new long long );
+			request.datafileId=fileId_sptr.get();
+
 			setRequestParameters(inputfile,ws_sptr,request);
+
 			ns1__getDatafileResponse response;
-			bool isis_archive=false;
+
 			int ret=icat.getDatafile(&request,&response);
 			if(ret==0)
 			{
 				if(response.return_->location)
 				{
 					std::string fileloc=*response.return_->location;
-					std::cout<<"Filelocation is "<<fileloc<<std::endl;
+					//std::cout<<"file location is "<<fileloc<<std::endl;
 
 					// the file location string contains some extra at the beggining of the string.
 					//removing the extra string "file://" from the file location string.
 					std::basic_string<char>::size_type index=fileloc.find_first_of("f");
 					const std::basic_string <char>::size_type npos = -1;
 					if(index!=npos)
-				    {
-					 fileloc.erase(index,7);
-				    }
+					{
+						fileloc.erase(index,7);
+					}
 					//if we are able to open the file from the location returned by the file location
+					//the user got the permission to acess isis archive
 					std::ifstream isisfile(fileloc.c_str());
 					if(!isisfile)
-				   {
+					{
 						isis_archive=false;
-				    }
+					}
 					else
-				    {
+					{
 						//
-						//need to call loadraw
-				    }
+						//if(isRawFile(fileName))
+						//{
+      //                    //need to call loadraw
+						//}
+						//else if (isNexusFile(fileName))
+						//{
+						//	//need to call load nexus.
+						//}
+
+					}
 
 				}
+				else
+				{
+					isis_archive=false;
+				}
 			}
 			else
 			{
-				icat.soap_stream_fault(std::cerr);
+				//icat.soap_stream_fault(std::cerr);
+				isis_archive=false;
 			}
 			if(!isis_archive)
 			{
-
-				std::string filepath="C:\\Mantid\\Code\\Mantid\\ICat\\test\\";
 				std::vector<std::string> fileList;
-				fileList.push_back(inputfile);
-                //get the name of all log files associated with raw file to down load
-				getFileListtoDownLoad(inputfile,ws_sptr,fileList);
-
-				//std::vector<std::string>::const_iterator citr;
-				//for(citr=fileList.begin();citr!=fileList.end();++citr)
-				//{
-				//	//call Icat API download data file.
-				//	ns1__downloadDatafile request;
-				//	//set request parameters
-				//	setRequestParameters(*citr,ws_sptr,request);
-				//	ns1__downloadDatafileResponse response;
-				//	std::string URL;
-				//	// download data file.
-				//	ret=icat.downloadDatafile(&request,&response);
-				//	if(ret==0)
-				//	{
-				//		if(response.URL)
-				//		{
-				//			URL=*response.URL;
-				//		}
-				//		//std::cout<<"URL is "<<URL<<std::endl;
-				//	}
-		  //		   //use HTTP  Get method to download the data file from the server to local machine
-				//	try
-				//	{
-				//		URI uri(URL);
-				//		std::string path(uri.getPathAndQuery());
-				//		if (path.empty()) path = "/";
-
-				//		HTTPClientSession session(uri.getHost(), uri.getPort());
-				//		HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
-				//		session.sendRequest(req);
-				//		HTTPResponse res;
-				//		clock_t start=clock();
-				//		std::istream& rs = session.receiveResponse(res);
-				//		clock_t end=clock();
-				//		float diff = float(end -start)/CLOCKS_PER_SEC;
-				//		std::cout<< "Time taken  for http download over internet is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
-
-				//		filepath+=*citr;
-				//		std::ofstream ofs( filepath.c_str(), std::ios_base::out );
-				//		if ( ofs.rdstate() & std::ios::failbit )
-				//		{
-				//			std::cout<<"Could not open file"<<std::endl;
-				//			return 0;
-				//		}
-				//		StreamCopier::copyStream(rs, ofs);
-				//		filepath.clear();
-				//	}
-				//	catch(Poco::Exception& )
-				//	{
-				//		throw;
-				//	}
-				//}//end of for loop for download file list iteration
+				//fileList.push_back(inputfile);
+				std::string runNumber;
+				getRunNumberfromFileName(inputfile,runNumber);
+				//get the name of all files associated with raw file to download
+				getFileListtoDownLoad(runNumber,ws_sptr,fileList);
+				//download the files from the server to the machine where mantid is installed
 				downloadFileOverInternet(icat,fileList,ws_sptr);
 			}
 			return ret;
 
 		}
+		/* This method calls ICat API downloadDatafile and gets the URL string and uses the URL to down load file server
+		 * @param icat -Icat proxy object
+		 * @param fileList - vector containing list of files to download.
+		*/
 		void CDownloadDataFile::downloadFileOverInternet(ICATPortBindingProxy &icat,const std::vector<std::string>& fileList,
-			                    API::ITableWorkspace_sptr ws_sptr)
-		{
-			    std::string filepath="C:\\Mantid\\Code\\Mantid\\ICat\\test\\";
+			API::ITableWorkspace_sptr ws_sptr)
+		{						
+			std::vector<std::string>::const_iterator citr;
+			for(citr=fileList.begin();citr!=fileList.end();++citr)
+			{
+				//call Icat API download data file.
+				ns1__downloadDatafile request;
+
+				boost::shared_ptr<std::string >sessionId_sptr(new std::string);
+				request.sessionId=sessionId_sptr.get();
+
+				boost::shared_ptr<long long >fileId_sptr(new long long );
+				request.datafileId=fileId_sptr.get();
 
-				std::vector<std::string>::const_iterator citr;
-				for(citr=fileList.begin();citr!=fileList.end();++citr)
+				//set request parameters
+				setRequestParameters(*citr,ws_sptr,request);
+
+				ns1__downloadDatafileResponse response;
+				std::string URL;
+				// get the URL using ICAT API
+				int ret=icat.downloadDatafile(&request,&response);
+				if(ret!=0)
 				{
-					//call Icat API download data file.
-					ns1__downloadDatafile request;
-					//set request parameters
-					setRequestParameters(*citr,ws_sptr,request);
-					ns1__downloadDatafileResponse response;
-					std::string URL;
-					// download data file.
-					int ret=icat.downloadDatafile(&request,&response);
-					if(ret==0)
-					{
-						if(response.URL)
-						{
-							URL=*response.URL;
-						}
-						//std::cout<<"URL is "<<URL<<std::endl;
-					}
-		  		   //use HTTP  Get method to download the data file from the server to local machine
-					try
-					{
-						URI uri(URL);
-						std::string path(uri.getPathAndQuery());
-						if (path.empty()) path = "/";
-
-						HTTPClientSession session(uri.getHost(), uri.getPort());
-						HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
-						session.sendRequest(req);
-						HTTPResponse res;
-						clock_t start=clock();
-						std::istream& rs = session.receiveResponse(res);
-						clock_t end=clock();
-						float diff = float(end -start)/CLOCKS_PER_SEC;
-						std::cout<< "Time taken  for http download over internet is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
-
-						filepath+=*citr;
-						std::ofstream ofs( filepath.c_str(), std::ios_base::out );
-						if ( ofs.rdstate() & std::ios::failbit )
-						{
-							std::cout<<"Could not open file"<<std::endl;
-							return ;
-						}
-						StreamCopier::copyStream(rs, ofs);
-						filepath.clear();
-					}
-					catch(Poco::Exception& )
-					{
-						throw;
-					}
-				}//end of for loop for download fuile list iteration
+					CErrorHandling::throwErrorMessages(icat);
+				}
+				
+				if(response.URL)
+				{
+					URL=*response.URL;
+				}
 
-		}
+				//download using Poco HttpClient session and save to local disk
+				doDownloadandSavetoLocalDrive(URL,*citr);
+			}//end of for loop for download file list iteration
 
-		/* *This method sets the request parameters for the downloadDatafile api
-		   *This method takes filename and table workspace as input and do a look up for
-		   *filename in the table  and gets the corresponding file id for the filename.
-		   *The file id is the request parameter for the downloadDatafile api.
-		   *@param fileName name of teh file to download
-		   *@param ws_sptr shared workspace pointer
-		   *@param request input request object
+		}
 
+	/*  * This method sets the request parameters for the downloadDatafile api
+		* This method takes filename and table workspace as input and do a look up for
+		* filename in the table  and gets the corresponding file id for the filename.
+		* The file id is the request parameter for the downloadDatafile api.
+		* @param fileName name of the file to download
+		* @param ws_sptr shared workspace pointer
+		* @param request input request object
 		*/
-		void CDownloadDataFile::setRequestParameters(const std::string fileName,API::ITableWorkspace_sptr ws_sptr,ns1__getDatafile& request)
-		{
-			//std::string fileName=getProperty("Filename");
-			//API::ITableWorkspace_sptr ws_sptr=getProperty("InputWorkspace");
+		void CDownloadDataFile::setRequestParameters(const std::string fileName,API::ITableWorkspace_sptr ws_sptr,
+			ns1__getDatafile& request)
+		{			
 			//write code to look up this filename in the table workspace
-			int row=0;const int col=1;
+			int row=0;const int col=2;
 			long long fileId=0;
 			try
 			{
-			ws_sptr->find(fileName,row,col);
-			fileId=ws_sptr->cell<long long >(row,col+2);
+				//i think find is not required now.
+				ws_sptr->find(fileName,row,col);
+				fileId=ws_sptr->cell<long long >(row,col+2);
 			}
 			catch(std::range_error&)
 			{
 				throw;
 			}
+			catch(std::out_of_range&)
+			{
+				throw;
+			}
 			catch(std::runtime_error&)
 			{
 				throw;
 			}
 
 			//get the sessionid which is cached in session class during login
-			m_sessionId_sptr=boost::shared_ptr<std::string >(new std::string);
-			*m_sessionId_sptr=Session::Instance().getSessionId();
-			request.sessionId=m_sessionId_sptr.get();
-			//m_fileId_sptr=boost::shared_ptr<LONG64>(new LONG64);
-			*m_fileId_sptr=fileId;
-			request.datafileId=m_fileId_sptr.get();
+			//m_sessionId_sptr=boost::shared_ptr<std::string >(new std::string);
+			//*m_sessionId_sptr=Session::Instance().getSessionId();
+			//m_fileId_sptr=boost::shared_ptr<long long >(new long long );
+			//*m_fileId_sptr=fileId;
+
+			*request.sessionId=Session::Instance().getSessionId();
+			*request.datafileId=fileId;
+			//std::cout<<"data file id is "<<*request.datafileId<<std::endl;
 
 		}
-		void CDownloadDataFile::setRequestParameters(const std::string fileName,API::ITableWorkspace_sptr ws_sptr,ns1__downloadDatafile& request)
-		{
 
-			//look up this filename in the table workspace
-			int row=0;const int col=1;long long fileId=0;
+	  /** This method sets the input request parameters.
+		* @param fileName - name of the file to download
+		* @param ws_sptr - shared pointer to workspace
+		* @param request - request object
+		*/
+		void CDownloadDataFile::setRequestParameters(const std::string fileName,API::ITableWorkspace_sptr ws_sptr,ns1__downloadDatafile& request)
+		{			
+			//look up  filename in the table workspace
+			int row=0;const int col=2;long long fileId=0;
 			ws_sptr->find(fileName,row,col);
 			try
 			{
@@ -278,61 +254,172 @@ namespace Mantid
 			{
 				throw;
 			}
+			catch(std::out_of_range&)
+			{
+				throw;
+			}
 			catch(std::runtime_error&)
 			{
 				throw;
 			}
+			
+			*request.sessionId=Session::Instance().getSessionId();
+			*request.datafileId=fileId;//m_fileId_sptr.get();
 
-			//get the sessionid which is cached in session class during login
-			m_sessionId_sptr=boost::shared_ptr<std::string >(new std::string);
-			*m_sessionId_sptr=Session::Instance().getSessionId();
-			request.sessionId=m_sessionId_sptr.get();
-			//m_fileId_sptr=boost::shared_ptr<long long >(new long long );
-			*m_fileId_sptr=fileId;
-			request.datafileId=m_fileId_sptr.get();
+		}
+
+	   /* This method returns the file names(row file and log file list) to down load from the selected row file name.
+		* @param runNumber - the run number associated to the row file
+		* @param ws_sptr - shared pointer to workspace
+		* @param downLoadList list of files to download
+		*/
+		void CDownloadDataFile::getFileListtoDownLoad(const std::string & runNumber,const API::ITableWorkspace_sptr& ws_sptr,
+			std::vector<std::string>& downLoadList )
+		{	
+
+			const std::basic_string <char>::size_type npos = -1;
+			ColumnVector<std::string> fileNameCol = ws_sptr->getVector("Name");
+			int colSize=fileNameCol.size();
+			for (int i=0;i<colSize;++i)
+			{
+				if(fileNameCol[i].find(runNumber)!=npos)
+				{
+					downLoadList.push_back(fileNameCol[i]);
+				}
+
+			}
 
 		}
-		/* This method returns the file names(row file and log file list) to down load from the selected row file name.
+
+	   /* This method returns the run number associated to a file from teh file name
+		* @param fileName  file name
+		* @param runNumber runnumber 
 		*/
-		void CDownloadDataFile::getFileListtoDownLoad(const std::string & fileName,API::ITableWorkspace_sptr ws_sptr,
-			                    std::vector<std::string>& downLoadList )
+		void CDownloadDataFile::getRunNumberfromFileName(const std::string& fileName, std::string& runNumber)
 		{
-			//std::string fileName=getProperty("Filename");
-			//API::ITableWorkspace_sptr ws_sptr=getProperty("InputWorkspace");
-			//find the run number from row file name.
+			//get  the run number from row file name.
 			std::basic_string <char>::size_type indexDot;
 			const std::basic_string <char>::size_type npos = -1;
-			std::string runNumber;
-			//find the position of . in row file
-			indexDot = fileName.find_last_of ( "." );
+			//find the position of .in row file
+			indexDot = fileName.find_last_of (".");
 			if(indexDot!= npos)
 			{
 				for (int i=0;i<=indexDot-1;++i)
 				{
-				int inteqv=(int)fileName.at(i);
-				if( (inteqv>=65 && inteqv<=90) || (inteqv>=97 && inteqv<=122) )
-				{
-				}
-				else
-				{
-					runNumber+=fileName.at(i);
-				}
+					int intval=(int)fileName.at(i);
+					if( (intval>=65 && intval<=90) || (intval>=97 && intval<=122) )
+					{
+					}
+					else
+					{
+						runNumber+=fileName.at(i);
+					}
 
 				}
 			}
 
-			ColumnVector<std::string> fileNameCol = ws_sptr->getVector("Name");
-			int colSize=fileNameCol.size();
-			for (int i=0;i<colSize;++i)
+		}
+
+	   /* This method checks the file extn and if it's a raw file reurns true
+		* This is useful when the we download a file over internet and save to local drive,
+		* to open the file in binary or ascii mode
+		* @param fileName  file name
+		*/
+		bool CDownloadDataFile::isBinaryFile(const std::string & fileName)
+		{			
+			std::basic_string <char>::size_type dotIndex;
+			const std::basic_string <char>::size_type npos = -1;
+			//find the position of .in row file
+			dotIndex = fileName.find_last_of (".");
+			std::string fextn=fileName.substr(dotIndex+1,fileName.size()-dotIndex);
+
+			bool binary;
+			(!fextn.compare("raw")|| !fextn.compare("RAW")|| !fextn.compare("nxs")) ? binary = true : binary = false;
+			//std::cout<<"file opening mode  for filename "<<fileName<<"is "<<binary<<std::endl;
+			return binary;
+
+		}
+
+	   /* This method downloads file over internet using Poco HTTPClientSession 
+		* @param URL- URL of the file to down load
+		* @param fileName  file name
+		*/
+		void CDownloadDataFile::doDownloadandSavetoLocalDrive(const std::string& URL,const std::string& fileName)
+		{
+			clock_t start;
+			//use HTTP  Get method to download the data file from the server to local disk
+			try
 			{
-				if(fileNameCol[i].find(runNumber)!=npos)
-				{
-					std::cout<<"download list adding file "<<fileNameCol[i]<<std::endl;
-					downLoadList.push_back(fileNameCol[i]);
-				}
+				URI uri(URL);
+				std::string path(uri.getPathAndQuery());
+				if (path.empty()) 
+				{
+					throw std::runtime_error("Invalid Path when downloading the data file");
+				}
+				start=clock();
+
+				HTTPClientSession session(uri.getHost(), uri.getPort());
+				HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
+				session.sendRequest(req);
+				
+				HTTPResponse res;
+				std::istream& rs = session.receiveResponse(res);
+				clock_t end=clock();
+		        float diff = float(end - start)/CLOCKS_PER_SEC;
+				g_log.debug()<<"Time taken to download file "<< fileName<<"is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
+				//save file to local disk
+				saveFiletoDisk(rs,fileName);
 
+			}
+			catch(Poco::SyntaxException& e)
+			{
+				g_log.error()<<e.what()<<std::endl;
+				throw;
+			}
+			catch(Poco::Exception& ex )
+			{			   
+				g_log.error()<<ex.what()<<std::endl;
+				throw;
 			}
 
 		}
+
+	  /** This method saves the input stream to a file
+		* @param rs input stream
+		* @param fileName name of the output file
+		*/
+		void CDownloadDataFile::saveFiletoDisk(std::istream& rs,const std::string& fileName)
+		{
+			
+			std::string filepath = Kernel::ConfigService::Instance().getString("icatDownload.directory");
+			//std::cout<<"ICatDownload path is "<<filepath<<std::endl;
+			filepath += fileName;
+			std::ios_base::openmode mode;
+			//if raw/nexus file open it in binary mode else ascii 
+			isBinaryFile(fileName)? mode = std::ios_base::binary : mode = std::ios_base::out;
+			std::ofstream ofs(filepath.c_str(), mode);
+			if ( ofs.rdstate() & std::ios::failbit )
+			{
+				throw Mantid::Kernel::Exception::FileError("Error on creating File",fileName);
+			}
+			//copy the input stream to a file.
+			StreamCopier::copyStream(rs, ofs);
+		}
+
+	   /* This method is used for unit testing purpose.
+		* as the Poco::Net library httpget throws an exception when the nd server n/w is slow 
+		* I'm testing the download from mantid server.
+		* as the downlaod method I've written is private I can't access that in unit testing.
+		* so adding this public method to call the private downlaod method and testing.
+		* @param URL - URL of the file to download
+		* @param fileName - name of the file
+		*/
+		void CDownloadDataFile::testDownload(const std::string& URL,const std::string& fileName)
+		{
+			doDownloadandSavetoLocalDrive(URL,fileName);
+
+		}
+
+
 	}
 }
diff --git a/Code/Mantid/ICat/src/FileList.cpp b/Code/Mantid/ICat/src/FileList.cpp
index e8b6a7ff770..da7abf29755 100644
--- a/Code/Mantid/ICat/src/FileList.cpp
+++ b/Code/Mantid/ICat/src/FileList.cpp
@@ -11,6 +11,7 @@ namespace Mantid
 	{
 		using namespace Kernel;
 		using namespace API;
+		/// Init method
 		void CFileList::init()
 		{
 			BoundedValidator<double>* mustBePositive = new BoundedValidator<double>();
@@ -21,11 +22,13 @@ namespace Mantid
 			declareProperty(new WorkspaceProperty<API::ITableWorkspace> ("OutputWorkspace", "", Direction::Output),
                             "The name of the workspace to store the icat search result");
 		}
+		/// Exec Method
 		void CFileList::exec()
 		{
 		   API::ITableWorkspace_sptr ws_sptr=doFileSearch();
 			setProperty("OutputWorkspace",ws_sptr);
 		}
+		/// This method does teh file search
 		API::ITableWorkspace_sptr CFileList::doFileSearch()
 		{
 			/*ns1__searchByAdvanced request;
@@ -39,13 +42,13 @@ namespace Mantid
 			
 			API::ITableWorkspace_sptr outputws;
 			CSearchHelper searchobj;	
-			int ret_advsearch=searchobj.doSearchByRunNumber(dstartRun,dendRun,ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES,outputws);
+			//int ret_advsearch=searchobj.doSearchByRunNumber(dstartRun,dendRun,ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES,outputws);
 			//int ret_advsearch=searchobj.doSearchByRunNumber(instrList,dstartRun,dendRun,outputws);
-			if(ret_advsearch!=0)
-			{
+			//if(ret_advsearch!=0)
+			//{
 			  //need to throw proper exception
-				throw ;
-			}
+				//throw ;
+			//}
            	return outputws;
 		}
 		
diff --git a/Code/Mantid/ICat/src/GetInvestigation.cpp b/Code/Mantid/ICat/src/GetInvestigation.cpp
index 3b781e8a0f7..d833e4874ba 100644
--- a/Code/Mantid/ICat/src/GetInvestigation.cpp
+++ b/Code/Mantid/ICat/src/GetInvestigation.cpp
@@ -4,6 +4,7 @@
 #include "MantidKernel/BoundedValidator.h"
 #include "MantidAPI/WorkspaceProperty.h"
 #include "MantidICat/SearchHelper.h"
+#include "MantidICat/ErrorHandling.h" 
 
 namespace Mantid
 {
@@ -11,52 +12,62 @@ namespace Mantid
 	{
 		using namespace Kernel;
 		using namespace API;
-		void CGetInvestigation::init()
+		/// Initialising the algorithm
+		void CGetDataFiles::init()
 		{
+			BoundedValidator<long long>* mustBePositive = new BoundedValidator<long long>();
+			mustBePositive->setLower(0);
+			declareProperty<long long>("InvestigationId",0,mustBePositive,"Id of the selected investigation");
+
 			declareProperty("Title","","The title of the investigation to do data search ");
+
 			declareProperty(new WorkspaceProperty<API::ITableWorkspace> ("InputWorkspace","",Direction::Input),
 				"The name of the workspace which stored the last icat investigation search result");
+
 			declareProperty(new WorkspaceProperty<API::ITableWorkspace> ("OutputWorkspace", "", Direction::Output),
                             "The name of the workspace to store the file data search details");
 		}
-		void CGetInvestigation::exec()
+		//execute the algorithm
+		void CGetDataFiles::exec()
 		{
-		   API::ITableWorkspace_sptr ws_sptr=doInvestigationSearch();
+		   API::ITableWorkspace_sptr ws_sptr=doDataFilesSearch();
 			setProperty("OutputWorkspace",ws_sptr);
 		}
-		API::ITableWorkspace_sptr CGetInvestigation::doInvestigationSearch()
+		/// This method returns a set of data files for a given investigationid
+		API::ITableWorkspace_sptr CGetDataFiles::doDataFilesSearch()
 		{
 			std::string invstTitle=getProperty("Title");
 			//input workspace
 			API::ITableWorkspace_sptr inputws_sptr=getProperty("InputWorkspace");
 
-			int row=0;
-			const int col=2; //need to find a way to get column index in table workspace.
-			long long investigationId=0;
-			try
-			{
-			inputws_sptr->find(invstTitle,row,col);
-			investigationId=inputws_sptr->cell<long long >(row,col-2);
-			}
-			catch(std::range_error&)
-			{
-				throw;
-			}
-			catch(std::runtime_error&)
-			{
-				throw;
-			}
+			//int row=0;
+			//const int col=2; //need to find a way to get column index in table workspace.
+			//long long investigationId=0;
+			//try
+			//{
+			//
+			//inputws_sptr->find(invstTitle,row,col);
+			//investigationId=inputws_sptr->cell<long long >(row,col-2);
+			//}
+			//catch(std::range_error&)
+			//{
+			//	throw;
+			//}
+			//catch(std::out_of_range&)
+			//{
+			//	throw;
+			//}
+			//catch(std::runtime_error&)
+			//{
+			//	throw;
+			//}
+
+			long long investigationId = getProperty("InvestigationId");
 			
 			API::ITableWorkspace_sptr outputws;
 			CSearchHelper searchobj;	
-			int ret_advsearch=searchobj.dogetInvestigationIncludes(investigationId,ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES,outputws);
-			//int ret_advsearch=searchobj.doSearchByRunNumber(instrList,dstartRun,dendRun,outputws);
-			if(ret_advsearch!=0)
-			{
-			  //need to throw proper exception
-				throw ;
-			}
-           	return outputws;
+			int ret_advsearch=searchobj.getDataFiles(investigationId,ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES,outputws);
+			return outputws;
 		}
 		
 		
diff --git a/Code/Mantid/ICat/src/Login.cpp b/Code/Mantid/ICat/src/Login.cpp
index 23f17a96b70..6cde6867550 100644
--- a/Code/Mantid/ICat/src/Login.cpp
+++ b/Code/Mantid/ICat/src/Login.cpp
@@ -1,30 +1,40 @@
 //
-#include"MantidICat/Login.h"
+#include "MantidICat/Login.h"
 #include "MantidICat/GSoap/stdsoap2.h"
 #include "MantidKernel/MandatoryValidator.h"
-#include"MantidICat/Session.h"
+#include "MantidICat/Session.h"
 #include "MantidICat/ICatExport.h"
+#include "MantidICat/ErrorHandling.h"
+#include "MantidKernel/MaskedProperty.h"
 
 namespace Mantid
 {
 	namespace ICat
 	{
+		using namespace Kernel;
 
 		DECLARE_ALGORITHM(Login)
 		
+		/// Init method to declare algorithm properties
 		void Login::init()
 		{
 			declareProperty("Username","", new Kernel::MandatoryValidator<std::string>(),
 				"The name of the logged in user");
-			declareProperty("Password","", new Kernel::MandatoryValidator<std::string>(),
+			declareProperty(new MaskedProperty<std::string>("Password","",new Kernel::MandatoryValidator<std::string>()),
 				"The password of the logged in user ");
-			declareProperty("DBServer","","Parameter that will identify the ICat DB server URL");
+
+			//declareProperty("DBServer","","Parameter that will identify the ICat DB server URL");
 		}
+		/// execute the algorithm
 		void Login::exec()
 		{
 			ICATPortBindingProxy icat;
 			doLogin(icat);
 		}
+
+	   /**This method calls the ICat the login api and connects to DB and returns session id.
+		 *@param icat ICat proxy object
+		*/
 		void Login::doLogin(ICATPortBindingProxy& icat)
 		{
 			std::string username=getProperty("Username");
@@ -41,10 +51,10 @@ namespace Mantid
 							NULL      /* if randfile!=NULL: use a file with random data to seed randomness */ 
 							))
 			{ 
-				icat.soap_stream_fault(std::cerr);
-				return;
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
 			}
-
+			
 			// Login to icat
 			ns1__login login;
 			ns1__loginResponse loginResponse;
@@ -54,24 +64,22 @@ namespace Mantid
 
 			std::string session_id;
 			int query_id = icat.login(&login, &loginResponse);
-
 			if( query_id == 0 )
 			{
-				session_id = *(loginResponse.return_);
+				session_id = *(loginResponse.return_);
+				//save session id
+				ICat::Session::Instance().setSessionId(session_id);
+				//save user name
+				ICat::Session::Instance().setUserName(username);
 			}
 			else
 			{ 
-				icat.soap_stream_fault(std::cerr);
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
 			}
-			//declareProperty("SessionId","","Session id of this client session");
-			//setProperty("SessionId",session_id);
-			ICat::Session::Instance().setSessionId(session_id);
+			
 
-			//m_usermap.
-			//std::map<std::string,std::string> userMap;
-			//typedef std::pair <std::string, std::string> String_Pair;
-			//userMap.insert(String_Pair(username,password));
-						
+									
 		}
 	}
 }
diff --git a/Code/Mantid/ICat/src/SearchByRunNumber.cpp b/Code/Mantid/ICat/src/SearchByRunNumber.cpp
index 092b360315f..f5e08f47b93 100644
--- a/Code/Mantid/ICat/src/SearchByRunNumber.cpp
+++ b/Code/Mantid/ICat/src/SearchByRunNumber.cpp
@@ -20,82 +20,34 @@ namespace Mantid
 			mustBePositive->setLower(0.0);
 			declareProperty("StartRun",0.0,mustBePositive,"The start run number");
 			declareProperty("EndRun",0.0,mustBePositive->clone(),"The end run number");
+			
+			declareProperty("Instruments","",new Kernel::MandatoryValidator<std::string>(),
+				"The list of instruments used in ISIS nuetron scattering experiments");
+
 			declareProperty(new WorkspaceProperty<API::ITableWorkspace> ("OutputWorkspace", "", Direction::Output),
 				"The name of the workspace that will be created to store the search result");
 		}
 		/// Execution method.
 		void CSearchByRunNumber::exec()
-		{
-			
+		{			
 			API::ITableWorkspace_sptr ws_sptr=doSearchByRunNumber();
 			setProperty("OutputWorkspace",ws_sptr);
 		}
 
-		/* This method does search by run number.
+		/* This method does search by run number and instrument name.
 		 * @returns shared pointer to table workspace which stores the data
-		*/
+		 */
 		API::ITableWorkspace_sptr  CSearchByRunNumber::doSearchByRunNumber()
 		{	
 			double dstartRun=getProperty("StartRun");
 			double dendRun=getProperty("EndRun");
-
+			std::string instrument = getPropertyValue("Instruments");
+		
 			API::ITableWorkspace_sptr outputws;
 			CSearchHelper searchobj;
-			//int ret_advsearch=searchobj.doSearchByRunNumber(dstartRun,dendRun,ns1__investigationInclude__INVESTIGATORS_USCOREONLY,outputws);
-			int ret_advsearch=searchobj.doSearchByRunNumber(dstartRun,dendRun,ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES,outputws);
-			
-			//need to handle error properly once i get error details from Tom
-			if(ret_advsearch!=0)
-			{
-				throw;
-			}
+			int ret_advsearch=searchobj.doSearchByRunNumber(dstartRun,dendRun,instrument,ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES,outputws);
 			return outputws;
 		
-		//pagination 
-		//	//ICAt proxy object
-		//	ICATPortBindingProxy icat;
-		//	// Define ssl authentication scheme
-		//	if (soap_ssl_client_context(&icat,
-		//		SOAP_SSL_NO_AUTHENTICATION, /* use SOAP_SSL_DEFAULT in production code */
-		//		NULL,       /* keyfile: required only when client must authenticate to 
-		//					server (see SSL docs on how to obtain this file) */
-		//					NULL,       /* password to read the keyfile */
-		//					NULL,      /* optional cacert file to store trusted certificates */
-		//					NULL,      /* optional capath to directory with trusted certificates */
-		//					NULL      /* if randfile!=NULL: use a file with random data to seed randomness */ 
-		//					))
-		//	{ 
-		//		icat.soap_stream_fault(std::cerr);
-		//		//return -1;
-		//	}
-		//std::string sessionId=Session::Instance().getSessionId();
-		//ns1__searchByAdvancedPagination request;
-		//request.sessionId=&sessionId;
-		//request.startIndex=0;
-		//request.numberOfResults=200;
-
-		//request.advancedSearchDetails=new ns1__advancedSearchDetails;
-		// 
-		//request.advancedSearchDetails->runStart=&dstartRun;
-		//request.advancedSearchDetails->runEnd=&dendRun;
-		//int einclude=ns1__investigationInclude__INVESTIGATORS_USCOREONLY;	
-		//request.advancedSearchDetails->investigationInclude=(ns1__investigationInclude*)&einclude;
-
-		//ns1__searchByAdvancedPaginationResponse response;
-
-		//clock_t start=clock();
-		//int ret_advsearch=icat.searchByAdvancedPagination(&request,&response);
-		//if(ret_advsearch!=0)
-		//{
-		//	std::cout<<"Error in pagination api"<<std::endl;
-		//	throw;
-		//}
-		//clock_t end=clock();
-		//float diff = float(end -start)/CLOCKS_PER_SEC;
-		//std::cout<< "Time taken by dosearch is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
-		//std::cout<<"no of records is "<<response.return_.size();
-			
-
 		}
 
 	
diff --git a/Code/Mantid/ICat/src/SearchHelper.cpp b/Code/Mantid/ICat/src/SearchHelper.cpp
index 7647505a8f7..27a4c828391 100644
--- a/Code/Mantid/ICat/src/SearchHelper.cpp
+++ b/Code/Mantid/ICat/src/SearchHelper.cpp
@@ -3,6 +3,7 @@
 #include "MantidKernel/PropertyWithValue.h"
 #include "MantidKernel/BoundedValidator.h"
 #include "MantidAPI/WorkspaceProperty.h"
+#include "MantidICat/ErrorHandling.h" 
 #include <iomanip>
 
 namespace Mantid
@@ -12,12 +13,11 @@ namespace Mantid
 		using namespace Kernel;
 		using namespace API;
 
-		/* This method calls ICat API searchbydavanced and do the basic search
+		/* This method calls ICat API searchbydavanced and do the basic run search 
 		 * @param icat Proxy object for ICat
 		 * @param request request object
 		 * @param response response object
 		 */
-
 		int CSearchHelper::doSearch(ICATPortBindingProxy& icat,boost::shared_ptr<ns1__searchByAdvanced>& request,ns1__searchByAdvancedResponse& response)
 		{
 			// Define ssl authentication scheme
@@ -31,8 +31,9 @@ namespace Mantid
 							NULL      /* if randfile!=NULL: use a file with random data to seed randomness */
 							))
 			{
-				icat.soap_stream_fault(std::cerr);
-				return -1;
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
+				
 			}
 			//std::cout<<"start run in CSearchHelper do search is "<<*request.advancedSearchDetails->runStart<<std::endl;
 			//std::cout<<"end  run in CSearchHelper do search is "<<*request.advancedSearchDetails->runEnd<<std::endl;
@@ -40,103 +41,71 @@ namespace Mantid
 			int ret_advsearch=icat.searchByAdvanced(request.get(),&response);
 			if(ret_advsearch!=0)
 			{
-				icat.soap_stream_fault(std::cerr);
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
 			}
 			clock_t end=clock();
 			float diff = float(end -start)/CLOCKS_PER_SEC;
-			std::cout<< "Time taken by dosearch is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
-			std::cout<<"CSearchHelper do search no of records is "<<response.return_.size()<<std::endl;
-			return ret_advsearch;
-		}
-		int CSearchHelper::dotest(ICATPortBindingProxy& icat,ns1__searchByAdvanced* request,ns1__searchByAdvancedResponse& response)
-		{
-			if (soap_ssl_client_context(&icat,
-				SOAP_SSL_NO_AUTHENTICATION, /* use SOAP_SSL_DEFAULT in production code */
-				NULL,       /* keyfile: required only when client must authenticate to
-							server (see SSL docs on how to obtain this file) */
-							NULL,       /* password to read the keyfile */
-							NULL,      /* optional cacert file to store trusted certificates */
-							NULL,      /* optional capath to directory with trusted certificates */
-							NULL      /* if randfile!=NULL: use a file with random data to seed randomness */
-							))
-			{
-				icat.soap_stream_fault(std::cerr);
-				return -1;
-			}
-			//std::cout<<"start run in CSearchHelper do search is "<<*request.advancedSearchDetails->runStart<<std::endl;
-			//std::cout<<"end  run in CSearchHelper do search is "<<*request.advancedSearchDetails->runEnd<<std::endl;
-            clock_t start=clock();
-			int ret_advsearch=icat.searchByAdvanced(request,&response);
-			if(ret_advsearch!=0)
-			{
-				icat.soap_stream_fault(std::cerr);
-			}
-			clock_t end=clock();
-			float diff = float(end -start)/CLOCKS_PER_SEC;
-			std::cout<< "Time taken by dosearch is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
-			std::cout<<"CSearchHelper do search no of records is "<<response.return_.size()<<std::endl;
+			//std::cout<< "Time taken by dosearch is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
+			//std::cout<<"CSearchHelper do search no of records is "<<response.return_.size()<<std::endl;
 			return ret_advsearch;
 		}
 
 		/* This method does a search  by run number and returns investigation data
 		 * @param dstartRun start run number
 		 * @param dendRun end run number
+		 * @param instrument name of the instrument
 		 * @param einclude enum to filter the search response
 		 * @param responsews_sptr output table workspace
 		 */
-
-		int CSearchHelper::doSearchByRunNumber(const double& dstartRun,const double& dendRun,ns1__investigationInclude einclude,
+		int CSearchHelper::doSearchByRunNumber(const double& dstartRun,const double& dendRun,const std::string& instrument,ns1__investigationInclude einclude,
 			               API::ITableWorkspace_sptr& responsews_sptr)
 		{
 			//ICAt proxy object
 			ICATPortBindingProxy icat;
 			// request object
-			//ns1__searchByAdvanced request;
 			boost::shared_ptr<ns1__searchByAdvanced> req_sptr(new ns1__searchByAdvanced );
 			boost::shared_ptr<std::string > sessionId_sptr(new std::string);
 			req_sptr->sessionId=sessionId_sptr.get();
 			boost::shared_ptr<ns1__advancedSearchDetails>adv_sptr(new ns1__advancedSearchDetails);
 			req_sptr->advancedSearchDetails=adv_sptr.get();
 			//run start
-			//boost::shared_ptr<double>runstart_sptr(new double);
-		//	req_sptr->advancedSearchDetails->runStart=runstart_sptr.get();
+			boost::shared_ptr<double>runstart_sptr(new double);
+			req_sptr->advancedSearchDetails->runStart=runstart_sptr.get();
 			//run end
-			//boost::shared_ptr<double> runend_sptr(new double);
-			//req_sptr->advancedSearchDetails->runEnd=runend_sptr.get();
-
-			boost::shared_ptr<std::string> dataFilename_sptr(new std::string);
-			req_sptr->advancedSearchDetails->datafileName=dataFilename_sptr.get();
-
+			boost::shared_ptr<double>runend_sptr(new double);
+			req_sptr->advancedSearchDetails->runEnd=runend_sptr.get();
+			
+			//instrument name
+			req_sptr->advancedSearchDetails->instruments.push_back(instrument);
 
 			// investigation include
             boost::shared_ptr<ns1__investigationInclude>invstInculde_sptr(new ns1__investigationInclude);
 			req_sptr->advancedSearchDetails->investigationInclude=invstInculde_sptr.get();
 
 			//setting the input parameters
-			//setRequestParameters(dstartRun,dendRun,einclude,request);
 			setReqParamforSearchByRunNumber(dstartRun,dendRun,einclude,req_sptr);
 
 			//response object
 			ns1__searchByAdvancedResponse response;
 			// do  search
 			int ret_search=doSearch(icat,req_sptr,response);
-			if(ret_search==0)
-			{
-				///save response to a table workspace
-				responsews_sptr=saveResponseDatatoTableWorkspace(einclude,response) ;
-			}
-			else
+			if(ret_search!=0)
 			{
 				//replace with mantid error routine
-				icat.soap_stream_fault(std::cerr);
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
+				
 			}
+			///save response to a table workspace
+			responsews_sptr=saveSearchByRunNumberResponse(response);
 			return ret_search;
 		}
-		/* This method sets the input request parameters for search
+	   /* This method sets the input request parameters for search 
 		* @param dstart start run number
 		* @param dend end run number
 		* @param einclude enum paramter to specify the response records
-		* @request input request object
+		* @request refrence to request object
 		*/
 		void CSearchHelper::setReqParamforSearchByRunNumber(const double& dstart,const double& dend,ns1__investigationInclude einclude,
 			                boost::shared_ptr<ns1__searchByAdvanced>& request)
@@ -145,70 +114,15 @@ namespace Mantid
 			*request->sessionId=Session::Instance().getSessionId();
 			request->advancedSearchDetails->caseSensitive=false;
 			//run start
-		    //*request->advancedSearchDetails->runStart=dstart;
-			//*request->advancedSearchDetails->runEnd=dend;
-			*request->advancedSearchDetails->datafileName="GEM1910*";
-			*request->advancedSearchDetails->investigationInclude=einclude;
-			}
-
-		/* This method sets the input request parameters for search
-		 * @param dstart start run number
-		 * @param dend end run number
-		 * @param einclude enum paramter to specify the response records
-		 * @request input request object
-		 */
-
-		void CSearchHelper::setRequestParameters(const double& dstart,const double& dend,ns1__investigationInclude einclude,
-			                ns1__searchByAdvanced& request)
-		{
-
-			//get the sessionid which is cached in session class during login
-			m_sessionId_sptr=boost::shared_ptr<std::string >(new std::string);
-			*m_sessionId_sptr=Session::Instance().getSessionId();
-			request.sessionId=m_sessionId_sptr.get();
-
-			m_advanceDetails_sptr=boost::shared_ptr<ns1__advancedSearchDetails>(new ns1__advancedSearchDetails);
-			m_advanceDetails_sptr->caseSensitive=false;
-
-			//run start
-			m_runStart_sptr =boost::shared_ptr<double> (new double);
-			*m_runStart_sptr=dstart;
-			m_advanceDetails_sptr->runStart=m_runStart_sptr.get();
-
+		    *request->advancedSearchDetails->runStart=dstart;
 			//run end
-			m_runEnd_sptr=boost::shared_ptr<double>(new double);
-			*m_runEnd_sptr=dend;
-			m_advanceDetails_sptr->runEnd=m_runEnd_sptr.get();
-
-			// enum include
-			m_invstInculde_sptr=boost::shared_ptr<ns1__investigationInclude>(new ns1__investigationInclude);
-			*m_invstInculde_sptr=einclude;
-
-			m_advanceDetails_sptr->investigationInclude=m_invstInculde_sptr.get();
-			request.advancedSearchDetails=m_advanceDetails_sptr.get();
-
-		}
-		/* This method saves the search response data to a table workspace
-		 * @param einclude enum to identfy the search result
-		 *  @param response const reference to response object
-		 *  @returns shared pointer to table workspace which stores the data
-		 */
-		API::ITableWorkspace_sptr CSearchHelper::saveResponseDatatoTableWorkspace(ns1__investigationInclude einclude,
-			                                     const ns1__searchByAdvancedResponse& response)
-		{
-			API::ITableWorkspace_sptr outputws ;
-			if(einclude==ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES)
-			{
-				outputws=saveSearchByRunNumberResponse(response);
+			*request->advancedSearchDetails->runEnd=dend;
+			// investigation include
+			*request->advancedSearchDetails->investigationInclude=einclude;
 			}
-			/*else if(einclude==ns1__investigationInclude__DATASETS_USCOREAND_USCOREDATAFILES)
-			{
-				outputws=saveFileSearchResponse(response);
-			}*/
-			return outputws;
-		}
 
-		/* This method loops through the return_ vector and saves the investigation data to a table workspace
+		
+	   /* This method saves the search response( investigations )data to a table workspace
 		*  @param response const reference to response object
 		*  @returns shared pointer to table workspace which stores the data
 		*/
@@ -238,26 +152,22 @@ namespace Mantid
 				for (citr=response.return_.begin();citr!=response.return_.end();++citr)
 				{
 					API::TableRow t = outputws->appendRow();
-
 					//investigation id
 					savetoTableWorkspace((*citr)->id,t);
+										
 					//rb number
 					savetoTableWorkspace((*citr)->invNumber,t);
-
-					//std::cout<<"search by run number: rb number is : "<<*(*citr)->invNumber<<std::endl;
-
 					//title
 					savetoTableWorkspace((*citr)->title,t);
-
-					//std::cout<<"search by runnumber: title is : "<<*(*citr)->title<<std::endl;
-
-					//type
+                   				
+					//type 
 					savetoTableWorkspace((*citr)->invType,t);
 					savetoTableWorkspace((*citr)->instrument,t);
 					//investigator
 					savetoTableWorkspace((*citr)->bcatInvStr,t);
 					// run range
 					savetoTableWorkspace((*citr)->invParamValue,t);
+								
 					//year
 					if((*citr)->invEndDate!=NULL)
 					{
@@ -278,10 +188,11 @@ namespace Mantid
 
 			return outputws;
 		}
+
 		/* This method loops through the response return_vector and saves the datafile details to a table workspace
 		 * @param response const reference to response object
 		 * @returns shared pointer to table workspace which stores the data
-		*/
+		 */
 		API::ITableWorkspace_sptr CSearchHelper::saveFileSearchResponse(const ns1__searchByAdvancedResponse& response)
 		{
 			//create table workspace
@@ -324,16 +235,10 @@ namespace Mantid
 						{
 
 							API::TableRow t = outputws->appendRow();
-
-							std::string fileName=*(*datafile_citr)->name;
-							//std::cout<<"File name is "<<fileName<<std::endl;
 							savetoTableWorkspace((*datafile_citr)->name,t);
-
-							int fileSize=*(*datafile_citr)->fileSize;
-							//std::cout<<"File size is "<<fileSize<<std::endl;
 							savetoTableWorkspace((*datafile_citr)->fileSize,t);
 
-							long long fileId=*(*datafile_citr)->id;
+							//long long fileId=*(*datafile_citr)->id;
 							//std::cout<<"File id is "<<fileId<<std::endl;
 							savetoTableWorkspace((*datafile_citr)->id,t);
 							ns1__datafileFormat* fileFormat=(*datafile_citr)->datafileFormat;
@@ -341,16 +246,14 @@ namespace Mantid
 							{
 								if(fileFormat->datafileFormatPK)
 								{
-									std::string format=*(fileFormat->datafileFormatPK->name);
+									//std::string format=*(fileFormat->datafileFormatPK->name);
 									//std::cout<<"File format is  "<<format<<std::endl;
 									savetoTableWorkspace((fileFormat->datafileFormatPK->name),t);
 
-									std::string version=*(fileFormat->datafileFormatPK->version);
+									//std::string version=*(fileFormat->datafileFormatPK->version);
 									//std::cout<<"File format version  is "<<version<<std::endl;
 									savetoTableWorkspace((fileFormat->datafileFormatPK->version),t);
 								}
-								std::string formatType=*(fileFormat->formatType);
-								//std::cout<<"File format type  is "<<formatType<<std::endl;
 								savetoTableWorkspace((fileFormat->formatType),t);
 
 							}
@@ -364,10 +267,7 @@ namespace Mantid
 								creationtime->assign(ftime);
 								savetoTableWorkspace(creationtime,t);
 							}
-							//std::cout<<"File creation time  is "<<*creationtime<<std::endl;
-
-
-
+			
 						}
 
 					}
@@ -383,29 +283,29 @@ namespace Mantid
 
 			return outputws;
 		}
+		/* This method sets the request parameters for the investigations includes
+		 * @param invstId - investigation id 
+		 * @param include - enum parameter to retrieve dat from DB
+		 * @param request - request object
+		*/
 		void CSearchHelper::setReqParamforInvestigationIncludes(long long invstId,ns1__investigationInclude include,ns1__getInvestigationIncludes& request)
 		{
 			//get the sessionid which is cached in session class during login
-			// m_sessionId_sptr=boost::shared_ptr<std::string >(new std::string);
-			//*m_sessionId_sptr=Session::Instance().getSessionId();
 			*request.sessionId=Session::Instance().getSessionId();;
-
-			// enum include
-			//*m_invstInculde_sptr=include;
 			*request.investigationInclude=include;
-
-			// m_invstId=boost::shared_ptr<long long>(new long long);
-		     //*m_invstId=invstId;
-			 *request.investigationId=invstId;
-
+  		    *request.investigationId=invstId;
 
 		}
-		int CSearchHelper::dogetInvestigationIncludes(long long invstId,ns1__investigationInclude include,
+		/* *This method calls ICat API getInvestigationIncludes and returns investigation details for a given investigation Id
+		   *@param invstId - investigation id
+		   *@param include - enum parameter for selecting the response data from the db.
+		   *@param responsews_sptr - table workspace to save the response data
+		*/
+		int CSearchHelper::getDataFiles(long long invstId,ns1__investigationInclude include,
 			               API::ITableWorkspace_sptr& responsews_sptr)
 		{
 			//ICAt proxy object
 			ICATPortBindingProxy icat;
-
 			// Define ssl authentication scheme
 			if (soap_ssl_client_context(&icat,
 				SOAP_SSL_NO_AUTHENTICATION, /* use SOAP_SSL_DEFAULT in production code */
@@ -417,8 +317,8 @@ namespace Mantid
 							NULL      /* if randfile!=NULL: use a file with random data to seed randomness */
 							))
 			{
-				icat.soap_stream_fault(std::cerr);
-				return -1;
+				//icat.soap_stream_fault(std::cerr);
+				CErrorHandling::throwErrorMessages(icat);
 			}
 
 			ns1__getInvestigationIncludes request;
@@ -430,16 +330,16 @@ namespace Mantid
 			boost::shared_ptr<ns1__investigationInclude>invstInculde_sptr(new ns1__investigationInclude);
 			request.investigationInclude=invstInculde_sptr.get();
 
-			//boost::shared_ptr<LONG64>invstId_sptr(new LONG64);
-		  //  request.investigationId=invstId_sptr.get();
+			//boost::shared_ptr<long long>invstId_sptr(new long long);
+		   // request.investigationId=invstId_sptr.get();
+			request.investigationId=new long long;
 			setReqParamforInvestigationIncludes(invstId,include,request);
 
 			ns1__getInvestigationIncludesResponse response;
 			int ret_advsearch=icat.getInvestigationIncludes(&request,&response);
 			if(ret_advsearch!=0)
 			{
-				icat.soap_stream_fault(std::cerr);
-				return 0;// handle error
+				CErrorHandling::throwErrorMessages(icat);
 			}
 			responsews_sptr=saveInvestigationIncludesResponse(response);
 
@@ -462,13 +362,15 @@ namespace Mantid
 				throw;
 			}
 			outputws->addColumn("str","Instrument");//Instrument name
+			outputws->addColumn("long64","InvestigationId");//investigation id
 			outputws->addColumn("str","Name");//File name
-			outputws->addColumn("int","File Size");
-			outputws->addColumn("long64","FileId");
-			outputws->addColumn("str","Format");
-			outputws->addColumn("str","Format Version");
-			outputws->addColumn("str","Format Type");
-			outputws->addColumn("str","Create Time");
+			outputws->addColumn("int","File Size");//File Size
+			outputws->addColumn("long64","FileId");//File id
+			outputws->addColumn("str","Format");//File Format
+			outputws->addColumn("str","Format Version");//File Version
+			outputws->addColumn("str","Format Type");// File Format Type
+			outputws->addColumn("str","Create Time");// File Creation Time
+
 			try
 			{
 
@@ -486,40 +388,45 @@ namespace Mantid
 						{
 
 							API::TableRow t = outputws->appendRow();
-
-							std::string instrName=*response.return_->instrument;
-							std::cout<<"Instrument name is "<<instrName<<std::endl;
+							
+							//instrument name
 							savetoTableWorkspace(response.return_->instrument,t);
 
-							std::string fileName=*(*datafile_citr)->name;
-							std::cout<<"File name is "<<fileName<<std::endl;
+							//investigation Id
+							savetoTableWorkspace(response.return_->id,t);
+
+							//std::cout<<"investigation id is "<<*response.return_->id<<std::endl;
+
+							// File Name
 							savetoTableWorkspace((*datafile_citr)->name,t);
 
-							int fileSize=*(*datafile_citr)->fileSize;
-							std::cout<<"File size is "<<fileSize<<std::endl;
+							//std::cout<<"File name is "<<*(*datafile_citr)->name<<std::endl;
+
+							// File Size
 							savetoTableWorkspace((*datafile_citr)->fileSize,t);
 
-							long long fileId=*(*datafile_citr)->id;
-							std::cout<<"File id is "<<fileId<<std::endl;
+							//long long fileId=*(*datafile_citr)->id;
+							//std::cout<<"File id is "<<fileId<<std::endl;
+							//File Id
 							savetoTableWorkspace((*datafile_citr)->id,t);
+
 							ns1__datafileFormat* fileFormat=(*datafile_citr)->datafileFormat;
 							if(fileFormat)
 							{
 								if(fileFormat->datafileFormatPK)
 								{
-									std::string format=*(fileFormat->datafileFormatPK->name);
-									std::cout<<"File format is  "<<format<<std::endl;
+									// File Format
 									savetoTableWorkspace((fileFormat->datafileFormatPK->name),t);
 
-									std::string version=*(fileFormat->datafileFormatPK->version);
-									std::cout<<"File format version  is "<<version<<std::endl;
+									// File Format Version
 									savetoTableWorkspace((fileFormat->datafileFormatPK->version),t);
 								}
-								std::string formatType=*(fileFormat->formatType);
-								std::cout<<"File format type  is "<<formatType<<std::endl;
+								// File format Type
 								savetoTableWorkspace((fileFormat->formatType),t);
 
 							}
+							
+							//File creation Time.
 							if((*datafile_citr)->datafileCreateTime!=NULL)
 							{
 								time_t  crtime=*(*datafile_citr)->datafileCreateTime;
@@ -529,9 +436,7 @@ namespace Mantid
 								std::string ftime(temp);
 								std::string *creationtime=new std::string ;
 								creationtime->assign(ftime);
-
 								savetoTableWorkspace(creationtime,t);
-								std::cout<<"File creation time  is "<<*creationtime<<std::endl;
 							}
 
 						}
@@ -548,5 +453,105 @@ namespace Mantid
 			return outputws;
 		}
 
+		/* *This method calls ICat API getInvestigationIncludes and returns datasets details for a given investigation Id
+		   *@param invstId - investigation id
+		   *@param include - enum parameter for selecting the response data from iact db.
+		   *@param responsews_sptr - table workspace to save the response data
+		*/
+		int CSearchHelper::doDataSetsSearch(long long invstId,ns1__investigationInclude include,
+			               API::ITableWorkspace_sptr& responsews_sptr)
+		{
+			//ICAt proxy object
+			ICATPortBindingProxy icat;
+			// Define ssl authentication scheme
+			if (soap_ssl_client_context(&icat,
+				SOAP_SSL_NO_AUTHENTICATION, /* use SOAP_SSL_DEFAULT in production code */
+				NULL,       /* keyfile: required only when client must authenticate to 
+							server (see SSL docs on how to obtain this file) */
+							NULL,       /* password to read the keyfile */
+							NULL,      /* optional cacert file to store trusted certificates */
+							NULL,      /* optional capath to directory with trusted certificates */
+							NULL      /* if randfile!=NULL: use a file with random data to seed randomness */ 
+							))
+			{ 
+				CErrorHandling::throwErrorMessages(icat);
+			}
+
+			ns1__getInvestigationIncludes request;
+			//get the sessionid which is cached in session class during login
+			boost::shared_ptr<std::string >sessionId_sptr(new std::string);
+			request.sessionId=sessionId_sptr.get();
+
+			// enum include 
+			boost::shared_ptr<ns1__investigationInclude>invstInculde_sptr(new ns1__investigationInclude);
+			request.investigationInclude=invstInculde_sptr.get();
+
+			request.investigationId=new long long;
+			setReqParamforInvestigationIncludes(invstId,include,request);
+
+			ns1__getInvestigationIncludesResponse response;
+			int ret_advsearch=icat.getInvestigationIncludes(&request,&response);
+			if(ret_advsearch!=0)
+			{
+				CErrorHandling::throwErrorMessages(icat);
+			}
+			responsews_sptr=saveDataSets(response);
+
+			return ret_advsearch;
+		}
+
+		/* This method loops through the response return_vector and saves the datasets details to a table workspace
+		 * @param response const reference to response object
+		 * @returns shared pointer to table workspace which stores the data
+		*/
+		API::ITableWorkspace_sptr CSearchHelper::saveDataSets(const ns1__getInvestigationIncludesResponse& response)
+		{
+			//create table workspace
+			API::ITableWorkspace_sptr outputws ;
+			try
+			{
+				outputws=WorkspaceFactory::Instance().createTable("TableWorkspace");
+			}
+			catch(Mantid::Kernel::Exception::NotFoundError& )
+			{
+				throw;
+			}
+			outputws->addColumn("str","Name");//File name
+			outputws->addColumn("str","Status");
+			outputws->addColumn("str","Type");
+			outputws->addColumn("str","Description");
+			outputws->addColumn("long64","Sample");
+			
+			try
+			{				
+				std::vector<ns1__dataset*> datasetVec;
+				datasetVec.assign((response.return_)->datasetCollection.begin(),(response.return_)->datasetCollection.end());
+
+				std::vector<ns1__dataset*>::const_iterator dataset_citr;
+				for(dataset_citr=datasetVec.begin();dataset_citr!=datasetVec.end();++dataset_citr)
+				{						
+					API::TableRow t = outputws->appendRow();
+
+					// DataSet Name
+					savetoTableWorkspace((*dataset_citr)->name,t);
+					// DataSet Status
+					savetoTableWorkspace((*dataset_citr)->datasetStatus,t);
+					//DataSet Type
+					savetoTableWorkspace((*dataset_citr)->datasetType,t);
+					//DataSet Type
+					savetoTableWorkspace((*dataset_citr)->description,t);
+					//DataSet Type
+					savetoTableWorkspace((*dataset_citr)->sampleId,t);
+				}
+			}
+
+			catch(std::runtime_error& )
+			{
+				throw;
+			}
+
+			return outputws;
+		}
+
 	}
 }
diff --git a/Code/Mantid/ICat/test/DownloadDataFileTest.h b/Code/Mantid/ICat/test/DownloadDataFileTest.h
index 15de5191901..2bedc0d30d9 100644
--- a/Code/Mantid/ICat/test/DownloadDataFileTest.h
+++ b/Code/Mantid/ICat/test/DownloadDataFileTest.h
@@ -1,13 +1,16 @@
-#ifndef DOWNLOADDATAFILE_H
-#define DOWNLOADDATAFILE_H
+#ifndef DOWNLOADDATAFILE_H_
+#define DOWNLOADDATAFILE_H_
+
 #include <cxxtest/TestSuite.h>
 #include "MantidICat/DownloadDataFile.h"
 #include "MantidICat/Session.h"
 #include "MantidICat/Login.h"
-//#include "MantidICat/FileList.h"
 #include "MantidICat/GetInvestigation.h"
 #include "MantidICat/SearchByRunNumber.h"
 #include "MantidDataObjects/WorkspaceSingleValue.h"
+#include "MantidKernel/ConfigService.h"
+#include <iomanip>
+#include <fstream>
 
 using namespace Mantid;
 using namespace Mantid::ICat;
@@ -19,61 +22,150 @@ public:
 		TS_ASSERT_THROWS_NOTHING( downloadobj.initialize());
 		TS_ASSERT( downloadobj.isInitialized() );
 	}
-	void testSearchByAdavanced()
+	void testDownLoadDataFile()
 	{
-		std::string s;
-		std::getline(std::cin,s);
+				
 		Session::Instance();
-
 		if ( !loginobj.isInitialized() ) loginobj.initialize();
 
-		// Now set it...
 		loginobj.setPropertyValue("Username", "mantid_test");
 		loginobj.setPropertyValue("Password", "mantidtestuser");
-		loginobj.setPropertyValue("DBServer", "");
+	
 		
 		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
 		TS_ASSERT( loginobj.isExecuted() );
 
-		//if ( !filelistobj.isInitialized() ) filelistobj.initialize();
-		//// Now set it...
-		//filelistobj.setPropertyValue("StartRun", "100.0");
-		//filelistobj.setPropertyValue("EndRun", "102.0");
-		//filelistobj.setPropertyValue("OutputWorkspace","SearchBy_RunNumber");
-		//TS_ASSERT_THROWS_NOTHING(filelistobj.execute());
-		//TS_ASSERT( filelistobj.isExecuted() );
-		
+				
 		if ( !searchobj.isInitialized() ) searchobj.initialize();
 		searchobj.setPropertyValue("StartRun", "100.0");
 		searchobj.setPropertyValue("EndRun", "102.0");
-		searchobj.setPropertyValue("OutputWorkspace","SearchBy_RunNumber");
+		searchobj.setPropertyValue("Instruments","HET");
+		searchobj.setPropertyValue("OutputWorkspace","investigations");
 				
 		TS_ASSERT_THROWS_NOTHING(searchobj.execute());
 		TS_ASSERT( searchobj.isExecuted() );
 
 		if ( !invstObj.isInitialized() ) invstObj.initialize();
-		//invstObj.setPropertyValue("Title", "1-to-1 Ni Powder Top Shield on");
-		invstObj.setPropertyValue("Title", "PZT1 10 130 C");
-		invstObj.setPropertyValue("InputWorkspace", "SearchBy_RunNumber");
-		invstObj.setPropertyValue("OutputWorkspace","filelist");
+		invstObj.setPropertyValue("InvestigationId","13539191");
+		invstObj.setPropertyValue("InputWorkspace", "investigations");//records of investigations
+		invstObj.setPropertyValue("OutputWorkspace","investigation");//selected invesigation
 		//		
 		TS_ASSERT_THROWS_NOTHING(invstObj.execute());
 		TS_ASSERT( invstObj.isExecuted() );
 		
+		clock_t start=clock();
 		if ( !downloadobj.isInitialized() ) downloadobj.initialize();
 
-		downloadobj.setPropertyValue("Filename","GEM19105.RAW");
-		downloadobj.setPropertyValue("InputWorkspace","filelist");
+		downloadobj.setPropertyValue("Filename","HET00097.RAW");
+		downloadobj.setPropertyValue("InputWorkspace","investigation");
+		
+		TS_ASSERT_THROWS_NOTHING(downloadobj.execute());
+
+		clock_t end=clock();
+		float diff = float(end - start)/CLOCKS_PER_SEC;
+
+		std::string filepath=Kernel::ConfigService::Instance().getString("defaultsave.directory");
+		filepath += "download_time.txt";
+
+		std::ofstream ofs(filepath.c_str(), std::ios_base::out | std::ios_base::trunc);
+		if ( ofs.rdstate() & std::ios::failbit )
+		{
+			throw Mantid::Kernel::Exception::FileError("Error on creating File","download_time.txt");
+		}
+		ofs<<"Time taken for http download over internet from isis data server for files with investigation id 12576918 file is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
+		
 						
+		TS_ASSERT( downloadobj.isExecuted() );
+		//delete the file after execution
+		remove("HET00097.RAW");
+
+	}
+
+	void testDownLoadNexusFile()
+	{				
+		Session::Instance();
+
+		if ( !loginobj.isInitialized() ) loginobj.initialize();
+
+		// Now set it...
+		loginobj.setPropertyValue("Username", "mantid_test");
+		loginobj.setPropertyValue("Password", "mantidtestuser");
+			
+		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
+		TS_ASSERT( loginobj.isExecuted() );
+
+				
+		if ( !searchobj.isInitialized() ) searchobj.initialize();
+		searchobj.setPropertyValue("StartRun", "17440.0");
+		searchobj.setPropertyValue("EndRun", "17556.0");
+		searchobj.setPropertyValue("Instruments","EMU");
+		searchobj.setPropertyValue("OutputWorkspace","investigations");
+				
+		TS_ASSERT_THROWS_NOTHING(searchobj.execute());
+		TS_ASSERT( searchobj.isExecuted() );
+
+		if ( !invstObj.isInitialized() ) invstObj.initialize();
+	//	invstObj.setPropertyValue("Title", "Polythene T=290 F=922" );
+
+		invstObj.setPropertyValue("InvestigationId", "24070400");
+		invstObj.setPropertyValue("InputWorkspace", "investigations");
+
+		invstObj.setPropertyValue("OutputWorkspace","investigation");
+		//		
+		TS_ASSERT_THROWS_NOTHING(invstObj.execute());
+		TS_ASSERT( invstObj.isExecuted() );
+		
+		clock_t start=clock();
+		if ( !downloadobj.isInitialized() ) downloadobj.initialize();
+
+		downloadobj.setPropertyValue("Filename","EMU00017452.nxs");
+		downloadobj.setPropertyValue("InputWorkspace","investigation");
 		TS_ASSERT_THROWS_NOTHING(downloadobj.execute());
+
+		clock_t end=clock();
+		float diff = float(end -start)/CLOCKS_PER_SEC;
+		
+		std::string filepath=Kernel::ConfigService::Instance().getString("defaultsave.directory");
+		filepath += "download_time.txt";
+		
+		std::ofstream ofs(filepath.c_str(), std::ios_base::app);
+		if ( ofs.rdstate() & std::ios::failbit )
+		{
+			throw Mantid::Kernel::Exception::FileError("Error on creating File","download_time.txt");
+		}
+		ofs<<"Time taken for http download  from isis data server over internet for files with investigation id 24070400 is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
+		ofs.close();
+		
 		TS_ASSERT( downloadobj.isExecuted() );
+		//delete the file after execution
+		remove("EMU00017452.nxs");
+	}
+	void testDownloaddataFile1()
+	{	
+		std::string filepath=Kernel::ConfigService::Instance().getString("defaultsave.directory");
+		filepath += "download_time.txt";
+		std::ofstream ofs(filepath.c_str(), std::ios_base::app);
+		if ( ofs.rdstate() & std::ios::failbit )
+		{
+			throw Mantid::Kernel::Exception::FileError("Error on creating File","download_time.txt");
+		}
+
+		CDownloadDataFile downloadobj1;
+		clock_t start=clock();
+		downloadobj1.testDownload("http://download.mantidproject.org/videos/Installation.htm","test.htm");
+		clock_t end=clock();
+		float diff = float(end -start)/CLOCKS_PER_SEC;
+
+		ofs<<"Time taken for http download from mantidwebserver over internet for a small file of size 1KB is "<<std::fixed << std::setprecision(2) << diff << " seconds" << std::endl;
+
+        //delete the file after execution
+		remove("test.htm");
 
 	}
 private:
-	   CSearchByRunNumber searchobj;
-	 CGetInvestigation invstObj;
+	    CSearchByRunNumber searchobj;
+	    CGetDataFiles invstObj;
 		CDownloadDataFile downloadobj;
-		//CFileList filelistobj;
 		Login loginobj;
 };
 #endif
\ No newline at end of file
diff --git a/Code/Mantid/ICat/test/FileListTest.h b/Code/Mantid/ICat/test/FileListTest.h
index ca683378e06..a2c355c3741 100644
--- a/Code/Mantid/ICat/test/FileListTest.h
+++ b/Code/Mantid/ICat/test/FileListTest.h
@@ -19,31 +19,22 @@ public:
 		TS_ASSERT_THROWS_NOTHING( invstObj.initialize());
 		TS_ASSERT( invstObj.isInitialized() );
 	}
-	void testSearchByAdavanced()
+	void xtestSearchByAdavanced()
 	{
-		std::string s;
-		std::getline(std::cin,s);
-		Session::Instance();
+		/*std::string s;
+		std::getline(std::cin,s);*/
 
+		Session::Instance();
 	if ( !loginobj.isInitialized() ) loginobj.initialize();
 
 		// Now set it...
 		loginobj.setPropertyValue("Username", "mantid_test");
 		loginobj.setPropertyValue("Password", "mantidtestuser");
-		loginobj.setPropertyValue("DBServer", "");
+		//loginobj.setPropertyValue("DBServer", "");
 		
 		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
 		TS_ASSERT( loginobj.isExecuted() );
-
-		//if ( !filelistobj.isInitialized() ) filelistobj.initialize();
-		//// Now set it...
-		//filelistobj.setPropertyValue("StartRun", "100.0");
-		//filelistobj.setPropertyValue("EndRun", "102.0");
-		//filelistobj.setPropertyValue("OutputWorkspace","SearchBy_RunNumber");
-		//		
-		//TS_ASSERT_THROWS_NOTHING(filelistobj.execute());
-		//TS_ASSERT( filelistobj.isExecuted() );
-
+		
 		if ( !searchobj.isInitialized() ) searchobj.initialize();
 		searchobj.setPropertyValue("StartRun", "100.0");
 		searchobj.setPropertyValue("EndRun", "102.0");
@@ -63,9 +54,9 @@ public:
 
 	}
 private:
-		CFileList filelistobj;
+	CFileList filelistobj;
 	CSearchByRunNumber searchobj;
-	CGetInvestigation invstObj;
+	CGetDataFiles invstObj;
 	Login loginobj;
 };
 #endif
\ No newline at end of file
diff --git a/Code/Mantid/ICat/test/LoginTest.h b/Code/Mantid/ICat/test/LoginTest.h
index cab0fe8792d..6fc5146be5e 100644
--- a/Code/Mantid/ICat/test/LoginTest.h
+++ b/Code/Mantid/ICat/test/LoginTest.h
@@ -1,5 +1,5 @@
-#ifndef LOGINTEST_H
-#define LOGINTEST_H
+#ifndef LOGINTEST_H_
+#define LOGINTEST_H_
 
 #include <cxxtest/TestSuite.h>
 #include "MantidICat/Login.h"
@@ -11,16 +11,18 @@ class CLoginTest: public CxxTest::TestSuite
 public:
 	void testInit()
 	{
+		Login loginobj;
 		TS_ASSERT_THROWS_NOTHING( loginobj.initialize());
 		TS_ASSERT( loginobj.isInitialized() );
 	}
 	void testLogin()
 	{
-		std::string s;
-		std::getline(std::cin,s);
+		/*std::string s;
+		std::getline(std::cin,s);*/
 		Session::Instance();
+		Login loginobj;
 
-	if ( !loginobj.isInitialized() ) loginobj.initialize();
+	   if ( !loginobj.isInitialized() ) loginobj.initialize();
 
 		// Should fail because mandatory parameter has not been set
 		TS_ASSERT_THROWS(loginobj.execute(),std::runtime_error);
@@ -28,18 +30,36 @@ public:
 		// Now set it...
 		loginobj.setPropertyValue("Username", "mantid_test");
 		loginobj.setPropertyValue("Password", "mantidtestuser");
-		loginobj.setPropertyValue("DBServer", "");
+		//loginobj.setPropertyValue("DBServer", "");
 		
 		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
-		TS_ASSERT( loginobj.isExecuted() );
+		TS_ASSERT(loginobj.isExecuted() );
+		
+	}
+	void testLoginFail()
+	{
+		
+		Login loginobj;
+		Session::Instance();
+
+	   if ( !loginobj.isInitialized() ) loginobj.initialize();
 
-		std::string sessionid;//=loginobj.getPropertyValue("SessionId");
-		//std::cout<<"test method session id "<<sessionid<<std::endl;
-		sessionid=Session::Instance().getSessionId();
-		std::cout<<"test method session id "<<sessionid<<std::endl;
+		// Should fail because mandatory parameter has not been set
+		TS_ASSERT_THROWS(loginobj.execute(),std::runtime_error);
+
+		//invalid username
+		loginobj.setPropertyValue("Username", "mantid_test");
+		loginobj.setPropertyValue("Password", "mantidtestuser1");
+		//loginobj.setPropertyValue("DBServer", "");
+		
+		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
+		//should fail
+		TS_ASSERT( !loginobj.isExecuted() );
+		//empty sessionid
+		TS_ASSERT(!Session::Instance().getSessionId().empty());
+		
 	}
-private:
 
-		Login loginobj;
+		
 };
 #endif
\ No newline at end of file
diff --git a/Code/Mantid/ICat/test/SearchByRunNumberTest.h b/Code/Mantid/ICat/test/SearchByRunNumberTest.h
index b91b63c713e..fb5f9d5fa0a 100644
--- a/Code/Mantid/ICat/test/SearchByRunNumberTest.h
+++ b/Code/Mantid/ICat/test/SearchByRunNumberTest.h
@@ -13,41 +13,69 @@ using namespace Mantid::ICat;
 class CSearchByAdvancedTest: public CxxTest::TestSuite
 {
 public:
-	//CSearchByAdvancedTest(){}
-	//~CSearchByAdvancedTest(){}
+	
 	void testInit()
 	{
 		TS_ASSERT_THROWS_NOTHING( searchobj.initialize());
 		TS_ASSERT( searchobj.isInitialized() );
 	}
-	void testSearchByAdavanced()
+	void testSearchByRunNumberandInstrument()
 	{
-		std::string s;
-		std::getline(std::cin,s);
+		/*std::string s;
+		std::getline(std::cin,s);*/
 		Session::Instance();
 
 		if ( !loginobj.isInitialized() ) loginobj.initialize();
 
-		// Now set it...
 		loginobj.setPropertyValue("Username", "mantid_test");
 		loginobj.setPropertyValue("Password", "mantidtestuser");
-		loginobj.setPropertyValue("DBServer", "");
+		//loginobj.setPropertyValue("DBServer", "");
 		
 		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
 		TS_ASSERT( loginobj.isExecuted() );
 
 		if ( !searchobj.isInitialized() ) searchobj.initialize();
-
 		
-		// Now set it...
 		searchobj.setPropertyValue("StartRun", "100.0");
-		searchobj.setPropertyValue("EndRun", "102.0");
+		searchobj.setPropertyValue("EndRun", "109.0");
+		searchobj.setPropertyValue("Instruments","LOQ");
 		searchobj.setPropertyValue("OutputWorkspace","SearchBy_RunNumber");
 				
 		TS_ASSERT_THROWS_NOTHING(searchobj.execute());
 		TS_ASSERT( searchobj.isExecuted() );
 
 	}
+	void xtestSearchByRunNumberInvalidInput()
+	{
+
+		/*std::string s;
+		std::getline(std::cin,s);*/
+
+		Session::Instance();
+
+		if ( !loginobj.isInitialized() ) loginobj.initialize();
+
+		// Now set it...
+		loginobj.setPropertyValue("Username", "mantid_test");
+		loginobj.setPropertyValue("Password", "mantidtestuser");
+		//loginobj.setPropertyValue("DBServer", "");
+		
+		TS_ASSERT_THROWS_NOTHING(loginobj.execute());
+		TS_ASSERT( loginobj.isExecuted() );
+
+		if ( !searchobj.isInitialized() ) searchobj.initialize();
+		
+		// start run number < end run number
+		searchobj.setPropertyValue("StartRun", "150.0");
+		searchobj.setPropertyValue("EndRun", "102.0");
+		searchobj.setPropertyValue("Instruments","LOQ");
+		searchobj.setPropertyValue("OutputWorkspace","SearchBy_RunNumber");
+				
+		TS_ASSERT_THROWS_NOTHING(searchobj.execute());
+		//should fail
+		TS_ASSERT( !loginobj.isExecuted() );
+
+	}
 private:
 		CSearchByRunNumber searchobj;
 		Login loginobj;
diff --git a/Code/Mantid/Kernel/inc/MantidKernel/MaskedProperty.h b/Code/Mantid/Kernel/inc/MantidKernel/MaskedProperty.h
new file mode 100644
index 00000000000..a87ce4ca35d
--- /dev/null
+++ b/Code/Mantid/Kernel/inc/MantidKernel/MaskedProperty.h
@@ -0,0 +1,96 @@
+#ifndef MANTID_KERNEL_MASKEDPROPERTY_H_
+#define MANTID_KERNEL_MASKEDPROPERTY_H_
+
+#include "MantidKernel/PropertyWithValue.h"
+
+
+ /** A property class for masking the properties. It inherits from PropertyWithValue.
+     This class masks the properties and useful when the property value is not to be
+	 displayed  in the user interface widgets like algorithm history display,
+	 log window etc and log file .The masked property will be displayed.
+     This class is specialised for string and masks the property value with charcater "*"
+    
+    Copyright &copy;  2011 STFC Rutherford Appleton Laboratory
+
+    This file is part of Mantid.
+
+    Mantid is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    Mantid is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+    File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>.
+    Code Documentation is available at: <http://doxygen.mantidproject.org>
+    */	
+
+namespace Mantid
+{
+	namespace Kernel
+	{
+		template <typename TYPE = std::string>
+		class MaskedProperty: public Kernel::PropertyWithValue<TYPE >
+		{
+		public:
+		  /** Constructor  for Maskedproperty class
+			* @param name - name of the property
+			* @param defaultvalue - defaultvalue of the property
+			* @param validator - property validator
+			* @param direction - Whether this is a Direction::Input, Direction::Output or Direction::InOut (Input & Output) property
+			*/
+			  MaskedProperty(const std::string& name,TYPE defaultvalue,IValidator<TYPE> *validator = new NullValidator<TYPE>,const unsigned int direction = Direction::Input):
+			  Kernel::PropertyWithValue<TYPE>(name,defaultvalue , validator, direction ),m_maskedValue("")
+			  { 
+			  }
+
+			/** Constructor  for Maskedproperty class
+			  * @param name - name of the property
+			  * @param defaultvalue - defaultvalue of the property
+			  * @param direction - Whether this is a Direction::Input, Direction::Output or Direction::InOut (Input & Output) property
+			  */
+			  MaskedProperty( const std::string& name, const TYPE& defaultvalue, const unsigned int direction):
+			  Kernel::PropertyWithValue <TYPE>(name,defaultvalue,direction ),m_maskedValue("")
+			  {
+				  
+			  }
+			 
+			/** This method creates History 
+			  */
+			  virtual const Kernel::PropertyHistory createHistory() const
+			  {
+							  
+				  doMasking();
+				
+				  return Kernel::PropertyHistory(this->name(),this->getMaskedValue(),this->type(),this->isDefault(),Kernel::PropertyWithValue<TYPE >::direction());
+			  }
+		private:
+
+			/** This method creates masked value for a property
+			  * Useful for masking for properties like password in mantid
+			  */
+			  void doMasking()const 
+			  {
+				  TYPE value(value());
+				  m_maskedValue=std::string(value.size(),'*');
+			  }
+
+			/** This method returns the masked property value
+			  */
+			  TYPE getMaskedValue() const
+			  {				  
+				  return m_maskedValue;
+     		  }
+		private:
+			mutable TYPE m_maskedValue;
+
+		};
+	}
+}
+#endif
diff --git a/Code/Mantid/Kernel/src/ConfigService.cpp b/Code/Mantid/Kernel/src/ConfigService.cpp
index 74bb42ed2e4..578da6dbbc7 100644
--- a/Code/Mantid/Kernel/src/ConfigService.cpp
+++ b/Code/Mantid/Kernel/src/ConfigService.cpp
@@ -136,6 +136,7 @@ namespace Kernel
     m_ConfigPaths.insert(std::make_pair("defaultsave.directory", false));
     m_ConfigPaths.insert(std::make_pair("datasearch.directories",true));
     m_ConfigPaths.insert(std::make_pair("pythonalgorithms.directories",true));
+	m_ConfigPaths.insert(std::make_pair("icatDownload.directory",true));
 
     //attempt to load the default properties file that resides in the directory of the executable
     updateConfig(getBaseDir() + m_properties_file_name,false,false);
diff --git a/Code/Mantid/Kernel/src/MaskedProperty.cpp b/Code/Mantid/Kernel/src/MaskedProperty.cpp
new file mode 100644
index 00000000000..57b6540df12
--- /dev/null
+++ b/Code/Mantid/Kernel/src/MaskedProperty.cpp
@@ -0,0 +1,12 @@
+#include "MantidKernel/MaskedProperty.h"
+
+namespace Mantid
+{
+namespace Kernel
+{
+///@cond TEMPLATE
+	template DLLExport class Mantid::Kernel::MaskedProperty<std::string>;
+///@endcond TEMPLATE
+
+} // namespace API
+} // namespace Mantid
\ No newline at end of file
diff --git a/Code/Mantid/Kernel/test/MaskedPropertyTest.h b/Code/Mantid/Kernel/test/MaskedPropertyTest.h
new file mode 100644
index 00000000000..3745c0ded71
--- /dev/null
+++ b/Code/Mantid/Kernel/test/MaskedPropertyTest.h
@@ -0,0 +1,47 @@
+#ifndef MASKEDPROPERTYTEST_H_
+#define MASKEDPROPERTYTEST_H_
+
+#include <cxxtest/TestSuite.h>
+#include "MantidKernel/PropertyWithValue.h"
+#include "MantidKernel/MaskedProperty.h"
+
+using namespace Mantid::Kernel;
+
+class MaskedPropertyTest:public CxxTest::TestSuite
+{
+public:
+	MaskedPropertyTest()
+	{
+		m_Property1=new MaskedProperty<std::string>("property1","value");
+		m_Property2= new MaskedProperty<std::string>("property2","");
+	
+	}
+	void testMaskProperty()
+	{
+		TS_ASSERT(! m_Property1->name().compare("property1") );
+		TS_ASSERT(! m_Property1->value().compare("value") );
+		PropertyHistory prohist=m_Property1->createHistory();
+		TS_ASSERT(! prohist.value().compare("*****") );
+	}
+
+	void testMaskProperty1()
+	{
+		TS_ASSERT(! m_Property2->name().compare("property2") );
+		TS_ASSERT(! m_Property2->value().compare("") );
+		PropertyHistory prohist=m_Property2->createHistory();
+		TS_ASSERT(! prohist.value().compare("") );
+	}
+
+	~MaskedPropertyTest()
+	{
+		delete m_Property1;
+	}
+private:
+	MaskedProperty<std::string> *m_Property1;
+	MaskedProperty<std::string> *m_Property2;
+
+
+};
+
+
+#endif
\ No newline at end of file
-- 
GitLab