Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instrument data cache for ENGINX #37420

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Framework/API/inc/MantidAPI/ISISInstrumentDataCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/DllConfig.h"
#include "MantidKernel/ConfigService.h"
#include <string>

namespace Mantid {
Expand All @@ -21,7 +22,8 @@ class MANTID_API_DLL ISISInstrumentDataCache {
std::string getFileParentDirectoryPath(const std::string &filename) const;

private:
std::pair<std::string, std::string> validateInstrumentAndNumber(const std::string &filename) const;
std::pair<Mantid::Kernel::InstrumentInfo, std::string> validateInstrumentAndNumber(const std::string &filename) const;
std::string makeIndexFilePath(const std::string &instrumentName) const;
std::pair<std::string, std::string> splitIntoInstrumentAndNumber(const std::string &filename) const;
std::string m_dataCachePath;
};
Expand Down
26 changes: 19 additions & 7 deletions Framework/API/src/ISISInstrumentDataCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ Mantid::Kernel::Logger g_log("ISISInstrumentDataCache");
std::string Mantid::API::ISISInstrumentDataCache::getFileParentDirectoryPath(const std::string &fileName) const {
g_log.debug() << "ISISInstrumentDataCache::getFileParentDirectoryPath(" << fileName << ")" << std::endl;

auto [instrName, runNumber] = validateInstrumentAndNumber(fileName);
auto [instrumentInfo, runNumber] = validateInstrumentAndNumber(fileName);
std::string instrName = instrumentInfo.name();

// Open index json file
std::string jsonPath = m_dataCachePath + "/" + instrName + "/" + instrName + "_index.json";
std::string jsonPath = makeIndexFilePath(instrName);
std::ifstream ifstrm{jsonPath};
if (!ifstrm) {
throw std::invalid_argument("Could not open index file: " + jsonPath);
if (!ifstrm.is_open()) { // Try again with shortname
instrName = instrumentInfo.shortName();
jsonPath = makeIndexFilePath(instrName);
ifstrm.open(jsonPath);
if (!ifstrm.is_open()) {
throw std::invalid_argument("Could not open index file: " + jsonPath);
}
}

// Read directory path from json file
Expand All @@ -39,7 +45,7 @@ std::string Mantid::API::ISISInstrumentDataCache::getFileParentDirectoryPath(con
return dirPath;
}

std::pair<std::string, std::string>
std::pair<Mantid::Kernel::InstrumentInfo, std::string>
Mantid::API::ISISInstrumentDataCache::validateInstrumentAndNumber(const std::string &fileName) const {

// Check if suffix eg. -add is present in filename
Expand All @@ -57,12 +63,18 @@ Mantid::API::ISISInstrumentDataCache::validateInstrumentAndNumber(const std::str
runNumber.erase(0, runNumber.find_first_not_of('0')); // Remove padding zeros

try { // Expand instrument name
instrName = FileFinder::Instance().getInstrument(instrName, false).name();
auto instrumentInfo = FileFinder::Instance().getInstrument(instrName, false);
return std::pair(instrumentInfo, runNumber);

} catch (const Kernel::Exception::NotFoundError &) {
throw std::invalid_argument("Instrument name not recognized.");
}
}

return std::pair(instrName, runNumber);
std::string Mantid::API::ISISInstrumentDataCache::makeIndexFilePath(const std::string &instrumentName) const {
g_log.debug() << "ISISInstrumentDataCache::makeIndexFilePath(" << instrumentName << ")" << std::endl;
std::string indexFilePath = m_dataCachePath + "/" + instrumentName + "/" + instrumentName + "_index.json";
return indexFilePath;
}

std::pair<std::string, std::string>
Expand Down
Loading