36 std::transform(s.begin(), s.end(), result.begin(), toupper);
105 const std::vector<std::string> &suffixes)
const {
106 if (basenames.size() == 0) {
111 const auto basename = *basenames.cbegin();
114 const auto [instrument, run] = toInstrumentAndRunNumber(basename);
115 if (instrument.empty() || run.empty()) {
116 g_log.
debug() <<
"Unexpected input passed to getArchivePath():" << std::endl << basename << std::endl;
120 const auto &config = Mantid::Kernel::ConfigService::Instance();
121 std::string facility;
123 facility = config.getInstrument(instrument).facility().name();
125 if (facility !=
"HFIR" && facility !=
"SNS") {
129 g_log.
debug() <<
"\"" << instrument <<
"\" is not an instrument known to Mantid." << std::endl;
137 const QueryParameters params{{
"facility", facility},
138 {
"instrument", instrument},
139 {
"projection",
"location"},
140 {
"tags",
"type/raw"},
141 {
"sort_by",
"ingested"},
142 {
"sort_direction",
"DESCENDING"},
143 {
"ranges_q",
"indexed.run_number:" + run}};
151 auto defaultOncat = ONCat::fromMantidSettings();
154 const auto datafiles = [&]() {
156 return oncat->list(
"api",
"datafiles", params);
157 }
catch (CatalogError &ce) {
158 g_log.
debug() <<
"Error while calling ONCat:" << std::endl << ce.what() << std::endl;
159 return std::vector<ONCatEntity>();
163 if (datafiles.size() == 0) {
164 g_log.
debug() <<
"ONCat does not know the location of run \"" << run <<
"\" for \"" << instrument <<
"\"."
169 g_log.
debug() <<
"All datafiles returned from ONCat:" << std::endl;
170 for (
const auto &datafile : datafiles) {
171 g_log.
debug() << datafile.toString() << std::endl;
181 const auto location = *datafiles.cbegin()->get<std::string>(
"location");
185 for (
const auto &suffix : suffixes) {
186 const std::string fullSuffix = basename + suffix;
187 if (toUpperCase(location).ends_with(toUpperCase(fullSuffix))) {
192 if (toUpperCase(location).ends_with(toUpperCase(basename))) {
202 std::vector<std::filesystem::path> results(hintstrs.size());
203 if (hintstrs.empty()) {
209 std::string instrumentName;
210 std::vector<std::string> runNumbers;
212 for (
const auto &hintstr : hintstrs) {
213 const auto [instrument, run] = toInstrumentAndRunNumber(hintstr);
214 if (instrument.empty() || run.empty()) {
215 g_log.
debug() <<
"Unexpected input passed to getArchivePaths():" << std::endl << hintstr << std::endl;
218 if (instrumentName.empty()) {
219 instrumentName = instrument;
220 }
else if (instrumentName != instrument) {
221 g_log.
debug() <<
"Multiple different instruments found in hints passed to getArchivePaths():" << std::endl;
224 runNumbers.push_back(run);
227 const auto &config = Mantid::Kernel::ConfigService::Instance();
228 std::string facility;
230 facility = config.getInstrument(instrumentName).facility().name();
231 if (facility !=
"HFIR" && facility !=
"SNS") {
235 g_log.
debug() <<
"\"" << instrumentName <<
"\" is not an instrument known to Mantid." << std::endl;
239 std::string runNumbersStr = boost::algorithm::join(runNumbers,
",");
245 const QueryParameters params{{
"facility", facility},
246 {
"instrument", instrumentName},
247 {
"projection",
"location"},
248 {
"tags",
"type/raw"},
249 {
"sort_by",
"run_number"},
250 {
"sort_direction",
"ASCENDING"},
251 {
"ranges_q",
"indexed.run_number:" + runNumbersStr}};
259 auto defaultOncat = ONCat::fromMantidSettings();
262 const auto datafiles = [&]() {
264 return oncat->list(
"api",
"datafiles", params);
265 }
catch (CatalogError &ce) {
266 g_log.
debug() <<
"Error while calling ONCat:" << std::endl << ce.what() << std::endl;
267 return std::vector<ONCatEntity>();
271 if (datafiles.size() == 0) {
272 g_log.
debug() <<
"ONCat does not know the location of runs \"" << runNumbersStr <<
"\" for \"" << instrumentName
273 <<
"\"." << std::endl;
277 g_log.
debug() <<
"All datafiles returned from ONCat:" << std::endl;
278 std::map<std::string, std::filesystem::path> runToLocation;
279 for (
const auto &datafile : datafiles) {
280 g_log.
debug() << datafile.toString() << std::endl;
281 const auto location = *datafile.get<std::string>(
"location");
282 const auto filename = std::filesystem::path(location).filename().string();
283 const auto [_, run] = toInstrumentAndRunNumber(filename);
290 if (!runToLocation.contains(run)) {
291 runToLocation.emplace(run, std::filesystem::path(location));
295 for (
size_t i = 0; i < runNumbers.size(); ++i) {
296 const auto it = runToLocation.find(runNumbers[i]);
297 if (it != runToLocation.end()) {
298 results[i] = it->second;