Mantid
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
Mantid::API::FileFinderImpl Class Reference

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_sptrgetArchiveSearch (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
 
FileFinderImploperator= (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 >
 

Detailed Description

This class finds data files given an instrument name (optionally) and a run number.

Author
Roman Tolchenov, Tessella plc
Date
23/07/2010

Definition at line 36 of file FileFinder.h.

Constructor & Destructor Documentation

◆ FileFinderImpl() [1/2]

Mantid::API::FileFinderImpl::FileFinderImpl ( )
private

Default constructor.

Definition at line 69 of file FileFinder.cpp.

References Mantid::Kernel::Glob::GLOB_DEFAULT, m_globOption, and setCaseSensitive().

◆ FileFinderImpl() [2/2]

Mantid::API::FileFinderImpl::FileFinderImpl ( const FileFinderImpl )
private

Copy constructor.

Member Function Documentation

◆ extractAllowedSuffix()

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

Parameters
userStringrun number that may have a suffix
Returns
the suffix, if there was one

Definition at line 118 of file FileFinder.cpp.

References ALLOWED_SUFFIX.

Referenced by makeFileName().

◆ findRun()

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.

Parameters
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.
Returns
A vector of full paths or empty vector

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().

◆ 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.

Parameters
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.
Returns
A vector of full paths or empty vector
Exceptions
std::invalid_argumentif the argument is malformed
Exception::NotFoundErrorif 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().

◆ getArchivePath()

const API::Result< std::string > Mantid::API::FileFinderImpl::getArchivePath ( const std::vector< IArchiveSearch_sptr > &  archs,
const std::set< std::string > &  filenames,
const std::vector< std::string > &  exts 
) const
private

Return the path to the file found in archive.

Parameters
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
Returns
The full path if the file exists and can be found in one of the search locations or an empty string otherwise.

Definition at line 728 of file FileFinder.cpp.

References Mantid::Kernel::Logger::debug(), and Mantid::API::g_log.

Referenced by getPath().

◆ getArchiveSearch()

std::vector< IArchiveSearch_sptr > Mantid::API::FileFinderImpl::getArchiveSearch ( const Kernel::FacilityInfo facility)
static

◆ getCaseSensitive()

bool Mantid::API::FileFinderImpl::getCaseSensitive ( ) const

Option to get if file finder should be case sensitive.

Returns
cs :: If case sensitive return true, if not case sensitive return false

Definition at line 97 of file FileFinder.cpp.

References Mantid::Kernel::Glob::GLOB_DEFAULT, and m_globOption.

Referenced by export_FileFinder(), findRun(), and getUniqueExtensions().

◆ getExtension()

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.

Parameters
filenameThe filename to get the extension from.
extsThe list of extensions to try before giving up and using the default: whatever happens after the '.'.
Returns
The extension. If one isn't determined it is an empty string.

Definition at line 299 of file FileFinder.cpp.

References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and toUpper().

Referenced by findRun().

◆ getFullPath()

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.

Parameters
filename:: A file name (without path) including extension
ignoreDirs:: If true, directories that match are skipped unless the path given is already absolute
Returns
The full path if the file exists and can be found in one of the search locations or an empty string otherwise.

Definition at line 109 of file FileFinder.cpp.

References m_globOption.

Referenced by export_FileFinder(), findRun(), getPath(), and MantidQt::API::FindFilesWorker::run().

◆ getInstrument()

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.

Parameters
hint:: The name hint.
returnDefaultIfNotFound:: Flag to control return. May throw exception if set to false.
Returns
This will return the default instrument if it cannot be determined.

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().

◆ getISISInstrumentDataCachePath()

const API::Result< std::string > Mantid::API::FileFinderImpl::getISISInstrumentDataCachePath ( const std::string &  cachePathToSearch,
const std::set< std::string > &  filenames,
const std::vector< std::string > &  exts 
) const
private

Definition at line 673 of file FileFinder.cpp.

Referenced by getPath().

◆ 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.

Parameters
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
Returns
The full path if the file exists and can be found in one of the search locations or an empty string otherwise.

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().

◆ getUniqueExtensions()

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

Parameters
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().

◆ makeFileName()

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.

Parameters
hint:: The name hint
instrument:: The current instrument object
Returns
The file name
Exceptions
NotFoundErrorif a required default is not set
std::invalid_argumentif 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().

◆ operator=()

FileFinderImpl & Mantid::API::FileFinderImpl::operator= ( const FileFinderImpl )
private

Assignment operator.

◆ setCaseSensitive()

void Mantid::API::FileFinderImpl::setCaseSensitive ( const bool  cs)

Option to set if file finder should be case sensitive.

Parameters
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().

◆ toInstrumentAndNumber()

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.

Parameters
hint:: The name hint
Returns
A pair of instrument name and run number

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().

◆ toUpper()

std::string Mantid::API::FileFinderImpl::toUpper ( const std::string &  src) const
private

Definition at line 852 of file FileFinder.cpp.

Referenced by getExtension().

◆ validateRuns()

std::string Mantid::API::FileFinderImpl::validateRuns ( const std::string &  searchText) const
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.

Parameters
searchText:: The text to validate.
Returns
An error message if something is invalid.

Definition at line 529 of file FileFinder.cpp.

Referenced by findRuns().

Friends And Related Symbol Documentation

◆ Mantid::Kernel::CreateUsingNew< FileFinderImpl >

Definition at line 57 of file FileFinder.h.

Member Data Documentation

◆ ALLOWED_SUFFIX

const std::string Mantid::API::FileFinderImpl::ALLOWED_SUFFIX = "-add"
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().

◆ m_globOption

int Mantid::API::FileFinderImpl::m_globOption
private

glob option - set to case sensitive or insensitive

Definition at line 80 of file FileFinder.h.

Referenced by FileFinderImpl(), getCaseSensitive(), getFullPath(), and setCaseSensitive().


The documentation for this class was generated from the following files: