Ganga configuration system

Configuration in Ganga is centrally managed in these packages: Ganga.Utility.Config and Ganga.GPIDev.Lib.Config.

Some design objectives:

  • Experiment-specific configuration (for example plugin modules) may be defined at site config level.
  • Both Atlas and LHCb will shared the same release but will have different config files
  • Users may work with multiple ganga configurations and easily switch between them

INI file format

Configuration file format *.ini is defined by the standard python module ConfigParser http://docs.python.org/lib/module-ConfigParser.html

Configuration sequence

The overriding mechanism is a standard way of interpreting a sequence of INI files. Configs are loaded in sequence: user config overrides site config which overrides release config. User and site configuration is defined in the configuration files.

Special treatment of PATH-like options

There is one Ganga-specific rule for PATH-like options: if a name of an option is of form *_PATH then the value will not be overriden but prepended, for example:

file1.ini

ANY_PATH = x

file2.ini

ANY_PATH = y

The result of the merge of (file1.ini,file2.ini) is: ANY_PATH = y:x

You may also reset the value of the path completely if this is needed with the following syntax:

file1.ini

ANY_PATH = x

file2.ini

ANY_PATH = :::y

The result of the merge of (file1.ini,file2.ini) is: ANY_PATH = y

User configuration

User configuration file (default): $HOME/.gangarc

The location of the user config file may be set in the command line argument:

% ganga --config /my/path/config.ini

Site configuration

Site config is a file (or a sequence of files) which is defined from the GANGA_CONFG_PATH environment variable or which may be specified with -config-path command line option. It is a colon-separated sequence of the configuration files.

Example:

GANGA_CONFIG_PATH = /some/physics/subgroup.ini:GangaLHCb/LHCb.ini

In this example the /some/subgroup.ini will override the settings defined in GangaLHCb/LHCb.ini.The GangaLHCb/LHCb.ini is a relative path and it will be resolved with respect to the Ganga release area. In this way you depend on the default settings prepared for LHCb by Ganga release team but you customize some of them for your subgroup (and you stored them separately)

Default release configuration

Release config corresponds to the defaults hardcoded in the source code (see the section below to understand how to define default configuration in your code).

Defining the configuration in the source code

First create config object for your package. The corresponding section in the configuration file will have the same name.

import Ganga.Utility.Config 
config = Ganga.Utility.Config.getConfig("YOUR_PACKAGE")

Assign default values using one of the following methods. These values will be in the default release configuration.

config['option1'] = val1
config.setDefaultOptions({'opt1':'x','opt2':'y','opt3':'z'})

At runtime in your code you may retrieve the value of the options. Note that you will get the effective values. The effective value takes into account default, session and user settings and may change at runtime.

print config['option1']

Note: Because the options may be changed in a different thread by the user, the long-lasting operations should first get the value of the options to avoid surprising change in the course of the execution.

However you should not cache the value of the option in static or global variables for more time than it is neccessary.

User access to the configuration

Ganga user has the access to the effective configuration with the predefined config object. Access to the configuration options defined above is provided as:

>>> print config.YOUR_PACKAGE.option1
val1

Alternative syntax allows to handle option or section names which are not legal python identifiers for the dot-syntax above:

>>> print config['YOUR_PACKAGE']['option1']
val1

Actions on user configuration changes

You may also attach the callback handlers which will be called every time a user modifies an option via the GPI.

def pre(opt,val):
    print 'always setting a square of the value'
    return val*2

def post(opt,val):
    print 'effectively set',val
    
config.attachUserHandler(pre,post)

-- JakubMoscicki - 18-Feb-2011

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2011-02-18 - JakubMoscicki
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    ArdaGrid All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2023 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