Gaudi Conditions Database How-To

Friday April 23 2005, the first production version of COOL has been released. It means that it's time to start trying to use it.

Note: this page changes often, so... stay tuned!


You do not need anymore to do special things to start using the DetCond package since it is included in LHCb. (There is a bug in the version of DetCondExample shipped with LHCb v19r4, we have to use v20r0).

Starting from a clean $HOME/cmtuser:

setenv LHCb_release_area $LHCBDEV
LHCbEnv v20r0
source $LHCb_release_area/LHCB/LHCB_v20r0/Ex/DetCondExample/v7r10/cmt/setup.csh
./DetCondExample.exe ../options/fillCondDB.opts
./DetCondExample.exe ../options/testCondDB.opts

The CondDB will be in the file $HOME/CONDDB.sqlite


DetCond package (interface to COOL)

Now that COOL is publicly available and that DetCond is in the last LHCb release, it's time to start using it. I'll tell you how.

Create and populate a database
Of course, to get informations from a database, you need a database with something inside.
(Many examples can be found in the package Ex/DetCondExample)

First of all you need an access to a database server. Currently, only MySQL and Oracle are supported. If you want to use Oracle, you should obtain your own Oracle developement account asking to [] (a public account is available on devdb, if you really need it NOW: user=conddb_test, pw=lcg, host=devdb). For MySQL there is no CERN service, but few private servers for which you can ask an account (some infos are in the COOL How-To, or you can [][ask me]] for an account on mine).

Once you have the account informations, you have to set up your option file. Add these lines:

ApplicationMgr.DLLs += { "DetCond" };
ApplicationMgr.ExtSvc += { "CondDBAccessSvc" };
CondDBAccessSvc.HostName = "_an hostname_";
CondDBAccessSvc.User     = "_user name_";
CondDBAccessSvc.Password = "_password_";
CondDBAccessSvc.Database = "_database name (8 chars all upper case)_";
CondDBAccessSvc.Schema   = "_schema name (=username in Oracle)_";
CondDBAccessSvc.BackEnd  = "_oracle or mysql or sqlite_";

Now you can create an empty database by just running your job (if the database is not there, it is created automatically). Probably you will need soon to delete a database in order to restart from scratch (you cannot delete a single object), there is a way to do it: add the option CondDBAccessSvc.RecreateDB = true; (probably it will change in the future for safety reasons).

In order to populate your new database, you must learn few concepts.
The informations in the conditions database are organized in a hierarchical structure made of 3 types of nodes:

  • FolderSets: nodes that are used to group other nodes
  • 2 types of Folders (or leaf-nodes):
    • Single-Version Folders: containing data object without overlapping Intervals Of Validity (IOVs)
    • Multi-Version Folders: containing data objects that may have IOVs which overlaps
Each data object consists of a payload (the content) and an IOV. To identify an object you must use:
  • the path to the leaf folder associated to that type of object (a string like "/path/to/my/object")
  • the time at which the object should be valid (if you have 2 objects with the IOVs [0;10[ and [10;20[, and you ask for the time 15, you get the object with IOV [10;20[)
  • for multi-version folders you may have many objects valid at a given time and you can distinguish between them using an identifier called tag (if you do not specify any tag, you will get the object that was inserted most recently, equivalent to the tag "HEAD")

OK, let's create our tree!
In your algorithm implementation file put something like:

#include "DetCond/ICondDBAccessSvc.h"


ICondDBAccessSvc *accSvc = svc<ICondDBAccessSvc>("CondDBAccessSvc");

// for a FolderSet
accSvc->createFolder("/path/to","a FolderSet",ICondDBAccessSvc::FOLDERSET);

// for a SingleVersion Folder (XML format)
accSvc->createFolder("/path/to/the/online-cond","a single version folder",ICondDBAccessSvc::XML,ICondDBAccessSvc::SINGLE);

// for a MultiVersion Folder (XML format)
accSvc->createFolder("/path/to/the/cond","a multi-version folder");
Easy, isn't it? wink (you can go to the file DetCond/ICondDBAccessSvc.h for more informations)

Now it's time to put real data into the folders. Objects of all the classes that inherits from ValidDataObject can go to the CondDB (if they have an XML converter), but I'll focus on Condition objects.
Condition inherits from ParamValidDataObject (as DetectorElement), which means that is essencially a flexible container of parameters. The types supported by the XML converter are:

  • int
  • double
  • std::string (aka other)
  • std::vector<int>
  • std::vector<double>
  • std::vector<std::string>
This is only a limitation of the converter, so you can put in there (almost) any type you like, but you'll not be able to do it through XML.
Creating a Condition and storing it to the opened DB instance is fairly easy:
Condition myCond; // create the condition
std::vector<int> channels;
myCond.addParam<std::vector<int> >("channels",channels);

The syntax of ICondDBAccessSvc::storeXMLString() needs clarification. The first parameter is the path to the folder in the CondDB, the second is an XML string, the other two are the extremes of the IOV (see GaudiKernel/TimePoint.h). Condition::toXml() is, of course, a function to automatically convert a condition to an XML string, and you must give to it an object name that will be used when reading the object from the detector transient store.

In the following section I'll explain how to access the conditions through the detector transient store.

Usage of conditions
The tree of the Detector Transient Store (DTS) is defined in the XML files contained in the package Det/XMLDDDB, and if you want your conditions to be accessible through DTS you need entries there like (referring to the example of the previous section):
<conditionref href="conddb:/path/to/the/cond#CondName"/>
The package Ex/DetCondExample contains a private, simplified XMLDDDB than can be used to learn how you can modify the official one.

If you have in your dddb.xml something like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DDDB SYSTEM "DTD/structure.dtd">
  <catalog name="dd">
    <catalog name="Conditions">
      <catalog name="MyDetector">
        <conditionref href="conddb:/path/to/the/cond#CondName"/>
you can access the condition from your GaudiAlgorithm with:
Condition *myCond = getDet<Condition>("/dd/Conditions/MyDetector/CondName");
... a piece of cake! smile

DetectorElements have a special way of handling conditions. When a D.E. uses a condition, it can be linked to it by adding in its XML description the tag conditioninfo

<conditioninfo name="TheCondition" condition="/dd/Conditions/MyDetector/CondName" />
You'll be able to access the condition from the DetectorElement with the method DetectorElement::condition() which has the prototype
virtual SmartRef<Condition> condition(const std::string &name) const;
An example (in your GaudiAlgorithm):
SmartDataPtr<DetectorElement> myDetEl(detSvc(), "/dd/Structure/LHCb/MyDetector");
SmartRef<Condition> myCond = myDetEl->condition("TheCondition");
Since GaudiKernel v19r2, it is possible to get the path associated to a SmartRef, so:
std::string myCondPath = myDetEl->condition("TheCondition").path();

-- MarcoClemencic - 25 Apr 2005

-- MarcoClemencic - 09 Feb 2006

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatcsh DetCondExample-LHCb_v18r3.csh r2 r1 manage 1.5 K 2005-05-11 - 16:24 MarcoClemencicSecondary shell script to install and run DetCondExample v7r0
Unknown file formatcsh DetCondExample-LHCb_v18r4.csh r1 manage 1.8 K 2005-05-13 - 19:36 MarcoClemencicSecondary script to install DetCondExample (LHCb v18r4)
Edit | Attach | Watch | Print version | History: r15 < r14 < r13 < r12 < r11 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r15 - 2013-03-20 - IllyaShapoval
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    LHCb All webs login

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