82 const std::vector<std::string> validFormats = {
"xml",
"nxs",
"hdf5"};
83 g_log.
debug() <<
"Looking for instrument file for " << instrumentName <<
" that is valid on '" << date <<
"'\n";
85 const std::string instrument(Kernel::ConfigService::Instance().getInstrument(instrumentName).
name());
88 const std::vector<std::string> &directoryNames = Kernel::ConfigService::Instance().getInstrumentDirectories();
91 const std::vector<std::string> matchingFiles =
94 if (!matchingFiles.empty()) {
95 instFile = matchingFiles[0];
96 g_log.
debug() <<
"Instrument file selected is " << instFile <<
'\n';
138 const std::string ext =
".xml";
140 boost::algorithm::ierase_all(filename, ext);
142 const std::string suffixSeperator(
"_Definition");
147 if (
auto sepPos = boost::algorithm::ifind_first(filename, suffixSeperator)) {
148 prefix = std::string(filename.begin(), sepPos.begin());
149 suffix = std::string(sepPos.end(), filename.end());
154 std::filesystem::path directoryPath(dir);
157 std::string fullPathParamIDF = (directoryPath / (prefix +
"_Parameters" + suffix + ext)).string();
159 if (std::filesystem::exists(fullPathParamIDF)) {
160 return fullPathParamIDF;
163 fullPathParamIDF = (directoryPath / (prefix +
"_Parameters" + ext)).string();
164 if (std::filesystem::exists(fullPathParamIDF)) {
165 return fullPathParamIDF;
187 const std::vector<std::string> &fileFormats,
188 const std::vector<std::string> &directoryNames,
189 const std::string &date) {
193 g_log.
debug() <<
"No date specified, using current date and time.\n";
194 const std::string now = Types::Core::DateAndTime::getCurrentTime().toISO8601String();
200 std::stringstream ss;
202 for (
size_t i = 0; i < fileFormats.size(); ++i) {
205 ss << fileFormats[i];
208 const std::string allFileFormats = ss.str();
210 const boost::regex regex(prefix +
".*\\." + allFileFormats, boost::regex_constants::icase);
213 DateAndTime refDate(
"1900-01-31 23:59:00");
215 DateAndTime refDateGoodFile(
"1900-01-31 23:59:00");
219 std::multimap<DateAndTime, std::string, std::greater<DateAndTime>> matchingFiles;
220 bool foundFile =
false;
221 std::string mostRecentFile;
222 for (
const auto &directoryName : directoryNames) {
225 for (
const auto &dir_entry : std::filesystem::directory_iterator(directoryName)) {
227 const auto &filePath = dir_entry.path();
228 if (!std::filesystem::is_regular_file(filePath))
231 const std::string l_filenamePart = filePath.filename().string();
232 if (regex_match(l_filenamePart, regex)) {
233 const std::string pathName = filePath.string();
234 g_log.
debug() <<
"Found file: '" << pathName <<
"'\n";
236 std::string validFrom, validTo;
238 g_log.
debug() <<
"File '" << pathName <<
" valid dates: from '" << validFrom <<
"' to '" << validTo <<
"'\n";
240 DateAndTime to, from;
241 if (validFrom.length() > 0)
242 from.setFromISO8601(validFrom);
245 if (validTo.length() > 0)
246 to.setFromISO8601(validTo);
248 to.setFromISO8601(
"2100-01-01T00:00:00");
250 if (from <=
d &&
d <= to) {
252 matchingFiles.insert(std::pair<DateAndTime, std::string>(from, pathName));
255 if (!foundFile && (from >= refDate)) {
257 mostRecentFile = pathName;
264 std::vector<std::string> pathNames;
265 if (!matchingFiles.empty()) {
266 pathNames.reserve(matchingFiles.size());
268 std::transform(matchingFiles.begin(), matchingFiles.end(), std::back_inserter(pathNames),
269 [](
const auto &elem) { return elem.second; });
271 pathNames.emplace_back(std::move(mostRecentFile));
284 std::string &outValidTo) {
288 myContentHandler conHand;
289 pParser.setContentHandler(&conHand);
292 pParser.parse(IDFfilename);
293 }
catch (
const DummyException &e) {
294 outValidFrom = e.m_validFrom;
295 outValidTo = e.m_validTo;
static std::vector< std::string > getResourceFilenames(const std::string &prefix, const std::vector< std::string > &fileFormats, const std::vector< std::string > &directoryNames, const std::string &date)
Utility to retrieve a resource file (IDF, Parameters, ..)