84 const std::vector<std::string> validFormats = {
"xml",
"nxs",
"hdf5"};
85 g_log.
debug() <<
"Looking for instrument file for " << instrumentName <<
" that is valid on '" << date <<
"'\n";
87 const std::string instrument(Kernel::ConfigService::Instance().getInstrument(instrumentName).
name());
90 const std::vector<std::string> &directoryNames = Kernel::ConfigService::Instance().getInstrumentDirectories();
93 const std::vector<std::string> matchingFiles =
96 if (!matchingFiles.empty()) {
97 instFile = matchingFiles[0];
98 g_log.
debug() <<
"Instrument file selected is " << instFile <<
'\n';
100 g_log.
debug() <<
"No instrument file found\n";
140 const std::string ext =
".xml";
142 boost::algorithm::ierase_all(filename, ext);
144 const std::string suffixSeperator(
"_Definition");
149 if (
auto sepPos = boost::algorithm::ifind_first(filename, suffixSeperator)) {
150 prefix = std::string(filename.begin(), sepPos.begin());
151 suffix = std::string(sepPos.end(), filename.end());
156 Poco::Path directoryPath(dir);
157 directoryPath.makeDirectory();
160 std::string fullPathParamIDF = directoryPath.setFileName(prefix +
"_Parameters" + suffix + ext).toString();
162 if (Poco::File(fullPathParamIDF).
exists()) {
163 return fullPathParamIDF;
166 fullPathParamIDF = directoryPath.setFileName(prefix +
"_Parameters" + ext).toString();
167 if (Poco::File(fullPathParamIDF).
exists()) {
168 return fullPathParamIDF;
190 const std::vector<std::string> &fileFormats,
191 const std::vector<std::string> &directoryNames,
192 const std::string &date) {
196 g_log.
debug() <<
"No date specified, using current date and time.\n";
197 const std::string now = Types::Core::DateAndTime::getCurrentTime().toISO8601String();
203 std::stringstream ss;
205 for (
size_t i = 0; i < fileFormats.size(); ++i) {
208 ss << fileFormats[i];
211 const std::string allFileFormats = ss.str();
213 const boost::regex regex(prefix +
".*\\." + allFileFormats, boost::regex_constants::icase);
214 Poco::DirectoryIterator end_iter;
217 DateAndTime refDate(
"1900-01-31 23:59:00");
219 DateAndTime refDateGoodFile(
"1900-01-31 23:59:00");
223 std::multimap<DateAndTime, std::string, std::greater<DateAndTime>> matchingFiles;
224 bool foundFile =
false;
225 std::string mostRecentFile;
226 for (
const auto &directoryName : directoryNames) {
229 for (Poco::DirectoryIterator dir_itr(directoryName); dir_itr != end_iter; ++dir_itr) {
231 const auto &filePath = dir_itr.path();
232 if (!filePath.isFile())
235 const std::string &l_filenamePart = filePath.getFileName();
236 if (regex_match(l_filenamePart, regex)) {
237 const auto &pathName = filePath.toString();
238 g_log.
debug() <<
"Found file: '" << pathName <<
"'\n";
240 std::string validFrom, validTo;
242 g_log.
debug() <<
"File '" << pathName <<
" valid dates: from '" << validFrom <<
"' to '" << validTo <<
"'\n";
244 DateAndTime to, from;
245 if (validFrom.length() > 0)
246 from.setFromISO8601(validFrom);
249 if (validTo.length() > 0)
250 to.setFromISO8601(validTo);
252 to.setFromISO8601(
"2100-01-01T00:00:00");
254 if (from <=
d &&
d <= to) {
256 matchingFiles.insert(std::pair<DateAndTime, std::string>(from, pathName));
259 if (!foundFile && (from >= refDate)) {
261 mostRecentFile = pathName;
268 std::vector<std::string> pathNames;
269 if (!matchingFiles.empty()) {
270 pathNames.reserve(matchingFiles.size());
272 std::transform(matchingFiles.begin(), matchingFiles.end(), std::back_inserter(pathNames),
273 [](
const auto &elem) { return elem.second; });
275 pathNames.emplace_back(std::move(mostRecentFile));
288 std::string &outValidTo) {
292 myContentHandler conHand;
293 pParser.setContentHandler(&conHand);
296 pParser.parse(IDFfilename);
297 }
catch (
const DummyException &e) {
298 outValidFrom = e.m_validFrom;
299 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, ..)