|
Mantid
|
This class finds data files given an instrument name (optionally) and a run number. More...
#include <FileFinder.h>
Public Member Functions | |
| std::string | extractAllowedSuffix (std::string &userString) const |
| Run numbers can be followed by an allowed string. | |
| const API::Result< std::string > | findRun (const std::string &hintstr, const std::vector< std::string > &exts={}, const bool useExtsOnly=false) const |
| Find a path to a single file from a hint. | |
| std::vector< std::string > | findRuns (const std::string &hintstr, const std::vector< std::string > &exts={}, const bool useExtsOnly=false) const |
| Find a list of files file given a hint. | |
| bool | getCaseSensitive () const |
| Option to get if file finder should be case sensitive. | |
| std::string | getExtension (const std::string &filename, const std::vector< std::string > &exts) const |
| DO NOT USE! MADE PUBLIC FOR TESTING ONLY. | |
| std::string | getFullPath (const std::string &filename, const bool ignoreDirs=false) const |
| Return the full path to the file given its name. | |
| const Kernel::InstrumentInfo | getInstrument (const std::string &hint, const bool returnDefaultIfNotFound=true) const |
| DO NOT USE! MADE PUBLIC FOR TESTING ONLY. | |
| const API::Result< std::string > | getPath (const std::vector< IArchiveSearch_sptr > &archs, const std::set< std::string > &filenames, const std::vector< std::string > &exts) const |
| Return the full path to the file given its name, checking local directories first. | |
| void | getUniqueExtensions (const std::vector< std::string > &extensionsToAdd, std::vector< std::string > &uniqueExts) const |
| Given a set of already determined extensions and new extensions, create a set of all extensions. | |
| std::string | makeFileName (const std::string &hint, const Kernel::InstrumentInfo &instrument) const |
| DO NOT USE! MADE PUBLIC FOR TESTING ONLY. | |
| void | setCaseSensitive (const bool cs) |
| Option to set if file finder should be case sensitive. | |
| std::pair< std::string, std::string > | toInstrumentAndNumber (const std::string &hint) const |
| Extracts the instrument name and run number from a hint. | |
Static Public Member Functions | |
| static std::vector< IArchiveSearch_sptr > | getArchiveSearch (const Kernel::FacilityInfo &facility) |
Private Member Functions | |
| FileFinderImpl () | |
| Default constructor. | |
| FileFinderImpl (const FileFinderImpl &) | |
| Copy constructor. | |
| const API::Result< std::string > | getArchivePath (const std::vector< IArchiveSearch_sptr > &archs, const std::set< std::string > &filenames, const std::vector< std::string > &exts) const |
| Return the path to the file found in archive. | |
| const API::Result< std::string > | getISISInstrumentDataCachePath (const std::string &cachePathToSearch, const std::set< std::string > &filenames, const std::vector< std::string > &exts) const |
| FileFinderImpl & | operator= (const FileFinderImpl &) |
| Assignment operator. | |
| std::string | toUpper (const std::string &src) const |
| std::string | validateRuns (const std::string &searchText) const |
| A method that returns error messages if the provided runs are invalid. | |
Private Attributes | |
| int | m_globOption |
| glob option - set to case sensitive or insensitive | |
Static Private Attributes | |
| static const std::string | ALLOWED_SUFFIX = "-add" |
| a string that is allowed at the end of any run number | |
Friends | |
| struct | Mantid::Kernel::CreateUsingNew< FileFinderImpl > |
This class finds data files given an instrument name (optionally) and a run number.
Definition at line 36 of file FileFinder.h.
|
private |
Default constructor.
Definition at line 69 of file FileFinder.cpp.
References Mantid::Kernel::Glob::GLOB_DEFAULT, m_globOption, and setCaseSensitive().
|
private |
Copy constructor.
| std::string Mantid::API::FileFinderImpl::extractAllowedSuffix | ( | std::string & | userString | ) | const |
Run numbers can be followed by an allowed string.
Check if there is one, remove it from the name and return the string, else return empty
| userString | run number that may have a suffix |
Definition at line 118 of file FileFinder.cpp.
References ALLOWED_SUFFIX.
Referenced by makeFileName().
| const API::Result< std::string > Mantid::API::FileFinderImpl::findRun | ( | const std::string & | hintstr, |
| const std::vector< std::string > & | extensionsProvided = {}, |
||
| const bool | useOnlyExtensionsProvided = false |
||
| ) | const |
Find a path to a single file from a hint.
| hintstr | :: hint string to look for filename. |
| extensionsProvided | :: Vector of aditional file extensions to consider. Optional. If not provided, facility extensions used. |
| useOnlyExtensionsProvided | :: Optional bool. If it's true (and extensionsProvided is not empty), search for the file using extensionsProvided only. If it's false, use extensionsProvided AND facility extensions. |
Definition at line 377 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::DataHandling::exists(), Mantid::Kernel::FacilityInfo::extensions(), Mantid::Kernel::InstrumentInfo::facility(), Mantid::API::g_log, getArchiveSearch(), getCaseSensitive(), getExtension(), getFullPath(), getInstrument(), getPath(), getUniqueExtensions(), Mantid::Kernel::Logger::information(), makeFileName(), Mantid::Kernel::FacilityInfo::noFilePrefix(), Mantid::Kernel::Strings::strip(), and Mantid::Kernel::Logger::warning().
Referenced by findRuns().
| std::vector< std::string > Mantid::API::FileFinderImpl::findRuns | ( | const std::string & | hintstr, |
| const std::vector< std::string > & | extensionsProvided = {}, |
||
| const bool | useOnlyExtensionsProvided = false |
||
| ) | const |
Find a list of files file given a hint.
Calls findRun internally.
| hintstr | :: Comma separated list of hints to findRun method. Can also include ranges of runs, e.g. 123-135 or equivalently 123-35. Only the beginning of a range can contain an instrument name. |
| extensionsProvided | :: Vector of allowed file extensions. Optional. If provided, this provides the only extensions searched for. If not provided, facility extensions used. |
| useOnlyExtensionsProvided,: | Optional bool. If it's true (and exts is not empty), search the for the file using exts only. If it's false, use exts AND facility extensions. |
| std::invalid_argument | if the argument is malformed |
| Exception::NotFoundError | if a file could not be found |
Definition at line 550 of file FileFinder.cpp.
References ALLOWED_SUFFIX, Mantid::Kernel::StringTokenizer::begin(), Mantid::Kernel::StringTokenizer::count(), Mantid::Kernel::Logger::debug(), Mantid::Kernel::StringTokenizer::end(), error, findRun(), Mantid::API::g_log, Mantid::Kernel::StringTokenizer::size(), Mantid::Kernel::Strings::strip(), std::to_string(), toInstrumentAndNumber(), Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY, Mantid::Kernel::StringTokenizer::TOK_TRIM, and validateRuns().
Referenced by MantidQt::API::FindFilesWorker::run().
|
private |
Return the path to the file found in archive.
| archs | :: A list of archives to search |
| filenames | :: A list of filenames (without extensions) to pass to the archive |
| exts | :: A list of extensions to check for in turn against each file |
Definition at line 728 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.
Referenced by getPath().
|
static |
Definition at line 327 of file FileFinder.cpp.
References Mantid::Kernel::FacilityInfo::archiveSearch(), Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and Mantid::Kernel::FacilityInfo::name().
Referenced by findRun().
| bool Mantid::API::FileFinderImpl::getCaseSensitive | ( | ) | const |
Option to get if file finder should be case sensitive.
Definition at line 97 of file FileFinder.cpp.
References Mantid::Kernel::Glob::GLOB_DEFAULT, and m_globOption.
Referenced by export_FileFinder(), findRun(), and getUniqueExtensions().
| std::string Mantid::API::FileFinderImpl::getExtension | ( | const std::string & | filename, |
| const std::vector< std::string > & | exts | ||
| ) | const |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY.
Determine the extension from a filename.
| filename | The filename to get the extension from. |
| exts | The list of extensions to try before giving up and using the default: whatever happens after the '.'. |
Definition at line 299 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and toUpper().
Referenced by findRun().
| std::string Mantid::API::FileFinderImpl::getFullPath | ( | const std::string & | filename, |
| const bool | ignoreDirs = false |
||
| ) | const |
Return the full path to the file given its name.
| filename | :: A file name (without path) including extension |
| ignoreDirs | :: If true, directories that match are skipped unless the path given is already absolute |
Definition at line 109 of file FileFinder.cpp.
References m_globOption.
Referenced by export_FileFinder(), findRun(), getPath(), and MantidQt::API::FindFilesWorker::run().
| const Kernel::InstrumentInfo Mantid::API::FileFinderImpl::getInstrument | ( | const std::string & | hint, |
| const bool | returnDefaultIfNotFound = true |
||
| ) | const |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY.
Return the InstrumentInfo as determined from the hint.
| hint | :: The name hint. |
| returnDefaultIfNotFound | :: Flag to control return. May throw exception if set to false. |
Definition at line 142 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and Mantid::Kernel::Exception::NotFoundError::what().
Referenced by findRun().
|
private |
Definition at line 673 of file FileFinder.cpp.
Referenced by getPath().
| const API::Result< std::string > Mantid::API::FileFinderImpl::getPath | ( | const std::vector< IArchiveSearch_sptr > & | archs, |
| const std::set< std::string > & | filenames, | ||
| const std::vector< std::string > & | exts | ||
| ) | const |
Return the full path to the file given its name, checking local directories first.
| archs | :: A list of archives to search |
| filenames | :: A list of filenames (without extensions) to pass to the archive |
| exts | :: A list of extensions to check for in turn against each file |
Definition at line 765 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::Kernel::Logger::error(), Mantid::API::Result< T >::errors(), Mantid::API::g_log, getArchivePath(), getFullPath(), and getISISInstrumentDataCachePath().
Referenced by findRun().
| void Mantid::API::FileFinderImpl::getUniqueExtensions | ( | const std::vector< std::string > & | extensionsToAdd, |
| std::vector< std::string > & | uniqueExts | ||
| ) | const |
Given a set of already determined extensions and new extensions, create a set of all extensions.
If not in an extension-is-case-sensitive environment, only add the lower case OR upper case version of the extension
| extensionsToAdd | :: a vector of extensions to add |
| uniqueExts | :: a vector of currently included extensions |
Definition at line 508 of file FileFinder.cpp.
References getCaseSensitive().
Referenced by findRun().
| std::string Mantid::API::FileFinderImpl::makeFileName | ( | const std::string & | hint, |
| const Kernel::InstrumentInfo & | instrument | ||
| ) | const |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY.
Make a data file name (without extension) from a hint.
The hint can be either a run number or a run number prefixed with an instrument name/short name. If the instrument name is absent the default one is used.
| hint | :: The name hint |
| instrument | :: The current instrument object |
| NotFoundError | if a required default is not set |
| std::invalid_argument | if the argument is malformed or run number is too long |
Definition at line 265 of file FileFinder.cpp.
References Mantid::Kernel::InstrumentInfo::delimiter(), extractAllowedSuffix(), Mantid::Kernel::InstrumentInfo::shortName(), and toInstrumentAndNumber().
Referenced by findRun().
|
private |
Assignment operator.
| void Mantid::API::FileFinderImpl::setCaseSensitive | ( | const bool | cs | ) |
Option to set if file finder should be case sensitive.
| cs | :: If true then set to case sensitive |
Definition at line 85 of file FileFinder.cpp.
References Mantid::Kernel::Glob::GLOB_CASELESS, Mantid::Kernel::Glob::GLOB_DEFAULT, and m_globOption.
Referenced by export_FileFinder(), and FileFinderImpl().
| std::pair< std::string, std::string > Mantid::API::FileFinderImpl::toInstrumentAndNumber | ( | const std::string & | hint | ) | const |
Extracts the instrument name and run number from a hint.
| hint | :: The name hint |
Find the last non-digit as the instrument name can contain numbers
Definition at line 196 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::Kernel::InstrumentInfo::filePrefix(), Mantid::API::g_log, and Mantid::Kernel::InstrumentInfo::zeroPadding().
Referenced by findRuns(), and makeFileName().
|
private |
Definition at line 852 of file FileFinder.cpp.
Referenced by getExtension().
|
private |
A method that returns error messages if the provided runs are invalid.
Performs validation on the search text entered into the File Finder.
It will return an error message if a problem is found.
| searchText | :: The text to validate. |
Definition at line 529 of file FileFinder.cpp.
Referenced by findRuns().
|
friend |
Definition at line 57 of file FileFinder.h.
|
staticprivate |
a string that is allowed at the end of any run number
Definition at line 63 of file FileFinder.h.
Referenced by extractAllowedSuffix(), and findRuns().
|
private |
glob option - set to case sensitive or insensitive
Definition at line 80 of file FileFinder.h.
Referenced by FileFinderImpl(), getCaseSensitive(), getFullPath(), and setCaseSensitive().