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

A property to allow a user to specify multiple files to load. More...

#include <MultipleFileProperty.h>

Inheritance diagram for Mantid::API::MultipleFileProperty:
Mantid::Kernel::PropertyWithValue< std::vector< std::vector< std::string > > > Mantid::Kernel::Property

Public Member Functions

MultipleFilePropertyclone () const override
 'Virtual copy constructor' More...
 
std::string getDefault () const override
 Get the value the property was initialised with -its default value. More...
 
std::string getDefaultExt () const
 Returns the main file extension that's used. More...
 
std::vector< std::string > getExts () const
 
bool isOptional () const
 Check if this property is optional. More...
 
 MultipleFileProperty (const MultipleFileProperty &)=default
 
 MultipleFileProperty (const std::string &name, const std::vector< std::string > &exts=std::vector< std::string >())
 Default constructor with default action. More...
 
 MultipleFileProperty (const std::string &name, unsigned int action, const std::vector< std::string > &exts=std::vector< std::string >(), bool allowEmptyTokens=false)
 Alternative constructor with action. More...
 
MultipleFilePropertyoperator= (const MultipleFileProperty &)=default
 
std::string setValue (const std::string &propValue) override
 Convert the given propValue into a comma and plus separated list of full filenames, and pass to the parent's setValue method to store as a vector of vector of strings. More...
 
std::string value () const override
 Returns the value of the property as a string. More...
 
- Public Member Functions inherited from Mantid::Kernel::PropertyWithValue< std::vector< std::vector< std::string > > >
std::vector< std::string > allowedValues () const override
 Returns the set of valid values for this property, if such a set exists. More...
 
PropertyWithValue< std::vector< std::vector< std::string > > > * clone () const override
 'Virtual copy constructor' More...
 
std::string getDefault () const override
 Get the default value for the property which is the value the property was initialised with. More...
 
IValidator_sptr getValidator () const
 
bool isDefault () const override
 Overriden function that returns if property has the same value that it was initialised with, if applicable. More...
 
bool isMultipleSelectionAllowed () override
 Is Multiple Selection Allowed. More...
 
std::string isValid () const override
 Overridden function that checks whether the property, if not overriden returns "". More...
 
virtual operator const std::vector< std::vector< std::string > > & () const
 
bool operator!= (const PropertyWithValue< std::vector< std::vector< std::string > > > &rhs) const
 
virtual const std::vector< std::vector< std::string > > & operator() () const
 
PropertyWithValueoperator+= (Property const *right) override
 Add to this. More...
 
PropertyWithValueoperator= (const PropertyWithValue &right)
 
virtual PropertyWithValueoperator= (const std::vector< std::vector< std::string > > &value)
 
bool operator== (const PropertyWithValue< std::vector< std::vector< std::string > > > &rhs) const
 
 PropertyWithValue (const PropertyWithValue< std::vector< std::vector< std::string > > > &right)
 
 PropertyWithValue (const std::string &name, std::vector< std::vector< std::string > > defaultValue, const std::string &defaultValueStr, IValidator_sptr validator, const unsigned int direction)
 
 PropertyWithValue (std::string name, std::vector< std::vector< std::string > > defaultValue, const unsigned int direction)
 
 PropertyWithValue (std::string name, std::vector< std::vector< std::string > > defaultValue, IValidator_sptr validator=IValidator_sptr(new NullValidator), const unsigned int direction=Direction::Input)
 
virtual void replaceValidator (IValidator_sptr newValidator)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
MANTID_KERNEL_DLL void saveProperty (::NeXus::File *file)
 
void saveProperty (::NeXus::File *file) override
 
std::string setDataItem (const std::shared_ptr< DataItem > &data) override
 Set the value of the property via a DataItem pointer. More...
 
std::string setValue (const std::string &value) override
 Set the value of the property via a string. More...
 
std::string setValueFromJson (const Json::Value &value) override
 Set the value of the property via a Json object. More...
 
int size () const override
 Return the size of this property. More...
 
std::string value () const override
 Returns the value of the property as a string. More...
 
Json::Value valueAsJson () const override
 Returns the value of the property as a Json::Value. More...
 
std::string valueAsPrettyStr (const size_t maxLength=0, const bool collapseLists=true) const override
 Returns the value of the property as a pretty printed string. More...
 
- Public Member Functions inherited from Mantid::Kernel::Property
virtual std::vector< std::string > allowedValues () const
 Returns the set of valid values for this property, if such a set exists. More...
 
