BaseSimulator

All aotmic models for PhaseI will inherit from the new class BaseSimulator::Simulator.

The BaseSimulator class:

  • has a member variable double sigma.
  • has a member variable IPowerDEVSLogger logger
  • Implements the exit and ta abstract functions of Simulator
  • exposes a new function BaseSimulator::debugMsg(int level, const char *fmt,...). It is similar to printLog, but uses the configuration to filter unimportant messages. See next section.

Debug Message Logging

Para escribir mensajes de logging, mejor utilizar la funcion debugMsg (en vez de printLog), que permite prender y apagar los nivel del logueo desde la configuracion (tanto a nivel global como modelo por modelo).

BaseSimulator::debugMsg(int level, const char *fmt,...)

Printlog igual sigue estando por compatibilidad y porque la usa debugMsg por tras. In some future we can use something more robust like Boost Log

Configurating debug message logging

En la configuración se puede usar la variable debugLevel para habilitar mas o menos mensajes de logging. debugLevel es a nivel global, que van a usar todos los modelos. Tambien se pueden usar variables <NomberModelo>.debugLevel para setearle el nivel de logueo a un modelo en especifico.

Por ejemplo, si estoy programando un nuevo modelo atomico MyModel:

  1. quiero que todo el resto de los modelos no impriman nada. Para eso seteo el debugLevel global para que unicamente se impriman las cosas importantes:
    debugLevel = LOG_LEVEL_IMPORTANT
  2. Quiero que el nuevo modelo que estroy programando imprima todos los mensajes asi puedo debuguearlo. Para eso seteo el nivel de logueo para ese modelo en particular:
    MyModel.debugLevel = LOG_LEVEL_ALL

Using the debugMsg in atomic models (C++)

The header of the function is:

BaseSimulator::debugMsg(int level, const char *fmt,...)

In an atomic model you can use it as follows:
debugMsg(LOG_LEVEL_IMPORTANT, "[%f] Very important message from model %s \n", t, this->getName());

debugMsg(LOG_LEVEL_PRIORITY, "[%f] An important message from model %s \n", t, this->getName());

debugMsg(LOG_LEVEL_DEBUG, "[%f] just a debug message from model %s \n", t, this->getName());

Variable Logging

To log variables (for example to Scilab) a few signature changed to allow for setting priorities to the variables in the configuration. In some close future it will allow to set samplers in configuration.

Configuration

It is very similar to the model of the debug messages, only that the configuration variable to use is logLevel. Also the logLevel can be set globally, per model, or per variable:

  1. The logLevel configurationvariable sests the global level.
  2. The <ModelName>.logLevel sets the level of a specific model, overriding the global configuration
  3. The <ModelName>.<VariableName>.logLevel sets the level for a specific variable, overriding the model and global configurations.
Ej: to log only priority variables from MyModel and only the MyVariable from MyModel2

logLevel=NONE

MyModel.logLevel = PRIORITY

MyVariable = ALL

Using the logger in atomic models (C++)

The instanciation of the logger object is done by the BaseSimulator in the init methiod.

So make sure to:

Specify the variables and priorities you want to log:
  • In your init function call the initSignals method:
    this->logger->initSignals({
    {"veryImportantVar", SCILAB_LOG_LEVEL_ALWAYS},
    {"someVar", SCILAB_LOG_LEVEL_PRIORITY },
    {"justForDebugging", SCILAB_LOG_LEVEL_DEBUG }
    });
Log the variables when they change:

this->logger->logSignal(t, this->importantValue, "veryImportantVar");

-- MatiasAlejandroBonaventura - 2016-06-03

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r7 - 2017-04-10 - MatiasAlejandroBonaventura
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback