IOV Iterator Utility API documentation and Tutorial

Complete: 3

API documentation


 Template <class T>  class CondIter 
Whenever you need to access the database in order to obtain data from Calibration/Alignment what you need to know is only the name of the database and the kind of data inside. You can download the database on your local machine (useful for testing programs) and then interface to it through the class CondIter<> or you can access directly the database through the class CondIter<> itself. In the following instructions the class T is a generic class whose objects are recorded in the database (e.g. EcalPedestals).
Conditions data are stored in IOVs. More information about what is an IOV are available here

 Constructor CondIter() 
when you instantiate the class CondIter<> you don't create the bond between the class and the database, but you only prepare the class to access a generic database.

  void create(const std::string & NameDB, const std::string & File, const std::string & User = "", const std::string & Pass = "", const std::string & nameBlob = "") 
with this method you link the class CondIter<> to the database. After this call CondIter can be used. It needs:

  • NameDB -> name of the database
  • File -> Tag human-readable of the content of the database
  • User -> name of the User (if you don't need to authenticate don't write anything here, or write "")
  • Pass -> Password to access database (if you don't need to authenticate don't write anything here, or write "")
  • nameBlob -> name of the blobstreamer in order to handle blob type of data (if you don't need it don't write anything here)

If you want to access the database which is on your local machine you have to use as NameDB the following string: sqlite_file:name.db. If you want to access directly the database you have to write the url. For some examples look at the tutorials .

 T const * next() 
with this method you pass through the set of data in the database from one Interval of Validity to the following.

  unsigned int getTime() 
get the mean time of the Interval of Validity: it can be a time or a run number, it depeds on how the data had been written.

 unsigned int getStartTime() 
get the SINCE time of the Interval of Validity

unsigned int getStopTime()
get the TILL time of the Interval of Validity

void setRange(unsigned int min,unsigned int max)
set the minimum and the maximum of the range of interest of the Iterator of the IOVs: thus when you call the method next() you get from min up to max

 void setMin(unsigned int min) 
set the minimum of the range of interest of the Iterator of the IOVs: thus when you call the method next() you get from min

 void setMax(unsigned int max)
set the maximum of the range of interest of the Iterator of the IOVs: thus when you call the method next() you get up to max


In order to optimize the speed of multiple access to the database a new class has been developed: CondCachedIter. This implemented class stores a vector of pointers of T inside and accesses those elements whenever the vector has been already filled. If for example you want to access one kind of member in the object retrieved from the database and then you want to access another one, the only thing you have to do is to call the method rewind and restart with the method next. Since most of the methods of the class CondCachedIter are the same as those of the class CondIter, you can choose which of the classes to use as you want and use the same methods.

 void rewind() 
with this method you come back to the beginning of the vector of pointer of T. You need this if you want to plot something for example two times.

 void drop() 
with this method you destroy the last object inserted in the voctor of pointers of class T.

 void clear() 
with this method you destroy all the elements of the vector of pointers of T. After thar you can reuse the class as from the beginning without calling the method create() anymore.

NB: if the number of IOVs is very large and if the objects stored are big, the use of class CondCachedIter may cause an excessive use of heap and may block the program. If methods rewind, drop and clear aren't required the use of CondIter is suggested.


Since in the CMSSW framework it's needed to mention all the templated classs used in the product, it has been developed a new class CondBasicIter which lies below the previous classes and performs the basic instructions such as linking with the database. The user is advised to use the classes CondIter and CondCachedIter in order to access the database.


How to create Iterators of new kind of objects

In order to create CondIter < T > where T is a new class not yet included in the CMSSW framework, you have to:

  • Write in the file CondTools/Utilities/test/classes.h:
    • #include "CondFormats/T/interface/T.h"
      (if not yet present).
    • CondIter< T > dummy;
      in the namespace.
  • Write in the file CondTools/Utilities/test/classes_def.xml:
    • < class name="CondIter< T >"/>
  • cvs the module where is defined the new class T (e.g. CondFormats/T).
  • scramv1 b in the folder CondTools/Utilities

Now you can use the class CondIter< T >. Remember to load the libCondFormats in the rootlogon.C file with the instruction

If you want to use the class CondCachedIter< T > you have to follow the same instructions.

How to configure

In order to use this class through ROOT you have to write in the rootlogon.C the following code:

