Mantid
Loading...
Searching...
No Matches
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 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_sptrgetArchiveSearch (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...
 
FileFinderImploperator= (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 >
 

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 65 of file FileFinder.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), 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
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

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

Definition at line 114 of file FileFinder.cpp.

References ALLOWED_SUFFIX.

Referenced by makeFileName().

◆ findRun()

std::string Mantid::API::FileFinderImpl::findRun ( const std::string &  hintstr,
const std::vector< std::string > &  exts = {},
const bool  useExtsOnly = false 
) const

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

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

◆ getArchivePath()

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 658 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) const

◆ 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 93 of file FileFinder.cpp.

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

◆ getInstrument()

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.

Parameters
hint:: The name hint.
Returns
This will return the default instrument if it cannot be determined.

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

◆ getPath()

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

◆ 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 485 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 256 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 81 of file FileFinder.cpp.

References m_globOption.

Referenced by export_FileFinder(), and FileFinderImpl().

◆ toInstrumentAndNumber()

std::pair< std::string, std::string > Mantid::API::FileFinderImpl::toInstrumentAndNumber ( const std::string &  hint) const
private

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

◆ toUpper()

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

Definition at line 761 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 506 of file FileFinder.cpp.

Referenced by findRuns().

Friends And Related Function Documentation

◆ Mantid::Kernel::CreateUsingNew< FileFinderImpl >

Definition at line 54 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 60 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 75 of file FileFinder.h.

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


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