Skip to content
Snippets Groups Projects
Commit 3cb0348e authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Re #10016. Deleting SNSDataArchiveICAT2.

parent 0f84d816
No related merge requests found
...@@ -105,7 +105,6 @@ set ( SRC_FILES ...@@ -105,7 +105,6 @@ set ( SRC_FILES
src/RenameLog.cpp src/RenameLog.cpp
src/RotateInstrumentComponent.cpp src/RotateInstrumentComponent.cpp
src/SNSDataArchive.cpp src/SNSDataArchive.cpp
src/SNSDataArchiveICAT2.cpp
src/SaveANSTOAscii.cpp src/SaveANSTOAscii.cpp
src/SaveAscii.cpp src/SaveAscii.cpp
src/SaveAscii2.cpp src/SaveAscii2.cpp
...@@ -242,7 +241,6 @@ set ( INC_FILES ...@@ -242,7 +241,6 @@ set ( INC_FILES
inc/MantidDataHandling/RenameLog.h inc/MantidDataHandling/RenameLog.h
inc/MantidDataHandling/RotateInstrumentComponent.h inc/MantidDataHandling/RotateInstrumentComponent.h
inc/MantidDataHandling/SNSDataArchive.h inc/MantidDataHandling/SNSDataArchive.h
inc/MantidDataHandling/SNSDataArchiveICAT2.h
inc/MantidDataHandling/SaveANSTOAscii.h inc/MantidDataHandling/SaveANSTOAscii.h
inc/MantidDataHandling/SaveAscii.h inc/MantidDataHandling/SaveAscii.h
inc/MantidDataHandling/SaveAscii2.h inc/MantidDataHandling/SaveAscii2.h
...@@ -375,7 +373,6 @@ set ( TEST_FILES ...@@ -375,7 +373,6 @@ set ( TEST_FILES
RemoveLogsTest.h RemoveLogsTest.h
RenameLogTest.h RenameLogTest.h
RotateInstrumentComponentTest.h RotateInstrumentComponentTest.h
SNSDataArchiveICAT2Test.h
SNSDataArchiveTest.h SNSDataArchiveTest.h
SaveANSTOAsciiTest.h SaveANSTOAsciiTest.h
SaveAscii2Test.h SaveAscii2Test.h
......
#ifndef MANTID_DATAHANDLING_SNSDATAARCHIVEICAT2_H_
#define MANTID_DATAHANDLING_SNSDATAARCHIVEICAT2_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/System.h"
#include "MantidAPI/IArchiveSearch.h"
#include <string>
namespace Mantid
{
namespace DataHandling
{
/**
This class is for searching the SNS data archive
@date 02/22/2012
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National 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://github.com/mantidproject/mantid>.
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport SNSDataArchiveICAT2: public API::IArchiveSearch
{
public:
/// Find the archive location of a set of files.
std::string getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts) const;
private:
/// Call web service to get full path.
std::string getPath(const std::string& fName) const;
};
}
}
#endif /* MANTID_DATAHANDLING_SNSDATAARCHIVEICAT2_H_ */
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidKernel/Logger.h"
#include "MantidDataHandling/SNSDataArchiveICAT2.h"
#include "MantidAPI/ArchiveSearchFactory.h"
#include <Poco/File.h>
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/NetException.h>
#include <Poco/URI.h>
#include <boost/algorithm/string.hpp>
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Element.h>
#include "Poco/SAX/InputSource.h"
#include <Poco/DOM/NodeList.h>
#include <Poco/DOM/NodeIterator.h>
#include <iostream>
using Poco::Net::HTTPSClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
using Poco::Net::HTTPMessage;
using Poco::Net::ConnectionRefusedException;
using Poco::URI;
namespace Mantid
{
namespace DataHandling
{
namespace
{
// Get a reference to the logger
Kernel::Logger g_log("SNSDataArchiveICAT2");
}
DECLARE_ARCHIVESEARCH(SNSDataArchiveICAT2,SNSDataSearchICAT2);
/**
* Calls a web service to get a full path to a file
* @param fName :: The file name.
* @return The path to the file or empty string in case of error.
*/
std::string SNSDataArchiveICAT2::getPath(const std::string& fName) const
{
std::string baseURL(
"https://prod.sns.gov/sns-icat-ws/icat-location/fileName/");
std::string URL(baseURL + fName);
g_log.debug() << "SNSDataArchiveICAT2 URL = \'" << URL << "\'\n";
std::string wsResult = "";
//#ifdef _WIN32
// // Return an empty string
//#else
//
//#endif
Poco::URI uri(URL);
std::string path(uri.getPathAndQuery());
Poco::Net::Context::Ptr context = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "",
"", Poco::Net::Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
try { // workaround for ubuntu 11.04
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context); // this line is broken
HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
session.sendRequest(req);
HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
char buff[300];
std::streamsize n;
do
{
rs.read(&buff[0], 300);
n = rs.gcount();
wsResult.append(&buff[0], n);
} while (n == 300);
} catch (ConnectionRefusedException &) {
g_log.information() << "Connection refused by prod.sns.gov\n";
throw;
} catch(Poco::IOException &e) {
g_log.debug() << e.name() << " thrown.\n";
g_log.information() << e.message() << "\n";
throw;
}
g_log.debug() << "SNSDataArchiveICAT2 Returning Filename = \'" << wsResult << "\'\n";
return wsResult;
}
/**
* @param filenames : List of files to search
* @param exts : List of extensions to check against
* @return list of archive locations
*/
std::string SNSDataArchiveICAT2::getArchivePath(const std::set<std::string>& filenames, const std::vector<std::string>& exts) const
{
std::vector<std::string>::const_iterator ext = exts.begin();
for (; ext != exts.end(); ++ext)
{
std::set<std::string>::const_iterator it = filenames.begin();
for(; it!=filenames.end(); ++it)
{
std::string path = getPath(*it + *ext);
try
{
if (!path.empty() && Poco::File(path).exists())
{
return path;
}
}
catch(std::exception& e)
{
g_log.error() << "Cannot open file " << path << ": " << e.what() << '\n';
return "";
}
} // it
} // ext
return "";
} // end of getArchivePath
} // namespace DataHandling
} // namespace Mantid
#ifndef SNSDATAARCHIVEICAT2TEST_H_
#define SNSDATAARCHIVEICAT2TEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidDataHandling/SNSDataArchiveICAT2.h"
#include "MantidAPI/ArchiveSearchFactory.h"
using namespace Mantid::DataHandling;
using namespace Mantid::API;
class SNSDataArchiveICAT2Test : public CxxTest::TestSuite
{
public:
void xtestSearch()
{
SNSDataArchiveICAT2 arch;
// PG3 Test case
std::set<std::string> filename;
filename.insert("PG3_7390");
std::vector<std::string> extension = std::vector<std::string>(1,"_event.nxs");
std::string path = arch.getArchivePath(filename, extension);
TS_ASSERT_EQUALS(path, "/SNS/PG3/IPTS-2767/0/7390/NeXus/PG3_7390_histo.nxs");
// BSS Test case
filename.clear();
filename.insert("BSS_18339");
path = arch.getArchivePath(filename, extension);
TS_ASSERT_EQUALS(path, "/SNS/BSS/IPTS-6817/0/18339/NeXus/BSS_18339_event.nxs");
// Test a non-existent file
filename.clear();
filename.insert("mybeamline_666");
extension = std::vector<std::string>(1, ".nxs");
path = arch.getArchivePath(filename, extension);
TS_ASSERT(path.empty());
}
void testFactory()
{
boost::shared_ptr<IArchiveSearch> arch = ArchiveSearchFactory::Instance().create("SNSDataSearchICAT2");
TS_ASSERT(arch);
}
};
#endif /*SNSDATAARCHIVEICAT2TEST_H_*/
...@@ -314,7 +314,6 @@ ...@@ -314,7 +314,6 @@
<archive> <archive>
<archiveSearch plugin="SNSDataSearch" /> <archiveSearch plugin="SNSDataSearch" />
<archiveSearch plugin="SNSDataSearchICAT2" />
</archive> </archive>
<computeResource name="Fermi"> <computeResource name="Fermi">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment