20#include <boost/algorithm/string.hpp>
21#include <boost/algorithm/string/predicate.hpp>
22#include <boost/regex.hpp>
24using boost::algorithm::ends_with;
26using Mantid::Catalog::Exception::CatalogError;
27using Mantid::Catalog::ONCat::ONCat;
28using Mantid::Catalog::ONCat::ONCat_uptr;
29using Mantid::Catalog::ONCat::ONCatEntity;
30using Mantid::Catalog::ONCat::QueryParameter;
31using Mantid::Catalog::ONCat::QueryParameters;
35std::string toUpperCase(
const std::string &s) {
36 std::string result(s);
37 std::transform(s.begin(), s.end(), result.begin(), toupper);
41const static boost::regex FILE_REGEX(
"^(.*?)_(\\d+).*$");
42const static std::string NOT_FOUND(
"");
100 const
std::vector<
std::
string> &suffixes)
const {
101 if (basenames.size() == 0) {
106 const auto basename = *basenames.cbegin();
109 boost::smatch result;
110 if (!boost::regex_match(basename, result, FILE_REGEX)) {
111 g_log.
debug() <<
"Unexpected input passed to getArchivePath():" << std::endl << basename << std::endl;
115 assert(result.size() == 3);
116 const std::string instrument = toUpperCase(result[1]);
117 const std::string run = result[2];
120 std::string facility;
122 facility = config.getInstrument(instrument).facility().name();
124 if (facility !=
"HFIR" && facility !=
"SNS") {
128 g_log.
debug() <<
"\"" << instrument <<
"\" is not an instrument known to Mantid." << std::endl;
136 const QueryParameters params{{
"facility", facility},
137 {
"instrument", instrument},
138 {
"projection",
"location"},
139 {
"tags",
"type/raw"},
140 {
"sort_by",
"ingested"},
141 {
"sort_direction",
"DESCENDING"},
142 {
"ranges_q",
"indexed.run_number:" + run}};
150 auto defaultOncat = ONCat::fromMantidSettings();
151 auto *oncat = m_oncat ? m_oncat.get() : defaultOncat.get();
153 const auto datafiles = [&]() {
155 return oncat->list(
"api",
"datafiles", params);
156 }
catch (CatalogError &ce) {
157 g_log.
debug() <<
"Error while calling ONCat:" << std::endl << ce.what() << std::endl;
158 return std::vector<ONCatEntity>();
162 if (datafiles.size() == 0) {
163 g_log.
debug() <<
"ONCat does not know the location of run \"" << run <<
"\" for \"" << instrument <<
"\"."
168 g_log.
debug() <<
"All datafiles returned from ONCat:" << std::endl;
169 for (
const auto &datafile : datafiles) {
170 g_log.
debug() << datafile.toString() << std::endl;
180 const auto location = *datafiles.cbegin()->get<std::string>(
"location");
184 for (
const auto &suffix : suffixes) {
185 const std::string fullSuffix = basename + suffix;
186 if (ends_with(toUpperCase(location), toUpperCase(fullSuffix))) {
191 if (ends_with(toUpperCase(location), toUpperCase(basename))) {
#define DECLARE_ARCHIVESEARCH(classname, facility)
Please see the .cpp file for more information.
void setONCat(ONCat_uptr oncat)
Exception for when an item is not found in a collection.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Kernel::Logger g_log("ExperimentInfo")
static logger object