Mantid
|
This class finds data files given an instrument name (optionally) and a run number. More...
#include <FileFinder.h>
Public Member Functions | |
std::string | findRun (const std::string &hintstr, const std::vector< std::string > &exts={}, const bool useExtsOnly=false) const |
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. More... | |
std::vector< IArchiveSearch_sptr > | getArchiveSearch (const Kernel::FacilityInfo &facility) const |
bool | getCaseSensitive () const |
Option to get if file finder should be case sensitive. More... | |
std::string | getExtension (const std::string &filename, const std::vector< std::string > &exts) const |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY. More... | |
std::string | getFullPath (const std::string &filename, const bool ignoreDirs=false) const |
Return the full path to the file given its name. More... | |
const Kernel::InstrumentInfo | getInstrument (const std::string &hint) const |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY. More... | |
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. More... | |
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. More... | |
std::string | makeFileName (const std::string &hint, const Kernel::InstrumentInfo &instrument) const |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY. More... | |
void | setCaseSensitive (const bool cs) |
Option to set if file finder should be case sensitive. More... | |
Private Member Functions | |
std::string | extractAllowedSuffix (std::string &userString) const |
Run numbers can be followed by an allowed string. More... | |
FileFinderImpl () | |
Default constructor. More... | |
FileFinderImpl (const FileFinderImpl &) | |
Copy constructor. More... | |
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. More... | |
FileFinderImpl & | operator= (const FileFinderImpl &) |
Assignment operator. More... | |
std::pair< std::string, std::string > | toInstrumentAndNumber (const std::string &hint) const |
Extracts the instrument name and run number from a hint. More... | |
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. More... | |
Private Attributes | |
int | m_globOption |
glob option - set to case sensitive or insensitive More... | |
Static Private Attributes | |
static const std::string | ALLOWED_SUFFIX = "-add" |
a string that is allowed at the end of any run number More... | |
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 65 of file FileFinder.cpp.
References Mantid::Kernel::SingletonHolder< T >::Instance(), m_globOption, and setCaseSensitive().
|
private |
Copy constructor.
|
private |
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 114 of file FileFinder.cpp.
References ALLOWED_SUFFIX.
Referenced by makeFileName().
std::string Mantid::API::FileFinderImpl::findRun | ( | const std::string & | hintstr, |
const std::vector< std::string > & | exts = {} , |
||
const bool | useExtsOnly = false |
||
) | const |
Definition at line 367 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(), and Mantid::Kernel::Strings::strip().
Referenced by findRuns().
std::vector< std::string > Mantid::API::FileFinderImpl::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.
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. |
exts | :: Vector of allowed file extensions. Optional. If provided, this provides the only extensions searched for. If not provided, facility extensions used. |
useExtsOnly | :: 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 527 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 658 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.
Referenced by getPath().
std::vector< IArchiveSearch_sptr > Mantid::API::FileFinderImpl::getArchiveSearch | ( | const Kernel::FacilityInfo & | facility | ) | const |
Definition at line 328 of file FileFinder.cpp.
References Mantid::Kernel::FacilityInfo::archiveSearch(), Mantid::DataObjects::create(), Mantid::Kernel::Logger::debug(), Mantid::API::g_log, Mantid::Kernel::SingletonHolder< T >::Instance(), 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 93 of file FileFinder.cpp.
References 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 300 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 105 of file FileFinder.cpp.
References Mantid::Kernel::SingletonHolder< T >::Instance(), and 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 |
DO NOT USE! MADE PUBLIC FOR TESTING ONLY.
Return the InstrumentInfo as determined from the hint.
hint | :: The name hint. |
Definition at line 137 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, Mantid::Kernel::SingletonHolder< T >::Instance(), and Mantid::Kernel::Exception::NotFoundError::what().
Referenced by findRun().
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 694 of file FileFinder.cpp.
References Mantid::Kernel::Logger::debug(), Mantid::Kernel::Logger::error(), Mantid::API::g_log, getArchivePath(), getFullPath(), and Mantid::Kernel::SingletonHolder< T >::Instance().
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 485 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 256 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 81 of file FileFinder.cpp.
References m_globOption.
Referenced by export_FileFinder(), and FileFinderImpl().
|
private |
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 187 of file FileFinder.cpp.
References Mantid::Kernel::InstrumentInfo::filePrefix(), Mantid::Kernel::SingletonHolder< T >::Instance(), and Mantid::Kernel::InstrumentInfo::zeroPadding().
Referenced by findRuns(), and makeFileName().
|
private |
Definition at line 761 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 506 of file FileFinder.cpp.
Referenced by findRuns().
|
friend |
Definition at line 54 of file FileFinder.h.
|
staticprivate |
a string that is allowed at the end of any run number
Definition at line 60 of file FileFinder.h.
Referenced by extractAllowedSuffix(), and findRuns().
|
private |
glob option - set to case sensitive or insensitive
Definition at line 75 of file FileFinder.h.
Referenced by FileFinderImpl(), getCaseSensitive(), getFullPath(), and setCaseSensitive().