Creating a new Table for the Calibration Database


This page details the procedure to go through to create a new table for the calibration database.


Introduction

This document provides a prescription for a user who wishes to add a table to the CDF Run II calibration database. There are many different sections of code associated with each table in the database. In order to facilitate the creation of this code CDF uses java and other script techniques in a phase of the build called \emph{codegen}. In order to add a table to the calibration database, the user needs to write a java file defining the table to be added. Then when codegen is executed on this java file, all the ancillary sections of code associated with this table are generated. Prior to March 2004, the requirements for this java file had remained unchanged for about 2 years. This note details some changes that have been made in terms of a full prescription.

Initial setup

The java file defining your table will be committed to a package in the CDF Run II repository which is specifically intended for database table definitions. There are many of these packages, usually one for each major sub-detector. An example is SvxCalibDBTables. If you are adding a table for a sub-detector which already has its own package (ie something with your subdetector name in it and the word Tables) then just add your java file to this package. Otherwise you will need to request a new package (email cdf_code_management@fnal.gov). Once you have a package, check out a development local release and add your package to it. For example:

source ~cdfsoft/cdf2.cshrc 
setup cdfsoft2 development
newrel -t development new_table_rel
cd new_table_rel
addpkg -h SvxCalibDBTables
cd SvxCalibDBTables/tables

Now you need to add the java file defining your table to the tables directory of your package. An example java file is given below, then the different parts are explained.



import emitter.Attrib;
import emitter.DBString;
import java.io.Serializable;
import java.util.Vector;

public class SvtBeamPosition extends Attrib implements Serializable
{
long ChannelID ;

int Version;
int Revision;

public int[] EventRange =new int[2];

int SVTGVL;
int nSVTGVL;

double SVTGX;
double SVTGXE;

public int[] SVTVAL =new int[6];
public int[] nSVTVAL=new int[6];
public float[] SVTX =new float[6];
public float[] SVTXE =new float[6];

public int[] SVTLAYERMASK =new int[24];

public String rcsId()
{
return "$Id: SvtBeamPosition.java,v 1.1 2004/03/17 23:30:26 rlc Exp $";
}

public Long rowCount() { return new Long(100); }
public Long frequency() { return new Long(24); } // in hours
public Long cdfNote() { return new Long(6942); }

}

The sections of the table java file

The import statements at the top of the file are like C++ include statements. These are the typical imports that are needed for a table. You should copy these exactly.

The \emph{public class..} line is where you declare the name of your table. Copy this line substituting the name of your table for SvtBeamPosition.

The data members of the class (the first on is ChannelID) are converted into columns in your table. The allowed types are given in this table along with examples.


Allowed datatypes
Type Description Example
long long integer long mylong;
int integer int myint;
double double precision floating point double mydouble;
float floating point number float myfloat;
DBString string static public DBString mystr = new DBString(38);
int[] integer array public int[] my_int_ar = new int[6];
float[] float array public float[] my_flt_ar = new float[6];


Note that arrays and strings have to have their lengths defined in brackets. Note also that there is no real gain in precision between double/float and long/int (this is a quirk of the implementation).

The rcisId method is a way of identifying who created this table java definition and when. Replace the name of the file, the username and time information with your own.

The three methods: are required to be implemented. The rowCount method returns a prediction of the typical number of rows of this table which will be inserted in a typical calibration insertion. For example, the SVX pedestal table has many thousands of row inserts each time a calibration is taken.

The frequency method returns a prediction of how many hours elapse between calibrations. These two methods are required in order to predict the size of the table after 2 years of running. This determines the amount of space the database allocates to this table.

Please be as accurate as possible with these predictions. However, leave room for possible expansions here. So if you know you will use 5 insertions per calibration now, but might use 10 in the future, put 10. But don't put 20 because this is a significant over-estimate.

The cdfNote method is required to enable other people to tell what this table is for. Please write a cdfnote detailing the useage and definition of your table and put its number here.

Finishing up

Once you have written your table java definition, and copied it to the tables directory of your package, then compile it. You do this by going to the top level of your local release: cd new_table_rel gmake .codegen where package is the name of your package. This executes codgen on your package. You will get a set of lines like:

<**codegen**> AlignmentDB
<*** generating GNUmakefile in tmp area for TEXT ***>
Refreshing libAlignmentDB_TEXT.a
<*** generating GNUmakefile in tmp area for OTL ***>
Refreshing libAlignmentDB_OTL.a
<**compiling**>  SvtBeamPosition.java
<**creating library**>  AlignmentDB.jar
<** creating  allAlignmentDB.list  **>
<**generating  SvtBeamPosition.Decls.hh **>
<**generating  java_done **>
<** Java-to-C++ generation -- AlignmentDB.RO.Def.HH ** >
<** Java-to-C++ generation -- AlignmentDB.RW.Def.HH ** >
<** Java-to-C++ generation -- AlignmentDB.RO.CC ** >
<** Java-to-C++ generation -- AlignmentDB.RW.CC ** >
<** Java-to-C++ generation -- AlignmentDB.RO.HH ** >
<** Java-to-C++ generation -- AlignmentDB.RW.HH ** >
<** Java-to-C++ generation -- AlignmentDB.RO.Text ** >
<** Java-to-C++ generation -- AlignmentDB.RW.Text ** >
<** Java-to-C++ generation -- AlignmentDB.RO.OTL ** >
<** Java-to-C++ generation -- AlignmentDB.RW.OTL ** >
<**  C++ header generation /cdf/scratch/msmartin/svt_beampos_dev/tmp/Linux2-GCC_3_3/AlignmentDB//generated_headers_stamp **>
<** generating GNUmakefile in tmp area for this /cdf/scratch/msmartin/svt_beampos_dev/tmp/Linux2-GCC_3_3/AlignmentDB/ **>
Refreshing libAlignmentDB.a

This indicates successful compilation. If you get something like:

<**codegen**> AlignmentDB
<*** generating GNUmakefile in tmp area for TEXT ***>
Refreshing libAlignmentDB_TEXT.a
<*** generating GNUmakefile in tmp area for OTL ***>
Refreshing libAlignmentDB_OTL.a
<**compiling**>  SvtBeamPosition.java
SvtBeamPosition.java:54: ';' expected.
    double SVTDYE  //  error on dy/dz (microradians)
                 ^
1 error
gmake[2]: *** [/cdf/scratch/msmartin/svt_beampos_dev/tmp/Linux2-GCC_3_3/AlignmentDB/SvtBeamPosition.class] Error 1
gmake[1]: *** [tables.codegen] Error 2
gmake: *** [AlignmentDB.codegen] Error 2

 
or anything else different to the successful signature then you need to fix something. Once you have successfully compiled your table file, commit it to the repository: cd new_table_rel//tables cvs add cvs commit Finally, email the calibration coordinator (Mat Martin at the time of writing msmartin@fnal.gov) and he will add your table to the database.