bool autoTrim () const
 Returns if the property is set to automatically trim string unput values of whitespace. More...
 
void clearSettings ()
 Deletes the PropertySettings object contained. More...
 
virtual Propertyclone () const =0
 'Virtual copy constructor' More...
 
virtual const PropertyHistory createHistory () const
 Create a PropertyHistory object representing the current state of the Property. More...
 
void createTemporaryValue ()
 Create a temporary value for this property. More...
 
unsigned int direction () const
 returns the direction of the property More...
 
const std::string & documentation () const
 Get the property's documentation string. More...
 
virtual void filterByTime (const Types::Core::DateAndTime &start, const Types::Core::DateAndTime &stop)
 Filter out a property by time. More...
 
virtual std::string getDefault () const =0
 Get the default value for the property which is the value the property was initialised with. More...
 
const std::string & getGroup ()
 
virtual size_t getMemorySize () const
 
IPropertySettingsgetSettings ()
 
bool hasTemporaryValue () const
 Property is using a temporary value for this property. More...
 
virtual bool isDefault () const =0
 Overriden function that returns if property has the same value that it was initialised with, if applicable. More...
 
virtual bool isMultipleSelectionAllowed ()
 Is Multiple Selection Allowed. More...
 
virtual std::string isValid () const
 Overridden function that checks whether the property, if not overriden returns "". More...
 
virtual bool isValueSerializable () const
 Whether the string returned by value() can be used for serialization. More...
 
virtual Propertymerge (Property *)
 Just returns the property (*this) unless overridden. More...
 
const std::string & name () const
 Get the property's name. More...
 
virtual Propertyoperator+= (Property const *rhs)=0
 Add to this. More...
 
bool remember () const
 Whether to save input values. More...
 
virtual void saveProperty (::NeXus::File *)
 
void setAutoTrim (const bool &setting)
 Sets if the property is set to automatically trim string unput values of whitespace. More...
 
virtual std::string setDataItem (const std::shared_ptr< DataItem > &)=0
 Set the value of the property via a DataItem pointer. More...
 
void setDocumentation (const std::string &documentation)
 Sets the user level description of the property. More...
 
void setGroup (const std::string &group)
 Set the group this property belongs to. More...
 
void setRemember (bool)
 Set wheter to remeber this property input. More...
 
void setSettings (std::unique_ptr< IPropertySettings > settings)
 Set the PropertySettings object. More...
 
virtual void setUnits (const std::string &unit)
 Sets the units of the property, as a string. More...
 
virtual std::string setValue (const std::string &)=0
 Set the value of the property via a string. More...
 
virtual std::string setValueFromJson (const Json::Value &)=0
 Set the value of the property via a Json object. More...
 
virtual std::string setValueFromProperty (const Property &right)=0
 Set the value of the property via a reference to another property. More...
 
virtual int size () const
 Return the size of this property. More...
 
virtual void splitByTime (std::vector< SplittingInterval > &splitter, std::vector< Property * > outputs, bool isProtonCharge=true) const
 Split a property by time. More...
 
const std::string type () const
 Returns the type of the property as a string. More...
 
const std::type_info * type_info () const
 Get the property type_info. More...
 
virtual const std::string & units () const
 Returns the units of the property, if any, as a string. More...
 
virtual std::string value () const =0
 Returns the value of the property as a string. More...
 
virtual Json::Value valueAsJson () const =0
 Returns the value of the property as a Json::Value. More...
 
virtual std::string valueAsPrettyStr (const size_t maxLength=0, const bool collapseLists=true) const
 Returns the value of the property as a pretty printed string. More...
 
virtual ~Property ()
 Virtual destructor. More...
 

Private Member Functions

std::string isEmptyValueValid () const
 Returns a string depending on whether an empty value is valid. More...
 
std::string setValueAsMultipleFiles (const std::string &propValue)
 Called by setValue in the case where multiple file loading is enabled. More...
 
std::string setValueAsSingleFile (const std::string &propValue)
 Called by setValue in the case where a user has disabled multiple file loading. More...
 

Private Attributes

unsigned int m_action {2}
 The action type of this property Load (dafault) or OptionalLoad are supported. More...
 
bool m_allowEmptyTokens {false}
 Whether to allow for empty tokens. More...
 
std::string m_defaultExt
 The default file extension associated with the type of file this property will handle. More...
 
