GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> CAL_DB / V0-2-4 > cal_db_gains_create / linux-gcc


Interface   Data Structures   File List   Data Fields   Globals  

cal_db_gains_create.c File Reference

Creates the include file used to build the loadable shareable image for the gains. More...

#include <stdio.h>
#include <stdlib.h>
#include <cal_import.h>
#include <cal_import_gains.h>
#include <calib_db_create.h>

Classes

struct  _Ctl
 The CAL include file creation control structure. More...

Typedefs

typedef struct _Ctl Ctl
 Typedef for struct _Ctl.

Functions

static void reportUsage (void)
 Brief explanation of the test creation usage.
static int idealized_prepare (unsigned int *export, const float gains[4][2])
 Prepares the imported data for export.
static int full_prepare (unsigned int *export, const float gains[16][8][12][4][2])
 Prepares the imported data for export.
static int writeFile (FILE *hfile, const char *hname, const char *package, const char *constituent, const char *version, CALIB_DB_STYLE_K style, const char *origin_name, const char *style_name, unsigned int key, unsigned int tag, const unsigned int *export)
 Files and writes the output include file.
static void full_write (FILE *hfile, const unsigned int *export)
 Writes the FULL version of the gains.
static void idealized_write (FILE *hfile, const unsigned int *export)
 Writes the IDEALIZED version of the gains.
static int fillCtl (Ctl *ctl, int argc, char *const argv[])
 Examines the command line parameters and fills the include file creation control structure.
static __inline unsigned int compose (float mev_f)
 Composes the calibration values for one log end.
static void fillGains (unsigned short int *gains, const unsigned int *exports)
 Fills one layers worth of gains.
static void fillShifts (unsigned short int *shifts, const unsigned int *exports)
 Fills one layers worth of shifts.
static int writeLayer (FILE *hfile, int lyr, const unsigned short int v[24])
 Write one layers worth of constants.
int CalDbGainsCreate (int argc, char *const argv[], const CalImportGains *import)
 Driver program to create CAL calibration include file.
static __inline int FFS (unsigned int val)
 Finds the First Set bit.


Detailed Description

Creates the include file used to build the loadable shareable image for the gains.

Author:
JJRussell - russell@slac.stanford.edu

   CVS $Id: cal_db_gains_create.c,v 1.5 2011/03/25 02:40:52 apw Exp $

This program accepts a cal_gains.h file and converts it to a representation that is used to transform ADC values to Mev. This portion handles only the gain part of the linear transformation. The pedestals are done imilarly, but by a different program.

The mechanism is fairly clunky, belonging to that ilk of programs whose mission is to write another program. In this case, the gain data is written out as data to a C data structure, called the schema. The resulting file is then compiled and built into a shareable image.

In addition to holding the data values, this schema also holds pointers to routines that are used to access the data. This tactic allows the interface to be stable, but effectively hides the internal representation of the data. Because the accessor routine's job is act as a go-between between the caller and the internal data, it must

  1. Present a well-defined and stable interface to the user
  2. Be privy to the detailed layout of the data

It is this last point that drives the design to include the implementation of these routines at the same time the data is defined. That keeps the two in lock step.


Typedef Documentation

Ctl

Typedef for struct _Ctl.

Contains all the parameters controlling the creation and content of the test include file.


Function Documentation

int CalDbGainsCreate ( int  argc,
char *const   argv[],
const CalImportGains import 
)

Driver program to create CAL calibration include file.

Returns:
Status, if 0, then successfully created the output file
Parameters:
argc The count of input arguments
argv The vector of input arguments
import The imported database

References CALIB_DB_STYLE_K_FULL, CALIB_DB_STYLE_K_IDEALIZED, fillCtl(), full_prepare(), _Ctl::hname, idealized_prepare(), reportUsage(), and writeFile().

static __inline unsigned int compose ( float  mev_f  )  [static]

Composes the calibration values for one log end.

