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

Move SNS to use ONCAT for finding files

parent 3639c31b
No related branches found
No related tags found
No related merge requests found
...@@ -141,7 +141,6 @@ ...@@ -141,7 +141,6 @@
src/RenameLog.cpp src/RenameLog.cpp
src/RotateInstrumentComponent.cpp src/RotateInstrumentComponent.cpp
src/RotateSource.cpp src/RotateSource.cpp
src/SNSDataArchive.cpp
src/SaveANSTOAscii.cpp src/SaveANSTOAscii.cpp
src/SaveAscii.cpp src/SaveAscii.cpp
src/SaveAscii2.cpp src/SaveAscii2.cpp
...@@ -335,7 +334,6 @@ set ( INC_FILES ...@@ -335,7 +334,6 @@ set ( INC_FILES
inc/MantidDataHandling/RenameLog.h inc/MantidDataHandling/RenameLog.h
inc/MantidDataHandling/RotateInstrumentComponent.h inc/MantidDataHandling/RotateInstrumentComponent.h
inc/MantidDataHandling/RotateSource.h inc/MantidDataHandling/RotateSource.h
inc/MantidDataHandling/SNSDataArchive.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
...@@ -518,7 +516,6 @@ set ( TEST_FILES ...@@ -518,7 +516,6 @@ set ( TEST_FILES
RenameLogTest.h RenameLogTest.h
RotateInstrumentComponentTest.h RotateInstrumentComponentTest.h
RotateSourceTest.h RotateSourceTest.h
SNSDataArchiveTest.h
SaveANSTOAsciiTest.h SaveANSTOAsciiTest.h
SaveAscii2Test.h SaveAscii2Test.h
SaveAsciiTest.h SaveAsciiTest.h
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef MANTID_DATAHANDLING_SNSDATAARCHIVE_H_
#define MANTID_DATAHANDLING_SNSDATAARCHIVE_H_
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IArchiveSearch.h"
#include "MantidKernel/System.h"
#include <string>
namespace Mantid {
namespace DataHandling {
/**
This class is for searching the SNS data archive
@date 02/22/2012
*/
class DLLExport SNSDataArchive : 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 override;
};
} // namespace DataHandling
} // namespace Mantid
#endif /* MANTID_DATAHANDLING_SNSDATAARCHIVE_H_ */
...@@ -48,6 +48,7 @@ namespace Mantid { ...@@ -48,6 +48,7 @@ namespace Mantid {
namespace DataHandling { namespace DataHandling {
DECLARE_ARCHIVESEARCH(ORNLDataArchive, ORNLDataSearch) DECLARE_ARCHIVESEARCH(ORNLDataArchive, ORNLDataSearch)
DECLARE_ARCHIVESEARCH(ORNLDataArchive, SNSDataSearch)
/** /**
* **************** * ****************
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include <sstream>
#include "MantidAPI/ArchiveSearchFactory.h"
#include "MantidDataHandling/SNSDataArchive.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/InternetHelper.h"
#include "MantidKernel/Logger.h"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <Poco/AutoPtr.h>
#include <Poco/DOM/DOMParser.h>
#include <Poco/DOM/Document.h>
#include <Poco/DOM/Element.h>
#include <Poco/DOM/NodeList.h>
#include <Poco/SAX/InputSource.h>
namespace Mantid {
namespace DataHandling {
namespace {
// Get a reference to the logger
Kernel::Logger g_log("SNSDataArchive");
/// Base url for restful web survice
const std::string
BASE_URL("http://icat.sns.gov:2080/icat-rest-ws/datafile/filename/");
} // namespace
DECLARE_ARCHIVESEARCH(SNSDataArchive, SNSDataSearch)
/**
* @param filenames : List of files to search
* @param exts : List of extensions to check against
* @return list of archive locations
*/
std::string
SNSDataArchive::getArchivePath(const std::set<std::string> &filenames,
const std::vector<std::string> &exts) const {
g_log.debug() << "getArchivePath([ ";
for (const auto &iter : filenames)
g_log.debug() << iter << " ";
g_log.information() << "], [ ";
for (const auto &iter : exts)
g_log.debug() << iter << " ";
g_log.debug() << "])\n";
auto iter = filenames.cbegin();
std::string filename = *iter;
// ICAT4 web service take upper case filename such as HYSA_2662
std::transform(filename.begin(), filename.end(), filename.begin(), toupper);
for (const auto &ext : exts) {
g_log.debug() << ext << ";";
}
g_log.debug() << "\n";
const std::string URL(BASE_URL + filename);
g_log.debug() << "URL: " << URL << "\n";
Kernel::InternetHelper inetHelper;
std::ostringstream rs;
int status = inetHelper.sendRequest(URL, rs);
// Create a DOM document from the response.
Poco::XML::DOMParser parser;
std::istringstream istrsource(rs.str());
Poco::XML::InputSource source(istrsource);
Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&source);
std::vector<std::string> locations;
// Everything went fine, return the XML document.
// Otherwise look for an error message in the XML document.
if (status == Kernel::InternetHelper::HTTP_OK) {
std::string location;
Poco::AutoPtr<Poco::XML::NodeList> pList =
pDoc->getElementsByTagName("location");
for (unsigned long i = 0; i < pList->length(); i++) {
location = pList->item(i)->innerText();
g_log.debug() << "location: " << location << "\n";
locations.push_back(location);
}
}
for (const auto &ext : exts) {
std::string datafile = filename + ext;
std::vector<std::string>::const_iterator iter = locations.begin();
for (; iter != locations.end(); ++iter) {
if (boost::algorithm::ends_with((*iter), datafile)) {
return *iter;
} // end if
} // end for iter
} // end for ext
return "";
}
} // namespace DataHandling
} // namespace Mantid
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#ifndef SNSDATAARCHIVETEST_H_
#define SNSDATAARCHIVETEST_H_
#include <cxxtest/TestSuite.h>
#include "MantidAPI/ArchiveSearchFactory.h"
#include "MantidDataHandling/SNSDataArchive.h"
using namespace Mantid::DataHandling;
using namespace Mantid::API;
class SNSDataArchiveTest : public CxxTest::TestSuite {
public:
void xtestSearch() {
SNSDataArchive 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");
// HYSA Test case
filename.clear();
filename.insert("HYSA_2411");
extension = std::vector<std::string>(1, ".nxs.h5");
path = arch.getArchivePath(filename, extension);
TS_ASSERT_EQUALS(path, "/SNS/HYSA/IPTS-8004/nexus/HYSA_2411.nxs.h5");
// 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("SNSDataSearch");
TS_ASSERT(arch);
}
};
#endif /*SNSDATAARCHIVETEST_H_*/
...@@ -38,7 +38,7 @@ Archive Searching ...@@ -38,7 +38,7 @@ Archive Searching
SNS / ONCat SNS / ONCat
########### ###########
- SNS file searching has been moved to `ONCAT <https://oncat.ornl.gov/>`_ - SNS file searching has been moved to `ONCAT <https://oncat.ornl.gov/>`_. Due to auto-updating of the ``Facilities.xml``, this was done by directing ``SNSDataSearch`` and ``ORNLDataSearch`` to both use ONCAT.
- For HFIR instruments that write out raw files with run numbers, we have enabled functionality that allows for the searching of file locations by making calls to ONCat. To use this, make sure that the "Search Data Archive" option is checked in your "Manage User Directories" settings. The ``FileFinder`` and algorithms such as :ref:`Load <algm-Load>` will then accept inputs such as "``HB2C_143210``". - For HFIR instruments that write out raw files with run numbers, we have enabled functionality that allows for the searching of file locations by making calls to ONCat. To use this, make sure that the "Search Data Archive" option is checked in your "Manage User Directories" settings. The ``FileFinder`` and algorithms such as :ref:`Load <algm-Load>` will then accept inputs such as "``HB2C_143210``".
ISIS / ICat ISIS / ICat
......
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