This document covers code generation and read only access through the Calibration API. This is typically used to read data from non-Calibration databases. The steps involved are:
This is an example of creating a view into the Hardware Database from the Calibration Database
DROP VIEW CAL_CHANNEL_VIEW_CALOR;DROP PUBLIC SYNONYM CAL_CHANNEL_VIEW_CALOR;
CREATE OR REPLACE FORCE VIEW CAL_CHANNEL_VIEW_CALOR
(COMPNAME ,CARDNAME
,CRATENAME ,SLOT
,SUBADDRESS ,DIRACCHANNEL
,CARDNAME_DIRAC ,GEOM_ID
,RACKNAME ,NODEVMEPROC)
AS SELECT c.BK_BANKNAME,c.CARDNAME
,c.cratename,c.slot,ch.subaddress
,ch.diracchannel,ch.cardname_dirac
,ch.channelnumber
,r.rackname
,cr.nodevmeproc
from CDF_ONLINE.cards c,CDF_ONLINE.channels ch,
CDF_ONLINE.racks r,CDF_ONLINE.crates cr
WHERE c.cardname=ch.cardnameand c.cratename=cr.cratename and
r.rackname=cr.rackname andc.BK_BANKNAME in ('CEM','PEM','CHA','WHA','PHA');
CREATE PUBLIC SYNONYM CAL_CHANNEL_VIEW_CALOR
FOR CALIB_DEV.CAL_CHANNEL_VIEW_CALOR;
The java description must inherit from emitter.ROattrib to generate Read Only access.
import emitter.ROattrib;
import emitter.DBString;
import java.io.Serializable;
/**
* AUTHOR Jack Cranshaw, 2/22/00, --
* VERSION 1.0,--
* INDEXED by Component, geom_id --
* -----------
* PURPOSE : View of Hardware Database
* All calorimeter (cent,wall,plug,em,had) electronics information.
*/
public class Cal_Channel_View_Calor extends ROattrib implements Serializable
{
static public DBString compname = new DBString(4);
static public DBString cardName = new DBString(38);
static public DBString crateName = new DBString(38);
long slot;
long subAddress;
long diracChannel;
static public DBString cardName_Dirac = new DBString(38);
long geom_ID;
static public DBString rackName = new DBString(12);
static public DBString nodeVMEProc = new DBString(38);
}
In this case, CALcomp.java
import emitter.Attrib;
import emitter.Component;
/**
* This is an entry of the CDF calibration dictionary.
* It lists the CAL-related attributes for the ONLINE (B0)
*
* Environment:
* developed for the CDF CodeGen project at LBL
* @version 0.0.1 21 April 1999 * @see Component
* @author Paolo Calafiura (PCalafiura@lbl.gov
)
* modified by Jack Cranshaw cranshaw@fnal.gov, 18 Nov 1999
*/
public class CALcomp extends Component {
public CALcomp_offline CAL_OFF;
public CALcomp_online CAL_ONL;
public Attrib Cal_Channel_View_Calor;
}
Described in the read/write Code Generation HOW-TO . The major difference here is that Step 5.a, defining your table in the database server, should only be done for msql
This is almost the same as described in the DBManager Users Guide. The difference is in the keys. ROKeys essentially append a qualifier to "Select * from the_view". A default ROKey would select all rows of the view/table.
The following is a condensation of DBUtils/Examples/ReadQualifiedDB.cc
// --> Class to define the key.
#include "CalibDB/ROKey.hh"
// --> The actual table definition -- code generated from java
#include "CalibDBTables/gen/Cal_Channel_View_Calor.Defs.hh"
using namespace std;
int main(int argc, char* argv[])
{
Cal_Channel_View_CalorContainer_ptr gcont;
Cal_Channel_View_Calor_mgr iom(argv[0],"Cal_Channel_View_Calor");
//this key will generate
//"select * from Cal_Channel_View_Calor where COMPNAME = 'CHA'"
ROKey qual("where COMPNAME = 'CHA'");
if(iom.get(qual,gcont) ==Result::success)
cout << "get successful, fetched " << gcont->size() << " rows " << endl;
}