next up previous contents
Next: Raw Data and Rotorooter Up: The MINOS Off-line Software Previous: Navigation   Contents




Last significant change: 2002/07/26

A Registry is a heterogenous and hierarchical collection similar to an STL map. It is a one to one association of a key to a value. The key is of the type const char* and the values can be of various types (thus ``heterogenous'') and are accessed in type safe ways. The currently implemented types of values are the basic ones (int, double, char, char*) as well as Registry itself (thus ``hierarchical'').

Registry is used to hold configuration information for various parts of the framework, including Algorithms (see sec. 3), Job Modules (sec. 1) and the Midad library (sec. 20).

Finally, Registry can go through ROOT I/O so it is possible to save them in the data stream for later read back.

Basics of Registry

This section walks through the life and times of a typical Registry.


Usually one creates a Registry on the stack as it can be passed by value. When copied, each stored value will also be copied. Here is the trivial construction:

    Registry reg;

This default constructor will setup the Registry to allow any new key/value pairs to be added, but it will disallow the changing of values after the initial setting. In this case the Registry is considered to have its keys unlocked and its values locked.

You can create a Registry whose values are immediately changeable by passing in false at construction time:

    Registry reg(false);

You can also manipulate and query the value lock with the ValuesLocked(), LockValues() and UnLockValues() methods. There are three similar method for the key lock.

Setting values

To set values, not surprisingly, you use the Set() method. There are a number of these methods, one for each type that Registry can hold. Here is an example showing the act of setting each type:

    Registry reg;
    reg.Set("my int",42);
    reg.Set("my double",6.9);
    reg.Set("my character",'x');
    reg.Set("my string","Hello World!");
    Registry reg2;
    reg.Set("my Registry",reg2);

In the case of int and double, you must be be aware of the type. If you want a double which happens to be an integral value, make sure you use a decimal (ie, if you want to store ``2'' as a double you must use ``2.0'').

Getting values

Getting a value back from a Registry takes a bit more effort as there needs to be a way to communicate success or failure at finding the key and getting the correct type for the value. The safe way is to use the Get() methods like:

    int x=0;
    if (!reg.Get("my int",x)) {
        cerr << "Failed to get \"my int\"\n";

However, if you are absolutely sure that your value is both in the Registry and the correct type, you can use the less safe, but syntactically sweeter GetTYPE() form:

    int x = reg.GetInt("my int");

If there is a failure, then ``zero'' is returned.

To make this slightly safer, you could test if the key exists before asking for it:

    int x = 0;
    if (reg.KeyExists("my int")) x = reg.GetInt("my int");
    else cerr << "No such key: \"my int\"\n";

Iterating on the keys

You can iterate over all keys in a registry via the RegistryKey iterator and the Key() method. For example:

    Registry reg;
    //... fill reg ...

    Registry::RegistryKey rk = reg.Key();
    cerr << "dumping "<<reg.Size()<<" keys:\n";
    while ( (const char* s = rk()) ) {
        cerr << "  " << s << "\n";

Using the Set() examples above to fill the Registry this code would print out something like:

    dumping 5 keys:
        my int
        my double
        my character
        my string
        my Registry

Miscellaneous Methods

Here is a grab bag of other things one can do with a Registry.

    Registry r1, r2;
    // ...
    // Assign one Registry to another:
    r1 = r2;

    // Merge one registry with another.  This is like assignment except
    // any keys in r1 but not in r2 will not be removed:

    // Get the number of keys in a Registry
    cout << "Reg1 has " << r1.Size() << " keys\n";

    // Dump a Registry to some ostream:
    cout << r1 << endl << r2 << endl;

next up previous contents
Next: Raw Data and Rotorooter Up: The MINOS Off-line Software Previous: Navigation   Contents
Minos software 2019-07-07