OpenMS
2.5.0
|
Management and storage of parameters / INI files. More...
#include <OpenMS/DATASTRUCTURES/Param.h>
Classes | |
struct | ParamEntry |
Parameter entry used to store the actual information inside of a Param entry. More... | |
class | ParamIterator |
Forward const iterator for the Param class. More... | |
struct | ParamNode |
Node inside a Param object which is used to build the internal tree. More... | |
Public Member Functions | |
Param () | |
Default constructor. More... | |
Param (const Param &)=default | |
Copy constructor. More... | |
Param (Param &&)=default | |
Move constructor. More... | |
~Param () | |
Destructor. More... | |
Param & | operator= (const Param &)=default |
Assignment operator. More... | |
Param & | operator= (Param &&) &=default |
Move assignment operator. More... | |
bool | operator== (const Param &rhs) const |
Equality operator. More... | |
ParamIterator | begin () const |
Begin iterator for the internal tree. More... | |
ParamIterator | end () const |
End iterator for the internal tree. More... | |
Accessors for single parameters | |
void | setValue (const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList()) |
Sets a value. More... | |
const DataValue & | getValue (const String &key) const |
Returns a value of a parameter. More... | |
const ParamEntry & | getEntry (const String &key) const |
Returns the whole parameter entry. More... | |
bool | exists (const String &key) const |
Tests if a parameter is set (expecting its fully qualified name, e.g., TextExporter:1:proteins_only) More... | |
ParamIterator | findFirst (const String &leaf) const |
Find leaf node by name (if it exists). More... | |
ParamIterator | findNext (const String &leaf, const ParamIterator &start_leaf) const |
Find next leaf node by name (if it exists), not considering the start_leaf . More... | |
Tags handling | |
void | addTag (const String &key, const String &tag) |
Adds the tag tag to the entry key . More... | |
void | addTags (const String &key, const StringList &tags) |
Adds the tags in the list tags to the entry key . More... | |
bool | hasTag (const String &key, const String &tag) const |
Returns if the parameter key has a tag. More... | |
StringList | getTags (const String &key) const |
Returns the tags of entry key . More... | |
void | clearTags (const String &key) |
Removes all tags from the entry key . More... | |
Descriptions handling | |
const String & | getDescription (const String &key) const |
Returns the description of a parameter. More... | |
void | setSectionDescription (const String &key, const String &description) |
Sets a description for an existing section. More... | |
const String & | getSectionDescription (const String &key) const |
Returns the description corresponding to the section with name key . More... | |
void | addSection (const String &key, const String &description) |
Adds a parameter section under the path key with the given description . More... | |
Manipulation of the whole parameter set | |
Size | size () const |
Returns the number of entries (leafs). More... | |
bool | empty () const |
Returns if there are no entries. More... | |
void | clear () |
Deletes all entries. More... | |
void | insert (const String &prefix, const Param ¶m) |
void | remove (const String &key) |
Remove the entry key or a section key (when suffix is ':') More... | |
void | removeAll (const String &prefix) |
Remove all entries that start with prefix . More... | |
Param | copy (const String &prefix, bool remove_prefix=false) const |
Returns a new Param object containing all entries that start with prefix . More... | |
Param | copySubset (const Param &subset) const |
Returns a new Param object containing all entries in the given subset. More... | |
bool | update (const Param &p_outdated, const bool add_unknown=false) |
Rescue parameter values from p_outdated to current param. More... | |
bool | update (const Param &p_outdated, const bool add_unknown, Logger::LogStream &stream) |
Rescue parameter values from p_outdated to current param. More... | |
bool | update (const Param &p_outdated, bool verbose, bool add_unknown, bool fail_on_invalid_values, bool fail_on_unknown_parameters, Logger::LogStream &stream) |
Rescue parameter values from p_outdated to current param. More... | |
void | merge (const Param &toMerge) |
Adds missing parameters from the given param toMerge to this param. Existing parameters will not be modified. More... | |
Default value handling | |
void | setDefaults (const Param &defaults, const String &prefix="", bool showMessage=false) |
Insert all values of defaults and adds the prefix prefix , if the values are not already set. More... | |
void | checkDefaults (const String &name, const Param &defaults, const String &prefix="") const |
Checks the current parameter entries against given defaults . More... | |
Restriction handling | |
void | setValidStrings (const String &key, const std::vector< String > &strings) |
Sets the valid strings for the parameter key . More... | |
void | setMinInt (const String &key, Int min) |
Sets the minimum value for the integer or integer list parameter key . More... | |
void | setMaxInt (const String &key, Int max) |
Sets the maximum value for the integer or integer list parameter key . More... | |
void | setMinFloat (const String &key, double min) |
Sets the minimum value for the floating point or floating point list parameter key . More... | |
void | setMaxFloat (const String &key, double max) |
Sets the maximum value for the floating point or floating point list parameter key . More... | |
Command line parsing | |
Param::ParamNode | root_ |
Invisible root node that stores all the data. More... | |
void | parseCommandLine (const int argc, const char **argv, const String &prefix="") |
Parses command line arguments. More... | |
void | parseCommandLine (const int argc, const char **argv, const Map< String, String > &options_with_one_argument, const Map< String, String > &options_without_argument, const Map< String, String > &options_with_multiple_argument, const String &misc="misc", const String &unknown="unknown") |
Parses command line arguments to specified key locations. More... | |
ParamEntry & | getEntry_ (const String &key) const |
Returns a mutable reference to a parameter entry. More... | |
Param (const Param::ParamNode &node) | |
Constructor from a node which is used as root node. More... | |
Management and storage of parameters / INI files.
This class provides a means to associate string names to int/double/string/StringList values. It allows for parameter hierarchies and to save/load the data as XML. Hierarchy levels are separated from each other by colons.
Example: 'common:file_options:default_file_open_path = /share/'
Each parameter and section has a description. Newline characters in the description are possible.
Each parameter can be annotated with an arbitrary number of tags. Tags must not contain comma characters!
E.g. the advanced tag indicates if this parameter is shown to all users or in advanced mode only.
Param | ( | ) |
Default constructor.
~Param | ( | ) |
Destructor.
|
protected |
Constructor from a node which is used as root node.
Adds a parameter section under the path key
with the given description
.
If the section already exists, the description is only overwritten if not empty.
Adds the tag tag
to the entry key
.
E.g. "advanced", "required", "input file", "output file"
Exception::ElementNotFound | is thrown if the parameter does not exists. |
Exception::InvalidValue | is thrown if the tag contain a comma character. |
void addTags | ( | const String & | key, |
const StringList & | tags | ||
) |
Adds the tags in the list tags
to the entry key
.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
Exception::InvalidValue | is thrown if a tag contain a comma character. |
ParamIterator begin | ( | ) | const |
Begin iterator for the internal tree.
Referenced by TOPPViewBase::loadPreferences(), main(), and DigestionEnzymeDB< DigestionEnzymeRNA, RNaseDB >::readEnzymesFromFile_().
void checkDefaults | ( | const String & | name, |
const Param & | defaults, | ||
const String & | prefix = "" |
||
) | const |
Checks the current parameter entries against given defaults
.
Several checks are performed:
os
.name | The name that is used in error messages. |
defaults | The default values. |
prefix | The prefix where to check for the defaults. |
Warnings etc. will be send to OPENMS_LOG_WARN.
Exception::InvalidParameter | is thrown if errors occur during the check |
void clear | ( | ) |
Deletes all entries.
Referenced by INIFileEditorWindow::openFile().
void clearTags | ( | const String & | key | ) |
Removes all tags from the entry key
.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
Returns a new Param object containing all entries that start with prefix
.
prefix | should contain a ':' at the end if you want to extract a subtree. Otherwise not only nodes, but as well values with that prefix are copied. |
remove_prefix | indicates if the prefix is removed before adding entries to the new Param |
Referenced by FeatureDistance::DistanceParams_::DistanceParams_(), TOPPViewBase::getSpectrumParameters(), TOPPViewBase::loadPreferences(), TOPPXFDR::main_(), TOPPOpenPepXLLF::main_(), TOPPOpenPepXL::main_(), TOPPOpenSwathBase::performCalibration(), TOPPASBase::savePreferences(), TOPPViewBase::savePreferences(), and ProductModel< 2 >::updateMembers_().
Returns a new Param object containing all entries in the given subset.
subset | The subset of Param nodes that should be copied out of the object here. Includes values etc. Does not check any compatibility. Just matches the names. |
bool empty | ( | ) | const |
Returns if there are no entries.
Referenced by DigestionEnzymeDB< DigestionEnzymeRNA, RNaseDB >::readEnzymesFromFile_().
ParamIterator end | ( | ) | const |
End iterator for the internal tree.
Referenced by TOPPViewBase::loadPreferences(), main(), and DigestionEnzymeDB< DigestionEnzymeRNA, RNaseDB >::readEnzymesFromFile_().
bool exists | ( | const String & | key | ) | const |
Tests if a parameter is set (expecting its fully qualified name, e.g., TextExporter:1:proteins_only)
key | The fully qualified name of the parameter to check. |
Referenced by TOPPASBase::loadPreferences(), TOPPViewBase::loadPreferences(), and main().
ParamIterator findFirst | ( | const String & | leaf | ) | const |
Find leaf node by name (if it exists).
leaf | The name of the parameter to find excluding the path parameter, e.g., given the parameter TextExporter:1:proteins_only the leaf would be named proteins_only. |
ParamIterator findNext | ( | const String & | leaf, |
const ParamIterator & | start_leaf | ||
) | const |
Find next leaf node by name (if it exists), not considering the start_leaf
.
leaf | The name of the parameter to find excluding the path parameter, e.g., given the parameter TextExporter:1:proteins_only the leaf would be named proteins_only. |
start_leaf | The already found leaf, that should not be considered during this search. |
Returns the description of a parameter.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
const ParamEntry& getEntry | ( | const String & | key | ) | const |
Returns the whole parameter entry.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
|
protected |
Returns a mutable reference to a parameter entry.
Exception::ElementNotFound | is thrown for unset parameters |
Returns the description corresponding to the section with name key
.
If the section does not exist an empty string is returned.
StringList getTags | ( | const String & | key | ) | const |
Returns the tags of entry key
.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
Returns a value of a parameter.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
Referenced by TOPPViewBase::addData(), TOPPViewBase::addDataFile(), TOPPViewBase::addRecentFile_(), FeatureDistance::DistanceParams_::DistanceParams_(), TOPPViewBase::fileChanged_(), TOPPViewBase::finishTOPPToolExecution(), TOPPViewBase::getSpectrumParameters(), TOPPASBase::loadPreferences(), TOPPViewBase::loadPreferences(), main(), TwoDOptimization::optimize(), TwoDOptimization::optimizeRegionsScanwise_(), TOPPOpenSwathBase::performCalibration(), TOPPViewBase::preferencesDialog(), TOPPASBase::savePreferences(), TOPPViewBase::savePreferences(), TOPPViewBase::showSpectrumGenerationDialog(), TOPPViewBase::showTOPPDialog_(), TOPPASBase::TOPPASBase(), TOPPViewBase::TOPPViewBase(), TOPPASBase::updateCurrentPath(), TOPPViewBase::updateCurrentPath(), TOPPViewBase::updateLayerBar(), BaseModel< 2 >::updateMembers_(), SignalToNoiseEstimatorMeanIterative< Container >::updateMembers_(), SignalToNoiseEstimatorMedian< ContainerT >::updateMembers_(), and TOPPViewBase::updateRecentMenu_().
Returns if the parameter key
has a tag.
Example: The tag 'advanced' is used in the GUI to determine which parameters are always displayed and which parameters are displayed only in 'advanced mode'.
Exception::ElementNotFound | is thrown if the parameter does not exists. |
Insert all values of param
and adds the prefix prefix
. You should append ':' to prefix manually when you want it to be a section.
Referenced by TOPPViewBase::initializeDefaultParameters_().
void merge | ( | const Param & | toMerge | ) |
Adds missing parameters from the given param toMerge
to this param. Existing parameters will not be modified.
toMerge | The Param object from which parameters should be added to this param. |
bool operator== | ( | const Param & | rhs | ) | const |
Equality operator.
void parseCommandLine | ( | const int | argc, |
const char ** | argv, | ||
const Map< String, String > & | options_with_one_argument, | ||
const Map< String, String > & | options_without_argument, | ||
const Map< String, String > & | options_with_multiple_argument, | ||
const String & | misc = "misc" , |
||
const String & | unknown = "unknown" |
||
) |
Parses command line arguments to specified key locations.
Parses command line arguments to specified key locations and stores the result internally.
argc | argc variable from command line |
argv | argv variable from command line |
options_with_one_argument | a map of options that are followed by one argument (with key where they are stored) |
options_without_argument | a map of options that are not followed by an argument (with key where they are stored). Options specified on the command line are set to the string 'true'. |
options_with_multiple_argument | a map of options that are followed by several arguments (with key where they are stored) |
misc | key where a StringList of all non-option arguments are stored |
unknown | key where a StringList of all unknown options are stored |
Parses command line arguments.
This method discriminates three types of arguments:
(1) options (starting with '-') that have a text argument
(2) options (starting with '-') that have no text argument
(3) text arguments (not starting with '-')
Command line arguments '-a avalue -b -c bvalue misc1 misc2' would be stored like this:
"prefix:-a" -> "avalue"
"prefix:-b" -> ""
"prefix:-c" -> "bvalue"
"prefix:misc" -> list("misc1","misc2")
argc | argc variable from command line |
argv | argv variable from command line |
prefix | prefix for all options |
Referenced by main().
void remove | ( | const String & | key | ) |
Remove the entry key
or a section key
(when suffix is ':')
Remove deletes either an entry or a section (when key
ends with ':'), by matching the exact name. No partial matches are accepted.
If an empty internal node remains, the tree is pruned until every node has either a successor node or a leaf, i.e. no naked nodes remain.
void removeAll | ( | const String & | prefix | ) |
Remove all entries that start with prefix
.
Partial are valid as well. All entries and sections which match the prefix are deleted.
If an empty internal node remains, the tree is pruned until every node has either a successor node or a leaf, i.e. no naked nodes remain.
Referenced by TOPPViewBase::savePreferences().
Insert all values of defaults
and adds the prefix prefix
, if the values are not already set.
defaults | The default values. |
prefix | The prefix to add to all defaults. |
showMessage | If true each default that is actually set is printed to stdout as well. |
Sets the maximum value for the floating point or floating point list parameter key
.
It is only checked in checkDefaults().
Exception::ElementNotFound | is thrown if key is not found or if the parameter type is wrong |
Referenced by SignalToNoiseEstimatorMeanIterative< Container >::SignalToNoiseEstimatorMeanIterative(), and SignalToNoiseEstimatorMedian< ContainerT >::SignalToNoiseEstimatorMedian().
Sets the maximum value for the integer or integer list parameter key
.
It is only checked in checkDefaults().
Exception::ElementNotFound | is thrown if key is not found or if the parameter type is wrong |
Referenced by TOPPViewBase::initializeDefaultParameters_(), SignalToNoiseEstimatorMeanIterative< Container >::SignalToNoiseEstimatorMeanIterative(), and SignalToNoiseEstimatorMedian< ContainerT >::SignalToNoiseEstimatorMedian().
Sets the minimum value for the floating point or floating point list parameter key
.
It is only checked in checkDefaults().
Exception::ElementNotFound | is thrown if key is not found or if the parameter type is wrong |
Referenced by SignalToNoiseEstimatorMeanIterative< Container >::SignalToNoiseEstimatorMeanIterative(), and SignalToNoiseEstimatorMedian< ContainerT >::SignalToNoiseEstimatorMedian().
Sets the minimum value for the integer or integer list parameter key
.
It is only checked in checkDefaults().
Exception::ElementNotFound | is thrown if key is not found or if the parameter type is wrong |
Referenced by TOPPViewBase::initializeDefaultParameters_(), SignalToNoiseEstimatorMeanIterative< Container >::SignalToNoiseEstimatorMeanIterative(), and SignalToNoiseEstimatorMedian< ContainerT >::SignalToNoiseEstimatorMedian().
Sets a description for an existing section.
Descriptions for values cannot be set with this method. They have to be set when inserting the value itself.
Exception::ElementNotFound | is thrown if the section does not exists. |
Referenced by TOPPViewBase::initializeDefaultParameters_().
Sets the valid strings for the parameter key
.
It is only checked in checkDefaults().
Exception::InvalidParameter | is thrown, if one of the strings contains a comma character |
Exception::ElementNotFound | exception is thrown, if the parameter is no string parameter |
Referenced by TOPPViewBase::initializeDefaultParameters_(), SignalToNoiseEstimatorMedian< ContainerT >::SignalToNoiseEstimatorMedian(), and TOPPASBase::TOPPASBase().
void setValue | ( | const String & | key, |
const DataValue & | value, | ||
const String & | description = "" , |
||
const StringList & | tags = StringList() |
||
) |
Sets a value.
key | String key. Can contain ':' which separates section names |
value | The actual value |
description | Verbose description of the parameter |
tags | list of tags associated to this parameter |
Referenced by TOPPViewBase::annotateMS1FromMassFingerprinting_(), TOPPViewBase::annotateWithID(), BaseModel< 2 >::BaseModel(), NucleicAcidSearchEngine::calculateAndFilterFDR_(), TOPPViewBase::getSpectrumParameters(), TOPPViewBase::initializeDefaultParameters_(), TOPPViewBase::loadFiles(), TOPPASBase::loadPreferences(), TOPPViewBase::loadPreferences(), NucleicAcidSearchEngine::main_(), SpectraMerger::mergeSpectra_(), TOPPOpenSwathBase::performCalibration(), PeakPickerIterative::pick(), TOPPViewBase::preferencesDialog(), NucleicAcidSearchEngine::preprocessSpectra_(), TOPPASBase::savePreferences(), TOPPViewBase::savePreferences(), BaseModel< 2 >::setCutOff(), TOPPViewBase::showSpectrumAlignmentDialog(), TOPPViewBase::showSpectrumGenerationDialog(), SignalToNoiseEstimatorMeanIterative< Container >::SignalToNoiseEstimatorMeanIterative(), SignalToNoiseEstimatorMedian< ContainerT >::SignalToNoiseEstimatorMedian(), SignalToNoiseOpenMS< ContainerT >::SignalToNoiseOpenMS(), TOPPASBase::TOPPASBase(), and TOPPViewBase::updateRecentMenu_().
Size size | ( | ) | const |
Returns the number of entries (leafs).
Referenced by TOPPViewBase::loadPreferences().
bool update | ( | const Param & | p_outdated, |
bool | verbose, | ||
bool | add_unknown, | ||
bool | fail_on_invalid_values, | ||
bool | fail_on_unknown_parameters, | ||
Logger::LogStream & | stream | ||
) |
Rescue parameter values from p_outdated
to current param.
All parameters present in both param objects will be transferred into this object, given that:
p_outdated
meets the new restrictions Not transferred are values from parameter "version" (to preserve the new version) or "type" (to preserve layout).
p_outdated | Old/outdated param object, whose values (as long as they are still valid) are used to update this object |
verbose | Print information about expected value updates |
add_unknown | Add unknown parameters from @p_outdated to this param object. |
fail_on_invalid_values | Return false if outdated parameters hold invalid values |
fail_on_unknown_parameters | Return false if outdated parameters contain unknown parameters (takes precedence over add_unknown ) |
stream | The stream where all the logging output is send to. |
bool update | ( | const Param & | p_outdated, |
const bool | add_unknown, | ||
Logger::LogStream & | stream | ||
) |
Rescue parameter values from p_outdated
to current param.
Calls ::update(p_outdated, true, add_unknown, false, false, stream) and returns its value.
bool update | ( | const Param & | p_outdated, |
const bool | add_unknown = false |
||
) |
Rescue parameter values from p_outdated
to current param.
Calls ::update(p_outdated, true, add_unknown, false, false, OPENMS_LOG_WARN) and returns its value.
Referenced by TOPPXFDR::main_(), TOPPOpenPepXLLF::main_(), and TOPPOpenPepXL::main_().
|
mutableprotected |
Invisible root node that stores all the data.