Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
Classes | Public Member Functions | Protected Member Functions | Protected Attributes

Param Class Reference
[Datastructures]

Management and storage of parameters / INI files. More...

#include <OpenMS/DATASTRUCTURES/Param.h>

List of all members.

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 construtor.
 Param (const Param &rhs)
 Copy constructor.
 ~Param ()
 Destructor.
Paramoperator= (const Param &rhs)
 Assignment operator.
bool operator== (const Param &rhs) const
 Equality operator.
ParamIterator begin () const
 Begin iterator for the internal tree.
ParamIterator end () const
 End iterator for the internal tree.
Accessors for single parameters

void setValue (const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
 Sets a value.
const DataValuegetValue (const String &key) const
 Returns a value of a parameter.
const ParamEntrygetEntry (const String &key) const
 Returns the whole parameter entry.
bool exists (const String &key) const
 Tests if a parameter is set (expecting its fully qualified name, e.g., TextExporter:1:proteins_only).
ParamIterator findFirst (const String &leaf) const
ParamIterator findNext (const String &leaf, const ParamIterator &start_leaf) const
Tags handling

void addTag (const String &key, const String &tag)
 Adds the tag tag to the entry key.
void addTags (const String &key, const StringList &tags)
 Adds the tags in the list tags to the entry key.
bool hasTag (const String &key, const String &tag) const
 Returns if the parameter key has a tag.
StringList getTags (const String &key) const
 Returns the tags of entry key.
void clearTags (const String &key)
 Removes all tags from the entry key.
Descriptions handling

const StringgetDescription (const String &key) const
 Returns the description of a parameter.
void setSectionDescription (const String &key, const String &description)
 Sets a description for an existing section.
const StringgetSectionDescription (const String &key) const
 Returns the description corresponding to the section with name key.
Manipulation of the whole parameter set

Size size () const
 Returns the number of entries (leafs).
bool empty () const
 Returns if there are no entries.
void clear ()
 Deletes all entries.
void insert (const String &prefix, const Param &param)
void remove (const String &key)
 Remove the entry key or a section key (when suffix is ':').
void removeAll (const String &prefix)
 Remove all entries that start with prefix.
Param copy (const String &prefix, bool remove_prefix=false) const
 Returns a new Param object containing all entries that start with prefix.
void update (const Param &old_version, const bool add_unknown=false, Logger::LogStream &stream=LOG_WARN)
 Rescue parameter values from old_version to current param.
void merge (const Param &toMerge)
 Adds missing parameters from the given Param to the param object. Existing parameters will not be modified.
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.
void checkDefaults (const String &name, const Param &defaults, const String &prefix="", std::ostream &os=std::cout) const
 Checks the current parameter entries against given defaults.
Restriction handling

void setValidStrings (const String &key, const std::vector< String > &strings)
 Sets the valid strings for the parameter key.
void setMinInt (const String &key, Int min)
 Sets the minimum value for the integer or integer list parameter key.
void setMaxInt (const String &key, Int max)
 Sets the maximum value for the integer or integer list parameter key.
void setMinFloat (const String &key, DoubleReal min)
 Sets the minimum value for the floating point or floating point list parameter key.
void setMaxFloat (const String &key, DoubleReal max)
 Sets the maximum value for the floating point or floating point list parameter key.
Command line parsing

void parseCommandLine (const int argc, const char **argv, const String &prefix="")
 Parses command line arguments.
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.
void parseCommandLine (const int argc, const char **argv, const std::vector< ParameterInformation > &parameters, const String &misc="misc", const String &unknown="unknown")
 Parses command line arguments using parameter definitions from TOPPBase.

Protected Member Functions

ParamEntrygetEntry_ (const String &key) const
 Returns a mutable reference to a parameter entry.
 Param (const Param::ParamNode &node)
 Constructor from a node wich is used as root node.

Protected Attributes

Param::ParamNode root_
 Invisible root node that stores all the data.

Detailed Description

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.

See also:
DefaultParamHandler

Constructor & Destructor Documentation

Param (  ) 

Default construtor.

Param ( const Param rhs  ) 

Copy constructor.

~Param (  ) 

Destructor.

Param ( const Param::ParamNode node  )  [protected]

Constructor from a node wich is used as root node.


Member Function Documentation

void addTag ( const String key,
const String tag 
)

Adds the tag tag to the entry key.

Exceptions:
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.

Exceptions:
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(), and main().

void checkDefaults ( const String name,
const Param defaults,
const String prefix = "",
std::ostream &  os = std::cout 
) const

Checks the current parameter entries against given defaults.

Several checks are performed:

  • If a parameter is present for which no default value is specified, a warning is issued to os.
  • If the type of a parameter and its default do not match, an exception is thrown.
  • If a string parameter contains an invalid string, an exception is thrown.
  • If parameter entry is a string list, an exception is thrown, if one or more list members are invalid strings
  • If a numeric parameter is out of the valid range, an exception is thrown.
  • If entry is a numeric list an exception is thrown, if one or more list members are out of the valid range
Parameters:
name The name that is used in error messages.
defaults The default values.
prefix The prefix where to check for the defaults.
os The output stream for the warnings.
Exceptions:
Exception::InvalidParameter is thrown if errors occur during the check
void clear (  ) 
void clearTags ( const String key  ) 

Removes all tags from the entry key.

Exceptions:
Exception::ElementNotFound is thrown if the parameter does not exists.
Param copy ( const String prefix,
bool  remove_prefix = false 
) const

Returns a new Param object containing all entries that start with prefix.

Parameters:
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_(), IDEvaluationBase::getPoints(), TOPPViewBase::getSpectrumParameters(), SimpleSeeder< PeakType, FeatureType >::initialize_(), TOPPViewBase::loadPreferences(), TOFCalibration::pickAndCalibrate(), TOPPViewBase::savePreferences(), and TOPPASBase::savePreferences().

bool empty (  )  const

Returns if there are no entries.

ParamIterator end (  )  const

End iterator for the internal tree.

Referenced by TOPPViewBase::loadPreferences(), and main().

bool exists ( const String key  )  const
ParamIterator findFirst ( const String leaf  )  const

find leaf node by name (if it exists)

Returns:
Returns end() if leaf does not exist
ParamIterator findNext ( const String leaf,
const ParamIterator start_leaf 
) const

find next leaf node by name (if it exists), not considering the start_leaf

Returns:
Returns end() if leaf does not exist
const String& getDescription ( const String key  )  const

Returns the description of a parameter.

Exceptions:
Exception::ElementNotFound is thrown if the parameter does not exists.
const ParamEntry& getEntry ( const String key  )  const

Returns the whole parameter entry.

Exceptions:
Exception::ElementNotFound is thrown if the parameter does not exists.
ParamEntry& getEntry_ ( const String key  )  const [protected]

Returns a mutable reference to a parameter entry.

Exceptions:
Exception::ElementNotFound is thrown for unset parameters
const String& getSectionDescription ( const String key  )  const

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.

Exceptions:
Exception::ElementNotFound is thrown if the parameter does not exists.
const DataValue& getValue ( const String key  )  const

Returns a value of a parameter.

Exceptions:
Exception::ElementNotFound is thrown if the parameter does not exists.

Referenced by TOPPViewBase::addData(), TOPPViewBase::addRecentFile_(), InternalCalibration::calibrateMapGlobally(), InternalCalibration::calibrateMapSpectrumwise(), OfflinePrecursorIonSelection::checkMassRanges_(), FeatureFinderAlgorithmPicked< PeakType, FeatureType >::chooseTraceFitter_(), TOPPViewBase::connectToDB_(), FeatureDistance::DistanceParams_::DistanceParams_(), ModelFitter< PeakType, FeatureType >::evaluate_(), IDEvaluationBase::exportAsImage(), TOPPViewBase::fileChanged_(), TOPPViewBase::finishTOPPToolExecution(), ModelFitter< PeakType, FeatureType >::fit(), OfflinePrecursorIonSelection::getMassRanges(), TOPPViewBase::getSpectrumParameters(), SimpleSeeder< PeakType, FeatureType >::initialize_(), TOPPViewBase::loadPreferences(), TOPPASBase::loadPreferences(), main(), OfflinePrecursorIonSelection::makePrecursorSelectionForKnownLCMSMap(), TwoDOptimization::optimize(), TwoDOptimization::optimizeRegionsScanwise_(), TOPPViewBase::preferencesDialog(), FeatureFinderAlgorithmSimplest< PeakType, FeatureType >::run(), FeatureFinderAlgorithmSimple< PeakType, FeatureType >::run(), FeatureFinderAlgorithmPicked< PeakType, FeatureType >::run(), FeatureFinderAlgorithmMRM< PeakType, FeatureType >::run(), TOPPViewBase::savePreferences(), TOPPASBase::savePreferences(), TOPPViewBase::showTOPPDialog_(), TOPPASBase::TOPPASBase(), TOPPViewBase::TOPPViewBase(), TOPPViewBase::updateCurrentPath(), TOPPASBase::updateCurrentPath(), TOPPViewBase::updateLayerBar(), TraceFitter< PeakType >::updateMembers_(), SimpleExtender< PeakType, FeatureType >::updateMembers_(), SignalToNoiseEstimatorMedian< OpenMS::MSSpectrum< PeakT > >::updateMembers_(), SignalToNoiseEstimatorMeanIterative< Container >::updateMembers_(), ModelFitter< PeakType, FeatureType >::updateMembers_(), FeatureFinderAlgorithmPicked< PeakType, FeatureType >::updateMembers_(), FeatureFinderAlgorithmIsotopeWavelet< PeakType, FeatureType >::updateMembers_(), BaseModel< 2 >::updateMembers_(), TOPPViewBase::updateRecentMenu_(), and FeatureFinderAlgorithmPicked< PeakType, FeatureType >::writeFeatureDebugInfo_().

bool hasTag ( const String key,
const String tag 
) const

Returns if the parameter key has a tag.

Example: The tag 'advanced' is used in the GUI to determine which parmeters are always displayed and which parameters are displayed only in 'advanced mode'.

Exceptions:
Exception::ElementNotFound is thrown if the parameter does not exists.
void insert ( const String prefix,
const Param param 
)
void merge ( const Param toMerge  ) 

Adds missing parameters from the given Param to the param object. Existing parameters will not be modified.

Parameters:
toMerge The Param object from which parameters should be added to the Param object.
Param& operator= ( const Param rhs  ) 

Assignment operator.

bool operator== ( const Param rhs  )  const

Equality operator.

void parseCommandLine ( const int  argc,
const char **  argv,
const String prefix = "" 
)

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")

Parameters:
argc argc variable from command line
argv argv varaible from command line
prefix prefix for all options

Referenced by main().

void parseCommandLine ( const int  argc,
const char **  argv,
const std::vector< ParameterInformation > &  parameters,
const String misc = "misc",
const String unknown = "unknown" 
)

Parses command line arguments using parameter definitions from TOPPBase.

Parses command line arguments according to parameter definitions made in TOPPBase (or a derived class) and stores the result internally.

Parameters:
argc argc variable from command line
argv argv variable from command line
parameters Information about registered parameters from TOPPBase
misc Key to store a StringList of all non-option arguments
unknown Key to store a StringList of all unknown options
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.

Parameters:
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
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.

Referenced by TOPPViewBase::connectToDB_(), and TOPPViewBase::preferencesDialog().

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

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.

Parameters:
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.
See also:
checkDefaults

Referenced by FeatureFinderAlgorithmSimplest< PeakType, FeatureType >::run(), and FeatureFinderAlgorithmSimple< PeakType, FeatureType >::run().

void setMaxFloat ( const String key,
DoubleReal  max 
)
void setMaxInt ( const String key,
Int  max 
)
void setMinFloat ( const String key,
DoubleReal  min 
)
void setMinInt ( const String key,
Int  min 
)
void setSectionDescription ( const String key,
const String description 
)
void setValidStrings ( const String key,
const std::vector< String > &  strings 
)
void setValue ( const String key,
const DataValue value,
const String description = "",
const StringList tags = StringList() 
)

Sets a value.

Parameters:
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::annotateWithID(), BaseModel< 2 >::BaseModel(), TOPPViewBase::connectToDB_(), FeatureFinderAlgorithmIsotopeWavelet< PeakType, FeatureType >::FeatureFinderAlgorithmIsotopeWavelet(), FeatureFinderAlgorithmMRM< PeakType, FeatureType >::FeatureFinderAlgorithmMRM(), FeatureFinderAlgorithmPicked< PeakType, FeatureType >::FeatureFinderAlgorithmPicked(), FeatureFinderAlgorithmSH< PeakType, FeatureType >::FeatureFinderAlgorithmSH(), ModelFitter< PeakType, FeatureType >::fitMZ_(), ModelFitter< PeakType, FeatureType >::fitRT_(), TOPPViewBase::getSpectrumParameters(), IDEvaluationBase::IDEvaluationBase(), TOPPViewBase::initializeDefaultParameters_(), TOPPViewBase::loadFiles(), TOPPViewBase::loadPreferences(), TOPPASBase::loadPreferences(), SpectraMerger::mergeSpectra_(), ModelFitter< PeakType, FeatureType >::ModelFitter(), TOPPViewBase::preferencesDialog(), FeatureFinderAlgorithmSimplest< PeakType, FeatureType >::run(), FeatureFinderAlgorithmSimple< PeakType, FeatureType >::run(), FeatureFinderAlgorithmPicked< PeakType, FeatureType >::run(), TOPPViewBase::savePreferences(), TOPPASBase::savePreferences(), BaseModel< 2 >::setCutOff(), TOPPViewBase::setIntensityMode(), TOPPViewBase::showSpectrumAlignmentDialog(), TOPPViewBase::showSpectrumGenerationDialog(), SignalToNoiseEstimatorMeanIterative< Container >::SignalToNoiseEstimatorMeanIterative(), SignalToNoiseEstimatorMedian< OpenMS::MSSpectrum< PeakT > >::SignalToNoiseEstimatorMedian(), SignalToNoiseOpenMS< PeakT >::SignalToNoiseOpenMS(), SimpleExtender< PeakType, FeatureType >::SimpleExtender(), SimpleSeeder< PeakType, FeatureType >::SimpleSeeder(), TOPPASBase::TOPPASBase(), TraceFitter< PeakType >::TraceFitter(), and TOPPViewBase::updateRecentMenu_().

Size size (  )  const

Returns the number of entries (leafs).

Referenced by TOPPViewBase::loadPreferences().

void update ( const Param old_version,
const bool  add_unknown = false,
Logger::LogStream stream = LOG_WARN 
)

Rescue parameter values from old_version to current param.

All parameters present in both param objects will be transferred into this object, given that:

  • the name is equal
  • the type is equal
  • the restrictions are equal

Not transferred are parameters with name "version" (to preserve the new version) or "type" (to preserve layout).

Parameters:
add_unknown Add unknown parameters to the param object. Default is false.
stream The stream where all the output is send to.

Member Data Documentation

Param::ParamNode root_ [mutable, protected]

Invisible root node that stores all the data.


OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:52 using doxygen 1.7.1