where the library "libCondFormatsEcalObjects" has been chosen in order to analyse the EcalPedestals data, howevere here you can load whatever library you want. Then you have to start ROOT with the command root.exe thus you load automatically the libraries.

Speed Power

The class CondCachedIter < T > has been developed from the previous class CondIter in order to optimize the speed of creation of plot. A simple performing test has been developed to see if the processing time decrease. There is an huge (at least 10x for direct access to database and 1.5x for access to local machine database) saving of time. The test program testCondIter_Performance.cpp in CondTools/Utilities/test performs a local database access and tests the speed of cached access (cfr Trial.eps), while the test program testCondIter_PerformanceDirect.cpp performs a remote database access and tests the speed of cached access.


Access conditions data in local sqlite database in FWLite/ROOT

In order to access the database you need:

  • A database
  • A Tag, which is a human-readable name through which you can access to a specific object in the database
  • What kind of object there is in your database

Here is an example:

std::string NameDB = "sqlite_file:///afs/";
std::string TagData = "SiStripFedCabling_v1";
Then you need to create your Iterator of IOVs. First you have to instantiate the Iterator and then you have to link the Iterator with the database. In the following example the kind of object in the database is SiStripFedCabling.
CondIter <SiStripFedCabling> *Iterator = new CondIter <SiStripFedCabling>;
Iterator->create (NameDB,TagData);
Now you can access the database with the simple instruction
const SiStripFedCabling* reference;
reference = Iterator->next();
After the previous instructions reference points to an object in the database. Once you have reference you can do several things. In this particular example (SiStripFedCabling) you can call the method print(std::stringstream&) and print the content of the object in the database on the standard output (for a further example see Print Implementation).
std::stringstream Inside;
reference = Iterator->next();
std::cout << Inside.str();
In order to use the previous code in ROOT framework you have to load libraries: just write in the file rootlogon.C (if not yet present create it) the following code
and then use the command root.exe.

Complete text code avaiable here: testCondIter_PrintA.cpp. You can run it inside ROOT framework with the instruction .x testCondIter_PrintA.cpp. The program creates one file DataA.txt with the dump of the content the object in the database.

Access conditions data through frontier in FWLite/ROOT

In order to access the database through frontier the instructions to follow are very similar to those for a local sqlite database access. The main differences are:

  • the name in the create method, i.e. frontier:// plus the name of the database. For example
    std::string NameDB = "frontier://";
  • The possible need for a user authentication in order to access the database (Username + password)

A complete text code example is avaiable here: testCondIter_PrintB.cpp. You can run it inside ROOT framework with the instruction .x testCondIter_PrintB.cpp. The program creates one file DataB.txt with the dump of the content the object in the database.

Print Implementation

A very standard database reading can be achieved into FWlite/ROOT if every condition object is provided with a print() method. Of course, the same implementation for every printing method is convenient.

Above it is shown a full example on a CSC object (namely CSCDbNoiseMatrix):

  • in the following print() method one can access and print the item object elements (matrix is a std::vector<Item>)

     void CSCDBNoiseMatrix::print( std::stringstream& s ) const {

     std::vector<CSCDBNoiseMatrix::Item>::const_iterator it ;
     for (it = matrix.begin(); it != matrix.end(); ++it){

     s << it->elem33  <<" " <<  it->elem34 << " " << it->elem35<< " "<< ...... << std::endl;

One can see the simplicity of the code, comparing to a CMSSW read database application, which has to care of the database accessing, instead already taken by the CondIter (CondCacthedIter) class. Calling the print() method in a ROOT macro, as shown in the tutorial, it is possible to fill a file with the content of a payload, selecting the range of the IOV if needed.

In 020 transfering, applying the reading tool to both source then target database it would be possibly to monitor the correct data transfering (a diff of text file, or a more deeper manipulation if corrections, i.e. multiplicative factor, approximation, has been applied before the transfer).

Review Status

Reviewer/Editor and date Comments
AndreaMassironi 19 Sep 2007 page author
ZhenXie 21 Sep 2007 ported from private html file
MicheleDeGruttola 1 April 2008 adding printing implementation

Responsible: AndreaMassironi
Last reviewed by: Reviewer ZhenXie
Last reviewed by: Reviewer MicheleDeGruttola

Edit | Attach | Watch | Print version | History: r14 < r13 < r12 < r11 < r10 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r14 - 2008-04-02 - unknown

    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

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