Project

General

Profile

Quick Start Guide

Setup

  • make sure you have a krb5 ticket for FNAL.GOV
  • make sure the following environment variables are set (these are automatically set via the normal offline setup scripts):
    • NOVADBWSURL
    • NOVADBWSPWDFILE

Create a XML definition file for your table, eg,

<?xml version="1.0"?>

<dBTable
  tableName="jonstest" 
  tableType="validity" 
  dbHost="novadbprod.fnal.gov" 
  dbName="nova_prod" 
  dbPort="5433" 
  creationDate="2013-06-05" 
  maintainer="jpaley@anl.gov">

  <dBColumn name="occupancy" colType="double" />
  <dBColumn name="coincidences" colType="double" />

</dBTable>

Create the validity table in the database:

NOTE1: currently, the executable can only be run from the Database package directory. This will be fixed soon.

NOTE2: "float" is a database data type that has equivalent precision as a C double)

> createValidityTableInDB -c -h ifdbdev.fnal.gov -n nova_dev -p 5433 -d FarDet -f JonsTestTable.xml
Creating validity dB table nova_dev in  database.
python create_table.py -o nova_admin -R nova_reader,nova_writer,nova_web -W nova_web -p 5433 -h ifdbdev.fnal.gov nova_dev fardet.jonstest occupancy:float coincidences:float 
Table created

Write data to the table:

  nova::dbi::Table jtt("Database/cxx/test/JonsTestTable.xml");

  jtt.SetDetector(novadaq::cnv::kFARDET);
  jtt.SetDataTypeMask(nova::dbi::kMCOnly|nova::dbi::kDataOnly);

  time_t t0 = time(NULL);
  int nspd = 60*60*24; // number of seconds per day

  nova::dbi::Row* r = jtt.NewRow();

  r->Set("tv",t0-3*nspd); // three days ago
  for (int i=0; i<10; ++i) {
    r->Set("channel",1000+i);
    r->Set("occupancy",(i+1)*1e-3);
    r->Set("coincidences",log10((i+1)*1.e-5));
    jtt.AddRow(r);
  }
  if (!jtt.Write()) return 1;

Load data from the database into a table:

  nova::dbi::Table jtt("Database/cxx/test/JonsTestTable.xml");

  jtt.SetDetector(novadaq::cnv::kFARDET);
  jtt.SetDataTypeMask(nova::dbi::kMCOnly);

  time_t t0 = time(NULL); // set time to 10 seconds prior

  int nspd = 60*60*24; // number of seconds per day

  jtt.SetMinTSVld(t0-3*nspd);
  jtt.SetMaxTSVld(t0);

  if (! jtt.Load()) {
    std::cerr << "oh oh, load failed!" << std::endl;
    [deal with it]
  }

Using loaded data

  // we assume a nova::dbi::Table::Load() has just been executed

  jtt. FillChanRowMap(); // build a map between channel number and vector of table rows for that channel
  nova::dbi::Row* vr = 0;
  long chan; // presume this gets appropriately set in your code
  time_t tevt = [event time]; // take from event header
  float occ;
  vr = jtt.GetVldRow(chan, tevt);
  if (vr) {
    [get column data for this row]
    if (vr->Col("occupancy")->Get(occ)) {
      // do something with the occ variable
    }
  }
  else {
    // no row found for that channel, deal with this.
  }

Loading data in a CSV file

  1. Make sure the format of the comma separated value (CSV) file is: [dataCol1],[dataCol2],...,channel,tv
    where "tv" is the timestamp. Note that the order of the data columns must match the order in the XML table definition file (NB, will try to improve the interface here so that one can define the column ordering within the CSV file itself)
  2. use the writeValidityCSVtoDB executable to load the CSV rows into the database, eg:
    Usage: writeValidityCSVToDB [NDOS|FarDet|NearDet] [data|mc|datamc] [XML table definition file] [CSV data file]
    

    where the 2nd command-line argument defines the validity data type (data, mc or both).