Returns:
The composed calibration values for one log end
Parameters:
mev_f The MEV at 4096 counts
Warning:
The scale is such that mev must be < 1 << 18 -1 = 262,143

References FFS().

Referenced by full_prepare(), and idealized_prepare().

static __inline int FFS ( unsigned int  wrd  )  [static]

Finds the First Set bit.

Returns:
The bit number of the First Set bit (MSb = 0)
Parameters:
wrd The word to scan

Referenced by compose().

static int fillCtl ( Ctl ctl,
int  argc,
char *const   argv[] 
) [static]

Examines the command line parameters and fills the include file creation control structure.

Parameters:
ctl The parameter control block.
argc The number of command line parameters.
argv The array of pointers to the command line parameters.
Return values:
0,Everything is okay.
-1,Incorrect command usage. Usually this means that the input file name was absent.

References _Ctl::hname, and reportUsage().

Referenced by CalDbGainsCreate().

static void fillGains ( unsigned short int *  gains,
const unsigned int *  exports 
) [static]

Fills one layers worth of gains.

Parameters:
gains The output gain array
exports The export data

Referenced by full_write().

static void fillShifts ( unsigned short int *  shifts,
const unsigned int *  exports 
) [static]

Fills one layers worth of shifts.

Parameters:
shifts The output shifts array
exports The export data

Referenced by full_write().

static int full_prepare ( unsigned int *  export,
const float  gains[16][8][12][4][2] 
) [static]

Prepares the imported data for export.

Returns:
The number of bad gain values encountered.
Parameters:
export Filled with the data to be exported
gains The imported gains data
This routine will fail if a gain outside the range that can be handled is encountered. The viable range is roughly 2^-13 to 2^13 Mev/ADC.

References compose().

Referenced by CalDbGainsCreate().

static void full_write ( FILE *  hfile,
const unsigned int *  export 
) [static]

Writes the FULL version of the gains.

Parameters:
hfile The include file handle
export The constants to export

References fillGains(), fillShifts(), and writeLayer().

Referenced by writeFile().

static int idealized_prepare ( unsigned int *  export,
const float  gains[4][2] 
) [static]

Prepares the imported data for export.

Returns:
The number of bad gain values encountered.
Parameters:
export Filled with the data to be exported
gains The imported gains data
This routine will fail if a gain outside the range that can be handled is encountered. The viable range is roughly 2^-13 to 2^13 Mev/ADC.

References compose().

Referenced by CalDbGainsCreate().

static void idealized_write ( FILE *  hfile,
const unsigned int *  export 
) [static]

Writes the IDEALIZED version of the gains.

Parameters:
hfile The include file handle
export The constants to export

Referenced by writeFile().

static int writeFile ( FILE *  hfile,
const char *  hname,
const char *  package,
const char *  constituent,
const char *  version,
CALIB_DB_STYLE_K  style,
const char *  origin_name,
const char *  style_name,
unsigned int  key,
unsigned int  tag,
const unsigned int *  export 
) [static]

Files and writes the output include file.

Returns:
Status
Parameters:
hfile The include file handle
hname The name of the input file
package The package name
constituent The constituent name
version The schema version number
style The style (one of CALIB_DB_STYLE_K_FULL or CALIB_DB_STYLE_DB_IDEALIZED)
origin_name The name of the data originating source (GLEAM, LAT, etc)
style_name The style name ("FULL", "IDEALIZED")
key The database's identifying key
tag The file's online tag (CMX version for example)
export The constants to export

References calib_db_info_write(), calib_db_preamble_write(), CALIB_DB_STYLE_K_FULL, full_write(), and idealized_write().

Referenced by CalDbGainsCreate().

static int writeLayer ( FILE *  hfile,
int  lyr,
const unsigned short int  v[24] 
) [static]

Write one layers worth of constants.

Parameters:
hfile The include file handle
lyr The layer number being written
v The 24 constants (12 columns * 2 logends) to write

Referenced by full_write().


Generated on Fri Sep 30 18:07:51 2011 by  doxygen 1.5.8