
#include <Component/ModelManager.H>
Inheritance diagram for ModelManager:


ModelManager should be implemented once in each executable, and will facilitate the management of a collection of ModelComponent objects, load/save of tunable ModelParamBase parameters that may be in those objects, and generation/parsing of command-line options. ModelComponent objects must manually register with the ModelManager to fall under its management. Typically, when a ModelComponent has subcomponents, only the top-level component should be registered with the ModelManager, as all ModelParamBase access functions will recurse through the ModelComponent's subcomponents. See test-model.C and test-audioGrab.C for simple examples of how to write executables that are managed by ModelManager.
Definition at line 62 of file ModelManager.H.
Public Member Functions | |
| virtual void | paramChanged (ModelParamBase *const param, const bool valueChanged, ParamClient::ChangeStatus *status) |
| Intercept people changing our ModelParam's. | |
Constructors and Destructors | |
| ModelManager (const std::string &descrName="The Model", const std::string &tagName="model", const bool loadCfgOpt=true, const bool saveCfgOpt=true, const bool autoLoadCfg=true) | |
| Default constructor. | |
| virtual | ~ModelManager () |
| Virtual destructor ensures proper destruction of derived classes. | |
| bool | debugMode () const |
| Returns true if we are running in debug mode. | |
Model option database | |
| void | allowOptions (const int mask) |
| Only allow ModelOptionDef's that match the given mask. | |
| virtual void | requestOption (OptionedModelParam &p, const bool useMyVal=false) |
| ModelComponent objects may request a command-line option here. | |
| virtual void | unRequestOption (OptionedModelParam &p) |
| Request the removal of a param from the command-line options. | |
| virtual void | requestOptionAlias (const ModelOptionDef *def) |
| Users may request model option aliases. | |
| virtual void | setOptionValString (const ModelOptionDef *def, const std::string &val) |
| Set an option value. | |
| virtual std::string | getOptionValString (const ModelOptionDef *def) |
| Get an option value. | |
| virtual bool | isOptionRequested (const ModelOptionDef *def) const |
| Check if anybody has requested the given option. | |
Alternative access to internal options | |
These functions may be useful for alternative methods of displaying the help for command-line options (e.g. in the Qt ModelManagerWizard). | |
| virtual uint | numOptionDefs () const |
| Get the number of ModelOptionDef objects in our list. | |
| virtual uint | getOptionDefs (const ModelOptionDef **arr, uint narr) |
| Get ModelOptionDef objects from our list, up to the size of the given array. | |
| virtual const ModelOptionDef * | findOptionDef (const char *name) const |
| Get the ModelOptionDef for the given name. | |
| virtual bool | isOptionDefUsed (const ModelOptionDef *def) const |
| Query if the given ModelOptionDef is used in this program. | |
Command-line parsing | |
| bool | parseCommandLine (const int argc, const char **argv, const char *usage, const int minarg, const int maxarg) |
| Parse all command-line options and set our params. | |
| bool | parseCommandLine (const int argc, char *const *argv, const char *usage, const int minarg, const int maxarg) |
| Overload that takes a argv array of non-const strings. | |
| bool | parseCommandLineCore (const int argc, const char **argv) |
| The core of parseCommandLine(). | |
| bool | parseCommandLineCore (const char *args) |
| uint | numExtraArgs () const |
| Get the number of available extra args. | |
| std::string | getExtraArg (const uint num) const |
| Get an extra arg, by number. | |
| template<class T> | |
| T | getExtraArgAs (const uint num) const |
| Get an extra arg converted to type T. | |
| void | clearExtraArgs () |
| Clear our list of leftover command-line arguments. | |
Persistent ModelParamBase management | |
| void | loadConfig () |
| Load all our ModelParamBase values from file. | |
| void | loadConfig (const std::string &fname) |
| Explicitly load all our ModelParams from file. | |
| void | saveConfig () const |
| Save all our ModelParams to file. | |
| void | saveConfig (const std::string &fname) const |
| Explicitly save all our ModelParams to file. | |
Protected Member Functions | |
| void | setFPE (bool val) |
| void | unRequestTestMode () |
| void | unRequestUsingFPE () |
| virtual void | start1 () |
| This is called from within start() before the subcomponents start. | |
| virtual void | start2 () |
| This is called from within start() after the subcomponents have started. | |
| virtual void | stop1 () |
| This is called from within stop() before the subcomponents stop. | |
Classes | |
| struct | Impl |
| This is the internal implementation struct for ModelManager. More... | |
|
||||||||||||||||||||||||
|
Default constructor.
Definition at line 131 of file ModelManager.C. References ModelManager::Impl::autoLoadConfig, ModelManager::Impl::com, ModelManager::Impl::didSave, OModelParam< T >::getOptionDef(), invt_install_fancy_terminate(), OModelParam< T >::make(), OPT_LoadConfigFile, OPT_SaveConfigFile, ModelManager::Impl::paramDebugMode, ModelManager::Impl::paramFpuPrecision, ModelManager::Impl::paramFpuRoundingMode, ModelManager::Impl::paramLoadConfigFname, ModelManager::Impl::paramSaveConfigFname, requestOption(), ModelComponent::setManager(), and setOptionValString(). |
|
|
Virtual destructor ensures proper destruction of derived classes.
Definition at line 193 of file ModelManager.C. References ModelComponent::managerDestroyed(), and ModelComponent::stop(). |
|
|
Only allow ModelOptionDef's that match the given mask. This mask is used to filter requestOption() calls -- if the ModelOptionDef's filterFlag isn't part of ModelManager's current mask, then the requestOption() is ignored. Definition at line 218 of file ModelManager.C. References CmdlineOptionManager::allowOptions(), ASSERT, and ModelManager::Impl::com. Referenced by main(), and mexFunction(). |
|
|
Clear our list of leftover command-line arguments.
Definition at line 614 of file ModelManager.C. References ASSERT, CmdlineOptionManager::clearExtraArgs(), and ModelManager::Impl::com. Referenced by MexModelManager::parseMexCommandLine(). |
|
|
Returns true if we are running in debug mode. Debug mode can be invoked via the --debug command-line option. Programs can use this function to do additional debug outputs if the manager is in debug mode. In addition, we will generate a debug printout of all model parameters just before start() and we will force the log level to LOG_DEBUG (see log.H) if debug mode is on. Definition at line 600 of file ModelManager.C. References ASSERT, OModelParam< T >::getVal(), and ModelManager::Impl::paramDebugMode. Referenced by main(). |
|
|
Get the ModelOptionDef for the given name. Aborts if there is no such ModelOptionDef. Implements OptionManager. Definition at line 372 of file ModelManager.C. References ModelManager::Impl::com, and CmdlineOptionManager::findOptionDef(). Referenced by modelmanager_xx_findoptiondef_xx_1(). |
|
|
Get an extra arg, by number.
Definition at line 351 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::getExtraArg(). Referenced by main(). |
|
||||||||||
|
Get an extra arg converted to type T.
Definition at line 326 of file ModelManager.H. References convertFromString, and val. Referenced by main(). |
|
||||||||||||
|
Get ModelOptionDef objects from our list, up to the size of the given array. Returns the number of array entries that were actually filled with valid ModelOptionDef pointers. Implements OptionManager. Definition at line 365 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::getOptionDefs(). Referenced by ModelManagerWizard::refreshOptions(). |
|
|
Get an option value. The value returned here is the value currently held by the ModelManager. This value is updated in three cases: 1) when a new component requests the option using requestOption() with useMyVal true; 2) when setOptionValString() is called, and 3) when the command-line arguments are parsed by ParseCommandLine, if a value for this option has been specified in the command line. If ModelComponent objects modify their local ModelParam values for their local parameter with this name, the value returned here will not be affected. Implements OptionManager. Definition at line 262 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::getOptionValString(). Referenced by modelmanager_xx_findoptiondef_xx_1(), processSplitImage(), and ModelManagerWizard::refreshOptions(). |
|
|
Query if the given ModelOptionDef is used in this program.
Implements OptionManager. Definition at line 378 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::isOptionDefUsed(). Referenced by ModelManagerWizard::refreshOptions(). |
|
|
Check if anybody has requested the given option.
Implements OptionManager. Definition at line 269 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::isOptionRequested(). |
|
|
Explicitly load all our ModelParams from file. This function will always load the params from the given file, even is --load-config-from=X was not specified. Definition at line 394 of file ModelManager.C. References LINFO, ParamMap::load(), and ModelComponent::readParamsFrom(). |
|
|
Load all our ModelParamBase values from file. This function is automatically called during parseCommandLine() if --load-config-from=XX option is encountered or autoload was specified in our constructor (thus ensuring that command-line options encountered after the option specifying which config file to load are applied after the config file has been loaded). It may also be called manually. This function is a no-op if no filename is in our loadConfigFile internal ModelParam (this parameter can be set by the --load-config-from=X command-line option). Otherwise, load the file (which should be a ParamMap) and configure all our parameters. Definition at line 385 of file ModelManager.C. References ASSERT, rutz::shared_ptr< T >::get(), and ModelManager::Impl::paramLoadConfigFname. Referenced by ModelManagerControl::loadConfig(), main(), and paramChanged(). |
|
|
Get the number of available extra args.
Definition at line 344 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::numExtraArgs(). Referenced by main(), and MexModelManager::parseMexCommandLine(). |
|
|
Get the number of ModelOptionDef objects in our list.
Implements OptionManager. Definition at line 358 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::numOptionDefs(). Referenced by ModelManagerWizard::refreshOptions(). |
|
||||||||||||||||
|
||||||||||||||||||||||||
|
Overload that takes a argv array of non-const strings.
|
|
||||||||||||||||||||||||
|
Parse all command-line options and set our params. This function will create a set of command-line options from our current collection of OptionedModelParam objects. It will then parse the command-line arguments and set the various option values accordingly, using a call to setOptionValString(). Any left-over args (i.e., not formatted as options) will be available through getExtraArg(), and if the number of such extra args is not within the specified minarg/maxarg bounds, a usage message and optionlist will be printed out (also printed out if a '--help' option is encountered). To decide which options should be exported by your various ModelComponent objects, typically you will call exportOptions() on the manager, which will propagate the call to all registered components. Here we have an additional default behavior that if exportOptions() has not been called on us, we will call it with an order to export all options, just before we start parsing the command-line. So, if you want to export all options, you don't have to do anything; if you want to only export special classes of options, then you will need to call exportOptions() manually some time before you parse the command-line. Returns true upon fully successful parse.
Definition at line 276 of file ModelManager.C. References ASSERT, ModelManager::Impl::autoLoadConfig, ModelManager::Impl::com, ModelComponent::exportOptions(), LFATAL, LINFO, ParamMap::load(), MC_RECURSE, CmdlineOptionManager::parseCommandLine(), and ModelComponent::readParamsFrom(). Referenced by main(), run_master(), and run_slave(). |
|
||||||||||||
|
The core of parseCommandLine(). This may be called recursively to handle command-line aliases. Note: beware that the first element of argv will be ignored (as it usually is the program name). Definition at line 330 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::parseCommandLineCore(). Referenced by MexModelManager::parseMexCommandLine(). |
|
||||||||||||
|
ModelComponent objects may request a command-line option here.
Implements OptionManager. Definition at line 225 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::requestOption(). Referenced by ModelManager(), and modelmanager_xx_defaultvalue_xx_1(). |
|
|
Users may request model option aliases.
Implements OptionManager. Definition at line 247 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::requestOptionAlias(). |
|
|
Explicitly save all our ModelParams to file. This function will always save the params to the given file, even is --save-config-to=X was not specified. Definition at line 411 of file ModelManager.C. References ParamMap::format(), LINFO, and ModelComponent::writeParamsTo(). |
|
|
Save all our ModelParams to file. This function is a no-op if no filename is in our saveConfigFile internal ModelParam (this parameter can be set by the --save-config-to=X command-line option). Otherwise, save all our params to the file as a ParamMap. Returns true on success. You should typically call this either some time before you start() your model, or after you have stop()'ed it. NOTE: There is a default behavior which is to call this as the first thing in start(), i.e., just before all our registered components will be started, unless you have manually called it yourself earlier, in which case it is not called again. Definition at line 402 of file ModelManager.C. References ASSERT, rutz::shared_ptr< T >::get(), and ModelManager::Impl::paramSaveConfigFname. Referenced by main(), ModelManagerControl::saveConfig(), and start1(). |
|
||||||||||||
|
Set an option value. All ModelParam objects associated this ModelOptionDef will be updated with the new value. Will throw a fatal error if the model has been started (see ModelComponent::start()). Implements OptionManager. Definition at line 254 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, and CmdlineOptionManager::setOptionValString(). Referenced by ModelManagerWizard::handleCheckBox(), ModelManagerWizard::handleLineEdit(), mexFunction(), ModelManager(), modelmanager_xx_defaultvalue_xx_1(), modelmanager_xx_findoptiondef_xx_1(), ObjRecSalBayes::ObjRecSalBayes(), and paramChanged(). |
|
|
This is called from within start() before the subcomponents start.
Reimplemented from ModelComponent. Definition at line 419 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, convertToString(), rutz::demangled_name(), ModelManager::Impl::didSave, CmdlineOptionManager::getArg(), getFpuPrecision(), getFpuRoundingMode(), OModelParam< T >::getVal(), LINFO, ModelManager::Impl::paramDebugMode, ModelManager::Impl::paramEchoArgs, ModelManager::Impl::paramTestMode, ModelManager::Impl::paramUsingFPE, ModelComponent::printout(), and saveConfig(). |
|
|
This is called from within start() after the subcomponents have started.
Reimplemented from ModelComponent. Definition at line 453 of file ModelManager.C. References ASSERT, CpuTimer::reset(), and ModelManager::Impl::timer. |
|
|
This is called from within stop() before the subcomponents stop.
Reimplemented from ModelComponent. Definition at line 461 of file ModelManager.C. References ASSERT, CpuTimer::mark(), CpuTimer::report(), and ModelManager::Impl::timer. |
|
|
Request the removal of a param from the command-line options.
Implements OptionManager. Definition at line 233 of file ModelManager.C. References ASSERT, ModelManager::Impl::com, LERROR, and CmdlineOptionManager::unRequestOption(). Referenced by unRequestTestMode(), and unRequestUsingFPE(). |
1.4.4