Skip to content

Commit 98cb2d3

Browse files
authored
Merge pull request #38027 from mantidproject/fix-enginx-data-cache
Fix ENGINX data cache search on IDAaaS
2 parents f50390a + b67e391 commit 98cb2d3

File tree

5 files changed

+33
-17
lines changed

5 files changed

+33
-17
lines changed

Framework/API/inc/MantidAPI/ISISInstrumentDataCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MANTID_API_DLL ISISInstrumentDataCache {
3030
std::pair<Mantid::Kernel::InstrumentInfo, std::string> validateInstrumentAndNumber(const std::string &filename) const;
3131
std::filesystem::path makeIndexFilePath(const std::string &instrumentName) const;
3232
std::pair<std::string, std::string> splitIntoInstrumentAndNumber(const std::string &filename) const;
33-
[[nodiscard]] std::pair<std::string, Json::Value>
33+
[[nodiscard]] std::pair<std::filesystem::path, Json::Value>
3434
openCacheJsonFile(const Mantid::Kernel::InstrumentInfo &instrument) const;
3535
[[nodiscard]] Mantid::Kernel::InstrumentInfo getInstrumentFromName(const std::string &instName) const;
3636
std::string m_dataCachePath;

Framework/API/src/FileFinder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ const API::Result<std::string> FileFinderImpl::getPath(const std::vector<IArchiv
826826
errors += cacheFilePath.errors();
827827

828828
} else {
829-
errors += "Could not find data cache directory: " + cachePathToSearch.string();
829+
g_log.debug() << "Data cache directory not found, proceeding with the search." << std::endl;
830+
errors += "Could not find data cache directory: " + cachePathToSearch.string() + '\n';
830831
}
831832

832833
// Search the archive

Framework/API/src/ISISInstrumentDataCache.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ std::string ISISInstrumentDataCache::getFileParentDirectoryPath(const std::strin
2424
g_log.debug() << "ISISInstrumentDataCache::getFileParentDirectoryPath(" << fileName << ")" << std::endl;
2525

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

2928
auto const [jsonPath, json] = openCacheJsonFile(instrumentInfo);
3029

3130
std::string relativePath = json[runNumber].asString();
3231

3332
if (relativePath.empty()) {
34-
throw std::invalid_argument("Run number " + runNumber + " not found for instrument " + instrName + ".");
33+
throw std::invalid_argument("Run number " + runNumber + " not found in index file " + jsonPath.filename().string() +
34+
".");
3535
}
3636

37-
std::string dirPath = m_dataCachePath + "/" + instrName + "/" + relativePath;
37+
std::filesystem::path dirPath = jsonPath.parent_path() / relativePath;
38+
std::string dirPathString = dirPath.make_preferred().string();
3839

39-
g_log.debug() << "Opened instrument index file: " << jsonPath << ". Found path to search: " << dirPath << "."
40-
<< std::endl;
41-
return dirPath;
40+
g_log.debug() << "Found path to search: " << dirPathString << std::endl;
41+
return dirPathString;
4242
}
4343

4444
/**
@@ -57,7 +57,8 @@ std::vector<std::string> ISISInstrumentDataCache::getRunNumbersInCache(const std
5757
* @return A pair containing the path and the contents of the json file.
5858
* @throws std::invalid_argument if the file could not be found.
5959
*/
60-
std::pair<std::string, Json::Value> ISISInstrumentDataCache::openCacheJsonFile(const InstrumentInfo &instrument) const {
60+
std::pair<std::filesystem::path, Json::Value>
61+
ISISInstrumentDataCache::openCacheJsonFile(const InstrumentInfo &instrument) const {
6162
// Open index json file
6263
std::filesystem::path jsonPath = makeIndexFilePath(instrument.name());
6364
std::ifstream ifstrm{jsonPath};
@@ -71,7 +72,8 @@ std::pair<std::string, Json::Value> ISISInstrumentDataCache::openCacheJsonFile(c
7172
// Read directory path from json file
7273
Json::Value json;
7374
ifstrm >> json;
74-
return {jsonPath.string(), json};
75+
g_log.debug() << "Opened instrument index file: " << jsonPath << std::endl;
76+
return {jsonPath, json};
7577
}
7678

7779
std::pair<InstrumentInfo, std::string>

Framework/API/test/ISISInstrumentDataCacheTest.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ class ISISInstrumentDataCacheTest : public CxxTest::TestSuite {
3131
std::string sansJson = R"({"101115": "2018/RB1800009-2"})";
3232
std::string pg3Json = R"({"11111": "mock/path"})";
3333
std::string wishJson = R"({"12345": "subdir1/subdir2"})";
34+
std::string enginxJson = R"({"55555": "subdir1/subdir2"})";
3435

35-
// Create test JSON file
3636
std::filesystem::create_directory(m_dataCacheDir);
3737

3838
std::unordered_map<std::string, std::string> instrFiles = {
39-
{"MARI", marJson}, {"SANS2D", sansJson}, {"POWGEN", pg3Json}, {"WISH", wishJson}};
39+
{"MARI", marJson}, {"SANS2D", sansJson}, {"POWGEN", pg3Json}, {"WISH", wishJson}, {"ENGINX", enginxJson}};
4040
for (const auto &[instrName, instrIndex] : instrFiles) {
4141

4242
std::filesystem::create_directory(m_dataCacheDir + "/" + instrName);
@@ -56,26 +56,38 @@ class ISISInstrumentDataCacheTest : public CxxTest::TestSuite {
5656
void testInstrNameExpanded() {
5757
ISISInstrumentDataCache dc(m_dataCacheDir);
5858
std::string actualPath = dc.getFileParentDirectoryPath("MAR25054");
59-
TS_ASSERT_EQUALS(actualPath, m_dataCacheDir + "/MARI/2019/RB1868000-1");
59+
std::filesystem::path expectedPath = m_dataCacheDir + "/MARI/2019/RB1868000-1";
60+
TS_ASSERT_EQUALS(actualPath, expectedPath.make_preferred().string());
6061
}
6162

6263
void testLowerCaseInstrName() {
6364
ISISInstrumentDataCache dc(m_dataCacheDir);
6465
std::string actualPath = dc.getFileParentDirectoryPath("mar25054");
65-
TS_ASSERT_EQUALS(actualPath, m_dataCacheDir + "/MARI/2019/RB1868000-1");
66+
std::filesystem::path expectedPath = m_dataCacheDir + "/MARI/2019/RB1868000-1";
67+
TS_ASSERT_EQUALS(actualPath, expectedPath.make_preferred().string());
6668
}
6769

6870
void testCorrectInstrRunSplit() {
6971
ISISInstrumentDataCache dc(m_dataCacheDir);
7072
std::string actualPath = dc.getFileParentDirectoryPath("SANS2D101115");
71-
TS_ASSERT_EQUALS(actualPath, m_dataCacheDir + "/SANS2D/2018/RB1800009-2");
73+
std::filesystem::path expectedPath = m_dataCacheDir + "/SANS2D/2018/RB1800009-2";
74+
TS_ASSERT_EQUALS(actualPath, expectedPath.make_preferred().string());
7275
}
7376

7477
void testInstrWithDelimiter() {
7578
// Checks short name + delimiter gets correctly identified
7679
ISISInstrumentDataCache dc(m_dataCacheDir);
7780
std::string actualPath = dc.getFileParentDirectoryPath("PG3_11111");
78-
TS_ASSERT_EQUALS(actualPath, m_dataCacheDir + "/POWGEN/mock/path");
81+
std::filesystem::path expectedPath = m_dataCacheDir + "/POWGEN/mock/path";
82+
TS_ASSERT_EQUALS(actualPath, expectedPath.make_preferred().string());
83+
}
84+
85+
void testShortNameIsTried() {
86+
// Name ENGIN-X is tried first and if it fails it tries ENGINX
87+
ISISInstrumentDataCache dc(m_dataCacheDir);
88+
std::string actualPath = dc.getFileParentDirectoryPath("ENGINX55555");
89+
std::filesystem::path expectedPath = m_dataCacheDir + "/ENGINX/subdir1/subdir2";
90+
TS_ASSERT_EQUALS(actualPath, expectedPath.make_preferred().string());
7991
}
8092

8193
void testInstrWithSuffix() {
@@ -106,7 +118,7 @@ class ISISInstrumentDataCacheTest : public CxxTest::TestSuite {
106118
void testRunNumberNotFound() {
107119
ISISInstrumentDataCache dc(m_dataCacheDir);
108120
TS_ASSERT_THROWS_EQUALS(dc.getFileParentDirectoryPath("SANS2D1234"), const std::invalid_argument &e,
109-
std::string(e.what()), "Run number 1234 not found for instrument SANS2D.");
121+
std::string(e.what()), "Run number 1234 not found in index file SANS2D_index.json.");
110122
}
111123

112124
void testIndexFileExistsWhenExists() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Loading ``ENGIN-X`` data on IDAaaS from the instrument data cache no longer throws a "path not found" error.

0 commit comments

Comments
 (0)