Mantid
Loading...
Searching...
No Matches
FileFinder.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidAPI/DllConfig.h"
15
16#include <filesystem>
17#include <set>
18#include <vector>
19
20// Forward declaration so the test class can be granted friend access without
21// pulling its header into this one.
22class FileFinderISISInstrumentDataCacheTest;
23
24namespace Mantid {
25//---------------------------------------------------------------------------
26// Forward declarations
27//---------------------------------------------------------------------------
28namespace Kernel {
29class InstrumentInfo;
30class FacilityInfo;
31} // namespace Kernel
32namespace API {
33
41class MANTID_API_DLL FileFinderImpl {
42 friend class ::FileFinderISISInstrumentDataCacheTest;
43
44public:
45 std::filesystem::path getFullPath(const std::string &filename, const bool ignoreDirs = false) const;
46 std::string extractAllowedSuffix(std::string &userString) const;
48 std::string makeFileName(const std::string &hintstr, const Kernel::InstrumentInfo &instrument) const;
49 void setCaseSensitive(const bool cs);
50 bool getCaseSensitive() const;
51 static std::vector<IArchiveSearch_sptr> getArchiveSearch(const Kernel::FacilityInfo &facility);
53 findRun(const std::string &hintstr, const std::vector<std::string> &exts = {}, const bool useExtsOnly = false) const;
54 std::vector<std::filesystem::path> findRuns(const std::string &hintstr, const std::vector<std::string> &exts = {},
55 const bool useExtsOnly = false) const;
56 std::vector<std::filesystem::path> findRuns(const std::vector<std::string> &hints,
57 const std::vector<std::string> &exts = {},
58 const bool useExtsOnly = false) const;
59
63 std::filesystem::path tryResolvePathWithExtension(const std::string &filename) const;
65 const Kernel::InstrumentInfo getInstrument(const std::string &hintstr, const bool returnDefaultIfNotFound = true,
66 const std::string &defaultInstrument = "") const;
68 std::string getExtension(const std::string &filename, const std::vector<std::string> &exts) const;
69 void getUniqueExtensions(const std::vector<std::string> &extensionsToAdd, std::vector<std::string> &uniqueExts) const;
70 std::pair<std::string, std::string> toInstrumentAndNumber(const std::string &hintstr,
71 const std::string &defaultInstrument = "") const;
72 std::pair<std::string, std::string> toInstrumentAndNumber(const std::string &hintstr,
73 const Kernel::InstrumentInfo &instrument) const;
74
75private:
77
79 struct FileInfo {
80 std::string hint{};
81 bool found{false};
82 std::filesystem::path path{};
83 std::shared_ptr<Mantid::Kernel::InstrumentInfo> instr{};
84 bool error{false};
85 std::string errorMsg{};
86 std::set<std::string> filenames{};
87 std::vector<std::string> extensionsToSearch{};
88 std::vector<Mantid::API::IArchiveSearch_sptr> archs{};
89 };
90
91 void performCacheSearch(std::vector<FileInfo> &fileInfos) const;
92
94 static const std::string ALLOWED_SUFFIX;
102 std::string validateRuns(const std::string &searchText) const;
105 bool isMalformedRange(const std::string &token) const;
106 void prepareFileInfo(FileInfo &fileInfo, const std::vector<std::string> &extensionsProvided,
107 bool useOnlyExtensionsProvided) const;
108 void processFileInfos(std::vector<FileInfo> &fileInfos, const std::vector<std::string> &extensionsProvided,
109 bool useOnlyExtensionsProvided) const;
110 void performFileSearch(std::vector<FileInfo> &fileInfos) const;
111 void performArchiveSearch(std::vector<FileInfo> &fileInfos) const;
112 void performBatchedArchiveSearch(std::vector<FileInfo> &fileInfos, const IArchiveSearch_sptr &sharedArch) const;
113 void performPerFileArchiveSearch(std::vector<FileInfo> &fileInfos) const;
117 static IArchiveSearch_sptr batchableArchive(const std::vector<FileInfo> &fileInfos);
118 const API::Result<std::filesystem::path> getISISInstrumentDataCachePath(const std::filesystem::path &cacheDir,
119 const std::set<std::string> &hintstrs,
120 const std::vector<std::string> &exts) const;
121 const API::Result<std::filesystem::path> getArchivePath(const std::vector<IArchiveSearch_sptr> &archs,
122 const std::set<std::string> &hintstrs,
123 const std::vector<std::string> &exts) const;
126};
127
129} // namespace API
130} // namespace Mantid
131
132namespace Mantid {
133namespace Kernel {
134EXTERN_MANTID_API template class MANTID_API_DLL Mantid::Kernel::SingletonHolder<Mantid::API::FileFinderImpl>;
135}
136} // namespace Mantid
double error
This class finds data files given an instrument name (optionally) and a run number.
Definition FileFinder.h:41
FileFinderImpl(const FileFinderImpl &)
Copy constructor.
int m_globOption
glob option - set to case sensitive or insensitive
Definition FileFinder.h:125
FileFinderImpl & operator=(const FileFinderImpl &)
Assignment operator.
static const std::string ALLOWED_SUFFIX
a string that is allowed at the end of any run number
Definition FileFinder.h:94
A class that holds information about a facility.
A class that holds information about an instrument.
Manage the lifetime of a class intended to be a singleton.
std::shared_ptr< IArchiveSearch > IArchiveSearch_sptr
Typedef for a shared pointer to an IArchiveSearch.
Mantid::Kernel::SingletonHolder< FileFinderImpl > FileFinder
Definition FileFinder.h:128
Helper class which provides the Collimation Length for SANS instruments.
Per-hint state threaded through the file-search pipeline.
Definition FileFinder.h:79
Policy class controlling creation of the singleton Implementation classes should mark their default c...