std::vector< std::string > m_exts
 Suggested extensions. More...
 
bool m_multiFileLoadingEnabled
 Whether or not the user has turned on multifile loading. More...
 
std::vector< std::vector< std::string > > m_oldFoundValue
 Last value of the found files used in MultipleFileProperty::setValueAsMultipleFiles and MultipleFileProperty::setValueAsSingleFile. More...
 
std::string m_oldPropValue
 Last value of propValue used in MultipleFileProperty::setValueAsMultipleFiles and MultipleFileProperty::setValueAsSingleFile. More...
 
Kernel::MultiFileNameParsing::Parser m_parser
 Parser used to parse multi-file strings. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Mantid::Kernel::Property
 Property (const Property &right)
 Copy constructor. More...
 
 Property (std::string name, const std::type_info &type, const unsigned int &direction=Direction::Input)
 Constructor. More...
 
- Protected Attributes inherited from Mantid::Kernel::PropertyWithValue< std::vector< std::vector< std::string > > >
std::vector< std::vector< std::string > > m_initialValue
 the property's default value which is also its initial value More...
 
std::vector< std::vector< std::string > > m_value
 The value of the property. More...
 
- Protected Attributes inherited from Mantid::Kernel::Property
std::string m_name
 The name of the property. More...
 

Detailed Description

A property to allow a user to specify multiple files to load.

The current functionality is such that there are two basic forms of syntax. For the puposes of documentation we'll call these the "Long Form" and "Short Form".


[A] Short Form

These strings are of the format "[dir][inst][under][runs][ext]" where:

[dir]   (Optional) = The OS-specific file directory, e.g. "c:/data/"
[inst]  (Optional) = The instrument name, e.g. "IRS" or "PG3".
[under] (Optional) = Some instrument filenames require an underscore.
[runs]  (Required) = The run numbers, e.g. "0102, 0110-0115, 0120,

0130:0140:2" [ext] (Optional) = The file extension, e.g. ".raw" For optional values, defaults or user settings are used where necessary. For [runs], users specify lists and ranges of runs using comma, plus, minus and colon. Some examples: @iverbatim "TSC0001,0002" = Runs 1 and 2 of the TOSCA instrument are to be loaded. "0003+0004" = Runs 3 and 4 of the default instrument are to be loaded and added together. "0005:0009.raw" = The raw files containing runs 5 to 9 of the default instrument are to be loaded. "c:/data/0010-0014" = The files in "c:/data/" containing runs 10 to 14 of the default instrument are to be loaded and added together. "IRS0020:0028:2.nxs" = The nexus files containing runs 20, 22, 24, 26 and 28 for IRIS are to be loaded. "INST_0030-0038:3" = Runs 30, 33, and 36 of INST are to be loaded and added together.


[B] Long Form

These strings are of the format "[[short_form][operator]]...[short_form]"

where:

[short_form] = [dir][inst][under][runs][ext], which is the "Short Form"

outlined above. [operator] = Either a comma or a plus.

Some examples:

"TSC0001,TSC0002+0003" = Runs 1, 2 and 3 of the TOSCA instrument should be loaded, but 2 and 3 are added together. "TSC0005+TSC0006,TSC0007.raw" = Runs 5 and 6 as well as the raw file containing run 7 of the TOSCA instrument should be loaded, but 5 and 6 are added together.


NOTES:

[1] Presently, we disallow more complex algebra such as "TSC0005,0006+TSC0007". In such a case it is ambiguous whether or not the user wishes to just add run 7 to 6, or add run 7 to both 5 and 6.

[2] The "Short Form" is parsed by the Kernel::MultiFileNameParsing::Parser class, whereas this class is responsible for splitting up the Long Form.

[3] The functionality of this class is such that all strings are stored only after being converted to the Long Form, and all filenames are fully resolved. For example "0005,0006+0007" is stored as "[dir][inst][under]0005[ext],[dir][inst][under]0006[ext]+[dir][inst][under]0007[ext]".

[4] The default functionality of this Property can be changed to emulate a simple FileProperty - to do this, the user must change the properties file. Disabling multi file loading in this way will allow users to use "," and "+" in their filenames, and in this case we use the dummy "" delimiters to call toValue and toString.


The value returned by getProperty is of type std::vector<std::vector<std::string>>. While the property itself does expand ranges, the value needs some intepretation by the client code. Specifically, values inside the same std::vector<std::string> should be added together, while values between them should be treated separately. In other words, if the value was [[a1,a2], [b1,b2]]. The results should be two workspaces, a1+a2 and b1+b2.


