14#include <json/reader.h>
24 g_log.
debug() <<
"ISISInstrumentDataCache::getFileParentDirectoryPath(" << fileName <<
")" << std::endl;
30 std::string relativePath = json[runNumber].asString();
32 if (relativePath.empty()) {
33 throw std::invalid_argument(
"Run number " + runNumber +
" not found in index file " + jsonPath.filename().string() +
37 std::filesystem::path dirPath = jsonPath.parent_path() / relativePath;
38 std::string dirPathString = dirPath.make_preferred().string();
40 g_log.
debug() <<
"Found path to search: " << dirPathString << std::endl;
51 return json.getMemberNames();
60std::pair<std::filesystem::path, Json::Value>
64 std::ifstream ifstrm{jsonPath};
65 if (!ifstrm.is_open()) {
67 ifstrm.open(jsonPath);
68 if (!ifstrm.is_open()) {
69 throw std::invalid_argument(
"Could not open index file: " + jsonPath.string());
75 g_log.
debug() <<
"Opened instrument index file: " << jsonPath << std::endl;
76 return {jsonPath, json};
79std::pair<InstrumentInfo, std::string>
83 std::string fileNameCopy = fileName;
84 std::string suffix = FileFinder::Instance().extractAllowedSuffix(fileNameCopy);
85 if (!suffix.empty()) {
86 throw std::invalid_argument(
"Unsuported format: Suffix detected: " + suffix);
91 if (runNumber.empty() || !std::all_of(runNumber.begin(), runNumber.end(), ::isdigit)) {
92 throw std::invalid_argument(
"Filename not in correct format.");
94 runNumber.erase(0, runNumber.find_first_not_of(
'0'));
101 auto instrumentInfo = FileFinder::Instance().getInstrument(instName,
false);
102 return instrumentInfo;
104 throw std::invalid_argument(
"Instrument name not recognized.");
109 g_log.
debug() <<
"ISISInstrumentDataCache::makeIndexFilePath(" << instrumentName <<
")" << std::endl;
110 auto const &indexFilePath =
111 std::filesystem::path(
m_dataCachePath) / instrumentName / (instrumentName +
"_index.json");
112 return indexFilePath;
115std::pair<std::string, std::string>
119 const auto itRev = std::find_if(fileName.rbegin(), fileName.rend(), std::not_fn(isdigit));
120 const auto nChars = std::distance(itRev, fileName.rend());
121 std::string runNumber = fileName.substr(nChars);
123 std::string fileNameUpperCase = fileName;
124 std::transform(fileNameUpperCase.begin(), fileNameUpperCase.end(), fileNameUpperCase.begin(), toupper);
125 std::string instrName = fileNameUpperCase.substr(0, nChars);
127 return std::pair(instrName, runNumber);
std::pair< Mantid::Kernel::InstrumentInfo, std::string > validateInstrumentAndNumber(const std::string &filename) const
std::vector< std::string > getRunNumbersInCache(std::string const &instrumentName) const
Get a vector of the run numbers' files present in the given instrument's data cache.
bool isIndexFileAvailable(std::string const &instrument) const
Check if the data cache index file is available on the current system for a given instrument.
std::pair< std::filesystem::path, Json::Value > openCacheJsonFile(const Mantid::Kernel::InstrumentInfo &instrument) const
Open the Json file and return the path and the opened file object.
std::string m_dataCachePath
Mantid::Kernel::InstrumentInfo getInstrumentFromName(const std::string &instName) const
std::string getFileParentDirectoryPath(const std::string &filename) const
std::pair< std::string, std::string > splitIntoInstrumentAndNumber(const std::string &filename) const
std::filesystem::path makeIndexFilePath(const std::string &instrumentName) const
Exception for when an item is not found in a collection.
A class that holds information about an instrument.
const std::string & shortName() const
Return the short name of the instrument.
const std::string & name() const
Return the name of the instrument.
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.
Kernel::Logger g_log("ExperimentInfo")
static logger object
Kernel::Logger g_log("DetermineSpinStateOrder")