Adding parameters from the global configuration to the modules

Hello,

I have several detector modules that require the same parameter. Therefore, I would like to set it only once in the global configuration “[Corryvreckan]” and retrieve it from there. Is this possible?

I have added it to the .config file as follows:


[Corryvreckan]
key = “value”

In the module file, I am attempting to retrieve it in the constructor with:


std::string key = config_.get(“key”)

This is similar to how I handle all other parameters. However, despite my understanding that it should be retrievable from the global configuration, it is not working. Instead, it gives me a fatal error stating that the parameter is not defined for this particular module.

I have also attempted the following:


ConfigManager* conf_manager = getConfigManager();
std::string key = conf_manager->getGlobalConfiguration().get(“key”);

However, I receive an error stating “Cannot access the config manager in constructor or destructor.”

I am now pondering the meaning of section 4.2 in the user manual, which states:

“The global (framework) header sections: These are all zero-length section headers
(including the one at the beginning of the file) and all sections marked with the header
[Corryvreckan] (case-insensitive). These are combined and accessed together as the
global configuration, which contains all parameters of the framework itself as described in
Section 3.3. All key-value pairs defined in this section are also inherited by all individual
configurations as long the key is not defined in the module configuration itself. This is
encouraged for module parameters used in multiple modules.”

I believe I may be overlooking something. Could one of the experts assist me?

Thank you,
Elena

Hi @esidoret

just to ensure I understand your need correctly - is it correct that you e.g. have

[MyModule]
name = "detector1"

[MyModule]
name = "detector2"

[MyModule]
name = "detector3"

[MyModule]
name = "detector4"

and would now like to share a parameter among them?

Your attempted access of the global config is correct, but you cannot do it in the constructor if your module (MyModule::MyModule(/*...*/) because it’s not ready there. If you place the same code in MyModule::initialize() it should work!

Best,
Simon

Hello,

That worked for me!

Thank you,
Elena