Definition at line 114 of file MultipleFileProperty.h.

Constructor & Destructor Documentation

◆ MultipleFileProperty() [1/3]

Mantid::API::MultipleFileProperty::MultipleFileProperty ( const std::string &  name,
unsigned int  action,
const std::vector< std::string > &  exts = std::vector<std::string>(),
bool  allowEmptyTokens = false 
)

Alternative constructor with action.

Parameters
name:: The name of the property
action:: File action
exts:: The allowed/suggested extensions
allowEmptyTokens:: whether to allow empty tokens

raise error for unsupported actions

Definition at line 74 of file MultipleFileProperty.cpp.

References Mantid::Kernel::SingletonHolder< T >::Instance(), Mantid::API::FileProperty::Load, m_action, m_exts, m_multiFileLoadingEnabled, and Mantid::API::FileProperty::OptionalLoad.

◆ MultipleFileProperty() [2/3]

Mantid::API::MultipleFileProperty::MultipleFileProperty ( const std::string &  name,
const std::vector< std::string > &  exts = std::vector<std::string>() 
)

Default constructor with default action.

Parameters
name:: The name of the property
exts:: The allowed/suggested extensions

Definition at line 97 of file MultipleFileProperty.cpp.

◆ MultipleFileProperty() [3/3]

Mantid::API::MultipleFileProperty::MultipleFileProperty ( const MultipleFileProperty )
default

Member Function Documentation

◆ clone()

MultipleFileProperty * Mantid::API::MultipleFileProperty::clone ( ) const
inlineoverridevirtual

'Virtual copy constructor'

Implements Mantid::Kernel::Property.

Definition at line 125 of file MultipleFileProperty.h.

◆ getDefault()

std::string Mantid::API::MultipleFileProperty::getDefault ( ) const
overridevirtual

Get the value the property was initialised with -its default value.

Returns
The default value

Implements Mantid::Kernel::Property.

Definition at line 175 of file MultipleFileProperty.cpp.

References Mantid::Kernel::PropertyWithValue< std::vector< std::vector< std::string > > >::m_initialValue, and m_multiFileLoadingEnabled.

◆ getDefaultExt()

std::string Mantid::API::MultipleFileProperty::getDefaultExt ( ) const
inline

Returns the main file extension that's used.

Definition at line 136 of file MultipleFileProperty.h.

◆ getExts()

std::vector< std::string > Mantid::API::MultipleFileProperty::getExts ( ) const
inline
Returns
the vector of suggested extensions. For use in GUIs showing files.

Definition at line 133 of file MultipleFileProperty.h.

◆ isEmptyValueValid()

std::string Mantid::API::MultipleFileProperty::isEmptyValueValid ( ) const
private

Returns a string depending on whether an empty value is valid.

Returns
Empty string if empty value is valid, error message otherwise

Definition at line 109 of file MultipleFileProperty.cpp.

References isOptional(), and SUCCESS.

◆ isOptional()

bool Mantid::API::MultipleFileProperty::isOptional ( ) const

Check if this property is optional.

Returns
True if the property is optinal, false otherwise

Definition at line 104 of file MultipleFileProperty.cpp.

References m_action, and Mantid::API::FileProperty::OptionalLoad.

Referenced by isEmptyValueValid(), and setValue().

◆ operator=()

MultipleFileProperty & Mantid::API::MultipleFileProperty::operator= ( const MultipleFileProperty )
default

◆ setValue()

std::string Mantid::API::MultipleFileProperty::setValue ( const std::string &  propValue)
overridevirtual

Convert the given propValue into a comma and plus separated list of full filenames, and pass to the parent's setValue method to store as a vector of vector of strings.

READ HEADER FILE DOCUMENTATION FOR A MORE DETAILED OVERVIEW.

Parameters
propValue:: A string of the allowed format, indicating the user's choice of files.
Returns
A string indicating the outcome of the attempt to set the property. An empty string indicates success.

Implements Mantid::Kernel::Property.

Definition at line 129 of file MultipleFileProperty.cpp.

References Mantid::Kernel::Logger::debug(), error, Mantid::API::g_log, isOptional(), m_multiFileLoadingEnabled, setValueAsMultipleFiles(), setValueAsSingleFile(), and SUCCESS.

◆ setValueAsMultipleFiles()

std::string Mantid::API::MultipleFileProperty::setValueAsMultipleFiles ( const std::string &  propValue)
private

Called by setValue in the case where multiple file loading is enabled.

NOTE: If multifile loading is enabled, then users make the concession that they cannot use "," or "+" in directory names; they are used as operators only.

Parameters
propValue:: A string of the allowed format, indicating the user's choice of files.
Returns
A string indicating the outcome of the attempt to set the property. An empty string indicates success.

Definition at line 235 of file MultipleFileProperty.cpp.

References Mantid::Kernel::Property::autoTrim(), error, Mantid::Kernel::Logger::error(), Mantid::Kernel::MultiFileNameParsing::Parser::fileNames(), Mantid::Kernel::VectorHelper::flattenVector(), Mantid::API::g_log, Mantid::Kernel::Direction::Input, Mantid::Kernel::SingletonHolder< T >::Instance(), Mantid::API::FileProperty::Load, m_allowEmptyTokens, m_exts, m_oldFoundValue, m_oldPropValue, m_parser, Mantid::Kernel::MultiFileNameParsing::Parser::parse(), Mantid::Kernel::MultiFileNameParsing::Parser::setTrimWhiteSpaces(), Mantid::API::FileProperty::setValue(), and SUCCESS.

Referenced by setValue().

◆ setValueAsSingleFile()

std::string Mantid::API::MultipleFileProperty::setValueAsSingleFile ( const std::string &  propValue)
private

Called by setValue in the case where a user has disabled multiple file loading.

Parameters
propValue:: A string of the allowed format, indicating the user's choice of files.
Returns
A string indicating the outcome of the attempt to set the property. An empty string indicates success.

Definition at line 191 of file MultipleFileProperty.cpp.

References Mantid::Kernel::Logger::debug(), error, Mantid::API::g_log, Mantid::Kernel::Direction::Input, Mantid::API::FileProperty::Load, m_exts, m_oldFoundValue, m_oldPropValue, Mantid::Kernel::Property::name(), Mantid::API::FileProperty::setValue(), and SUCCESS.

Referenced by setValue().

◆ value()

std::string Mantid::API::MultipleFileProperty::value ( ) const
overridevirtual

Returns the value of the property as a string.

Implements Mantid::Kernel::Property.

Definition at line 164 of file MultipleFileProperty.cpp.

References m_multiFileLoadingEnabled, and Mantid::Kernel::PropertyWithValue< std::vector< std::vector< std::string > > >::m_value.

Member Data Documentation

◆ m_action

unsigned int Mantid::API::MultipleFileProperty::m_action {2}
private

The action type of this property Load (dafault) or OptionalLoad are supported.

Definition at line 158 of file MultipleFileProperty.h.

Referenced by isOptional(), and MultipleFileProperty().

◆ m_allowEmptyTokens

bool Mantid::API::MultipleFileProperty::m_allowEmptyTokens {false}
private

Whether to allow for empty tokens.

Definition at line 168 of file MultipleFileProperty.h.

Referenced by setValueAsMultipleFiles().

◆ m_defaultExt

std::string Mantid::API::MultipleFileProperty::m_defaultExt
private

The default file extension associated with the type of file this property will handle.

Definition at line 155 of file MultipleFileProperty.h.

◆ m_exts

std::vector<std::string> Mantid::API::MultipleFileProperty::m_exts
private

Suggested extensions.

Definition at line 150 of file MultipleFileProperty.h.

Referenced by MultipleFileProperty(), setValueAsMultipleFiles(), and setValueAsSingleFile().

◆ m_multiFileLoadingEnabled

bool Mantid::API::MultipleFileProperty::m_multiFileLoadingEnabled
private

Whether or not the user has turned on multifile loading.

Definition at line 147 of file MultipleFileProperty.h.

Referenced by getDefault(), MultipleFileProperty(), setValue(), and value().

◆ m_oldFoundValue

std::vector<std::vector<std::string> > Mantid::API::MultipleFileProperty::m_oldFoundValue
private

◆ m_oldPropValue

std::string Mantid::API::MultipleFileProperty::m_oldPropValue
private

◆ m_parser

Kernel::MultiFileNameParsing::Parser Mantid::API::MultipleFileProperty::m_parser
private

Parser used to parse multi-file strings.

Definition at line 152 of file MultipleFileProperty.h.

Referenced by setValueAsMultipleFiles().


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