GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> LSE / V2-1-0 > lsew / rhel6-32


Interface   Data Structures   File List   Data Fields   Globals  

CDF_tkr_std.c File Reference

Implementation to produce Compressed Data Format for the TKR contributors. More...

#include <LSE/CDF_tkr_std.h>
#include <CDF_tkr_def.h>
#include <LDT/BFP.h>
#include <LDT/BWP.h>
#include <LDT/BW.h>
#include <LDT/BTE.h>
#include <LDT/HUFF.h>
#include <EDS/EDR_tkr.h>
#include <LSE/cdf_buf_print.h>
#include <PBI/FFS.ih>
#include <string.h>

Classes

struct  _TowerMaps
 Captures the map of the tower classification and the XY layers for all 16 towers. More...
struct  _TotsRep
 The tots represented as a count of the significant bits + the significant bits. More...
struct  _TotsRet
 Return value from the tots_acquire, captures the next write location plus a bit mask of those TOTs having each particular value of the number of significant digits. More...
struct  _LayerCntsStatus
 Captures the result of the layer counts assessment. More...
struct  _CDF_tkr_twr_sum_blk_f
union  _CDF_tkr_twr_sum_blk

Defines

#define _mon   cdf_tkr_std_mon

Typedefs

typedef struct _TowerMaps TowerMaps
 Typedef for struct _TowerMaps.
typedef struct _TotsRep TotsRep
 Typedef for struct _TotsRep.
typedef struct _TotsRet TotsRet
 Typedef for struct _TotsRet.
typedef struct _LayerCntsStatus LayerCntsStatus
 Typedef for struct _LayerCntsStatus.
typedef struct
_CDF_tkr_twr_sum_blk_f 
CDF_tkr_twr_sum_blk_f
typedef union _CDF_tkr_twr_sum_blk CDF_tkr_twr_sum_blk

Functions

static BW_vector tree18_encode (unsigned int w)
 Does a binary-like tree encode of an 18-bit number.
static __inline int layer_map_pack (CDF_tkr *tkr, unsigned int *buf, unsigned int pos, unsigned int map)
 Packs the specified layer map.
static TotsRet tots_acquire (CDF_tkr *tkr, TotsRep *tots, unsigned int present, unsigned int hist[8], const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Packs the TOTs for the specified layers.
static __inline int tots_huff_build (HUFF_code *codes, const unsigned int *hist, int *size, unsigned int *validMask)
static __inline unsigned int tots_huff_pack (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, unsigned int mask, const HUFF_code *codes, int ncodes)
 Encodes the Huffman table used to encode the TOT exponents.
static __inline unsigned int tots_expman_pack (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, TotsRep *tots, int ntots, const HUFF_code *codes)
 Compresses what is essentially the exponent map of the TOTs.
static __inline unsigned int tots_copy (unsigned int *buf, unsigned int pos, const TotsRep *tots, int ntots)
 Packs the TOT values using a straight copy.
static __inline unsigned int tots_pack (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const EDR_tkrTower *twrs, unsigned int twrMap)
 Driver routine to pack the strips from each non-empty layer.
static __inline unsigned int layer_maps_pack (CDF_tkr *cdf, unsigned int *buf, int position, const EDR_tkrTower *twrs, unsigned int twrMap)
 Driver routine to pack the layer masks.
static __inline int layer_cnts_assess (LayerCntsStatus *lcs, const EDR_tkrTower *twrs, unsigned int twrMap, unsigned int classMap)
 Gathers and asseses the information about how to encode the number of hit strips in each layer.
static __inline unsigned int layer_cnts_pack_cmaps (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const LayerCntsStatus *lcs)
 Packs the count maps for the active layers.
static __inline unsigned int layer_cnts_pack_cnts (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const LayerCntsStatus *lcs, int style)
 Packs the strip counts for each active layer.
static __inline unsigned int find_next_strip (unsigned int map, int xy, const int *maps, unsigned int twrMap, const EDR_tkrTower *twrs, const EDR_tkrLayer *lyrs)
 Effectively does a look-ahead to find the next hit strip. If there is none, -1 is returned.
static __inline unsigned int layer_cnts_pack (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const EDR_tkrTower *twrs, unsigned int twrMap, unsigned int classMap)
 Driver routine to pack the layer masks.
static __inline unsigned int strips_pack_lyrs (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, int class, const EDR_tkrLayer *lyrs, unsigned int map, unsigned char *cmax)
 Packs the beginning strip number for each cluster.
static __inline int strips_pack_twrs (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const EDR_tkrTower *twrs, unsigned int twrMap, unsigned int classMap, unsigned char cmax[17])
 Driver routine to pack the strips from each non-empty layer.
static __inline unsigned int clusters_pack_lyrs (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const EDR_tkrLayer *lyrs, unsigned int map, int class, int nbits)
 Packs the cluster width for each cluster.
static __inline int clusters_pack_twrs (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const EDR_tkrTower *twrs, unsigned int twrMap, unsigned int classMap, const unsigned char cmax[17])
 Driver routine to pack the cluster widths from each non-empty layer.
static __inline unsigned int layer_map_size (CDF_tkr *cdf, const EDR_tkrTower *twr)
 Computes the number of bits to encode the layer maps from the specified tower,.
static __inline unsigned long
long int 
tower_analyze (CDF_tkr *cdf, const EDR_tkrTower *twr, CDF_tkr_std_mon_twr *mtwr)
 Analyzes all struck layers indicated by the layer map.
static __inline unsigned char tower_classify (CDF_tkr *cdf, CDF_tkr_std_mon_twr *mtwr, unsigned long long int tsb_ull)
static BW_vector towers_classify (CDF_tkr *cdf, const EDR_tkrTower *twrs, unsigned int twrMap)
 Picks the optimal encoding method for all towers.
unsigned int CDF_tkr_std_compress (CDF_tkr *cdf, unsigned int *buf, unsigned int pos, const EDR_tkr *tkr)
 Adds the TKR record.


Detailed Description

Implementation to produce Compressed Data Format for the TKR contributors.

Author:
JJRussell - russell@slac.stanford.edu
    CVS $Id: CDF_tkr_std.c,v 1.5 2011/03/26 17:35:24 russell Exp $


Typedef Documentation

Typedef for struct _LayerCntsStatus.

The cmaps array is dense in the active layers, while the cnts array is dense in layers that have counts associated with them

Typedef for struct _TotsRet.

The pointer to the next TOTs location to write is absolutely necessary. The present mask is an optimization to avoid scanning NS values that are not populated. Perhaps even better would be a histogram of the values, That way the scan loop could abort when the number reached 0. We will try this simple approach until it is found that something more sophisiticated is warranted.

Typedef for struct _TowerMaps.

Each map contains 2 bits of information per tower.

For the layer maps the 2 bits represent whether the X and/or Y layers have any hits. The order is X0 = Bit 0 (MSb) Y0 = bit 1, X1 = bit2, etc

For the class maps, the two bits give the tower encoding scheme to use. The order is Tower 0 class = Bits 0,1 (MSb = bit 0), Tower 1 class = Bits 2,3 etc.


Function Documentation

unsigned int CDF_tkr_std_compress ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const EDR_tkr *  tkr 
)

Adds the TKR record.

Returns:
The next available bit position in the output buffer
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit offset
tkr The unpacked TKR event

References clusters_pack_twrs(), _CDF_tkr::ign_map, layer_cnts_pack(), layer_maps_pack(), _CDF_tkr::std_map, strips_pack_twrs(), tots_pack(), and towers_classify().

Referenced by CDF_tkr_ped_compress().

static __inline unsigned int clusters_pack_lyrs ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const EDR_tkrLayer *  lyrs,
unsigned int  map,
int  class,
int  nbits 
) [static]

Packs the cluster width for each cluster.

Returns:
The next available bit position in the output buffer
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit offset
lyrs The layers to pack
map The bit map of which layer to pack
class The class of the tower (diagnostic only)
nbits The number of bits to devote to the width (diagnostic onlY)

Referenced by clusters_pack_twrs().

static __inline unsigned int clusters_pack_twrs ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const EDR_tkrTower *  twrs,
unsigned int  twrMap,
unsigned int  classMap,
const unsigned char  cmax[17] 
) [static]

Driver routine to pack the cluster widths from each non-empty layer.

Returns:
The next writable bit position
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
twrs The array of unpacked tower information
twrMap The map of struck towers
classMap The big-endian style classMap
cmax The array of the maximum number of clusters by tower The last entry gives the maximum of all towers.

References clusters_pack_lyrs().

Referenced by CDF_tkr_std_compress().

static __inline unsigned int find_next_strip ( unsigned int  map,
int  xy,
const int *  maps,
unsigned int  twrMap,
const EDR_tkrTower *  twrs,
const EDR_tkrLayer *  lyrs 
) [static]

Effectively does a look-ahead to find the next hit strip. If there is none, -1 is returned.

Return values:
The next hit strip
-1 if there is no next strip
Parameters:
map The current layer map
xy 0 if the current layer map is an X map, 1 if a Y map
maps The array X and Y layer maps for the current tower
twrMap The tower map
twrs The array of towers
lyrs The layers for the current tower.

Referenced by layer_cnts_assess().

static __inline int layer_cnts_assess ( LayerCntsStatus lcs,
const EDR_tkrTower *  twrs,
unsigned int  twrMap,
unsigned int  classMap 
) [static]

Gathers and asseses the information about how to encode the number of hit strips in each layer.

Returns:
The encoding method
Parameters:
lcs The layer count status structure to fill in
twrs The tower structures for this event
twrMap The map of active towers
classMap The class of each active tower

References _LayerCntsStatus::cmaps, _LayerCntsStatus::cnts, _LayerCntsStatus::cnts_width, find_next_strip(), _LayerCntsStatus::ncmaps, _LayerCntsStatus::ncnts, _LayerCntsStatus::nstops, and _LayerCntsStatus::twr_list.

Referenced by layer_cnts_pack().

static __inline unsigned int layer_cnts_pack ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const EDR_tkrTower *  twrs,
unsigned int  twrMap,
unsigned int  classMap 
) [static]

Driver routine to pack the layer masks.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
twrs The array of towers for this event
twrMap The array of struck towers
classMap The tower class map

References layer_cnts_assess(), layer_cnts_pack_cmaps(), layer_cnts_pack_cnts(), and _LayerCntsStatus::twr_list.

Referenced by CDF_tkr_std_compress().

static __inline unsigned int layer_cnts_pack_cmaps ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const LayerCntsStatus lcs 
) [static]

Packs the count maps for the active layers.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
lcs The layer count status structure

References _LayerCntsStatus::cmaps, and _LayerCntsStatus::ncmaps.

Referenced by layer_cnts_pack().

static __inline unsigned int layer_cnts_pack_cnts ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const LayerCntsStatus lcs,
int  style 
) [static]

Packs the strip counts for each active layer.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
lcs The layer count status structure
style The packing style

References _LayerCntsStatus::cnts, _LayerCntsStatus::cnts_width, and _LayerCntsStatus::ncnts.

Referenced by layer_cnts_pack().

static __inline int layer_map_pack ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
unsigned int  map 
) [static]

Packs the specified layer map.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
map The layer map to pack

References tree18_encode().

Referenced by layer_maps_pack().

static __inline unsigned int layer_map_size ( CDF_tkr cdf,
const EDR_tkrTower *  twr 
) [static]

Computes the number of bits to encode the layer maps from the specified tower,.

Returns:
The number of bits to encode the specified layer map
Parameters:
cdf The TKR compression data formatting handle
twr The target tower
This is just a debugging routine so efficiency is not an issue. This routine just calls the normal packing routine with the arguments set to consider only this tower. The packed data is ignored.

References layer_maps_pack().

Referenced by towers_classify().

static __inline unsigned int layer_maps_pack ( CDF_tkr cdf,
unsigned int *  buf,
int  position,
const EDR_tkrTower *  twrs,
unsigned int  twrMap 
) [static]

Driver routine to pack the layer masks.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
position The current bit position
twrs The array of towers for this event
twrMap The array of struck towers

References layer_map_pack().

Referenced by CDF_tkr_std_compress(), and layer_map_size().

static __inline unsigned int strips_pack_lyrs ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
int  class,
const EDR_tkrLayer *  lyrs,
unsigned int  map,
unsigned char *  cmax 
) [static]

Packs the beginning strip number for each cluster.

Returns:
The next available bit position in the output buffer
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit offset
class The class specification of the tower.
lyrs The array of layers to traverse
map Bit map of the layers to process
cmax Returned as a number which has the same number of bits as the maximum cluster width

Referenced by strips_pack_twrs().

static __inline int strips_pack_twrs ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const EDR_tkrTower *  twrs,
unsigned int  twrMap,
unsigned int  classMap,
unsigned char  cmax[17] 
) [static]

Driver routine to pack the strips from each non-empty layer.

Returns:
The next writable bit position
Parameters:
cdf The TKR compression context
buf The output buffer
pos The current bit position
twrs The array of unpacked tower information
twrMap The map of struck towers
classMap The big-endian style classMap
cmax The maximum count by tower, the last entry is returned as the overall maximum

References strips_pack_lyrs().

Referenced by CDF_tkr_std_compress().

static TotsRet tots_acquire ( CDF_tkr cdf,
TotsRep tots,
unsigned int  present,
unsigned int  hist[8],
const EDR_tkrLayer *  lyrs,
unsigned int  layerMap 
) [static]

Packs the TOTs for the specified layers.

Returns:
The next writable tot + the update present mask
Parameters:
cdf The TKR compression data formatting handle
tots The output buffer
present Bit mask of 'ns' values present
hist Histogram of the 8 possible values for the number of signficant digits in the TOTs
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

References _TotsRep::ns, _TotsRet::present, _TotsRep::tot, and _TotsRet::tots.

Referenced by tots_pack().

static __inline unsigned int tots_copy ( unsigned int *  buf,
unsigned int  pos,
const TotsRep tots,
int  ntots 
) [static]

Packs the TOT values using a straight copy.

Returns:
The next bit position to write
Parameters:
buf The output buffer
pos The current bit position
tots The array of TOTs in leading zero format
ntots The number to pack

References _TotsRep::tot.

Referenced by tots_pack().

static __inline unsigned int tots_expman_pack ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
TotsRep tots,
int  ntots,
const HUFF_code *  codes 
) [static]

Compresses what is essentially the exponent map of the TOTs.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
tots The array of TOTs in leading zero format
ntots The number to pack
codes The Huffman codes

References _TotsRep::ns, and _TotsRep::tot.

Referenced by tots_pack().

static __inline unsigned int tots_huff_pack ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
unsigned int  mask,
const HUFF_code *  codes,
int  ncodes 
) [static]

Encodes the Huffman table used to encode the TOT exponents.

Returns:
The next bit position to write
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
mask The 8-bit mask of which length codes are valid. The most significant bit (bit 0) is for codes of length 0 and bit 7 is for codes of length 7.
codes The dense list of Huffman codes
ncodes The count of Huffman codes

Referenced by tots_pack().

static __inline unsigned int tots_pack ( CDF_tkr cdf,
unsigned int *  buf,
unsigned int  pos,
const EDR_tkrTower *  twrs,
unsigned int  twrMap 
) [static]

Driver routine to pack the strips from each non-empty layer.

Returns:
The next writable bit position
Parameters:
cdf The TKR compression data formatting handle
buf The output buffer
pos The current bit position
twrs The array of unpacked tower information
twrMap The map of struck towers
There are two packings possible
  1. 0, followed by a straight copy
  2. 10, followed by a huffman encoding of the exponent

The cheaper of the two methods is used.

The TOT packing algorithm attempts to take advantage of the fact that the number of significant bits in a TOT value is only 3-6 bits out of the possible 8 bits. There are two types of TOT values, noise hits and MIP type hits. Evidence is that noise hits are quite small (likely less the 4 bits) and 1 MIP hits are around 40 counts (in the 5-6 bit range.)

Consequently a Huffman code is used to encode the number of leading zeroes. The remaining significant digits are just coded as is. Given the fact that 0 and 1 are very unlikely, these to values are collapsed to the same exponent value with the consequence that an exponent of 0 cannot be interpretted as being 1.

If the

if (ntots < 4) goto COPY;

References _TotsRet::present, _TotsRet::tots, tots_acquire(), tots_copy(), tots_expman_pack(), and tots_huff_pack().

Referenced by CDF_tkr_std_compress().

static __inline unsigned long long int tower_analyze ( CDF_tkr cdf,
const EDR_tkrTower *  twr,
CDF_tkr_std_mon_twr mtwr 
) [static]

Analyzes all struck layers indicated by the layer map.

Parameters:
cdf The TKR compression data formatting handle
twr The tower to analyze
mtwr Monitor structure

References _CDF_tkr_std_mon_twr::lyrs, _CDF_tkr_std_mon_twr::nlyrs, and _CDF_tkr_std_mon_twr::xy.

Referenced by towers_classify().

static BW_vector towers_classify ( CDF_tkr cdf,
const EDR_tkrTower *  twrs,
unsigned int  twrMap 
) [static]

Picks the optimal encoding method for all towers.

Returns:
Big endian bit array of the encoding class
Parameters:
cdf The TKR compression data formatting handle
twrs The unpacked tower information
twrMap Map of the towers with hits
There are 4 encoding classes. There are classifed by whether one needs a STOP bit and/or CONTIGIOUS bit.

  • Class 0, neither. This is only available for towers with single bare hits (no clusters)
  • Class 1, contigious bit only. This is only available for towers with a single hit or single clusters
  • Class 2, stop bit only, more than 1 hit, but with any clusters encoded as singles
  • Class 3, both contigious and stop bits

References _CDF_tkr_std_mon_twr::cwidth, _CDF_tkr_std_mon_twr::id, layer_map_size(), _CDF_tkr_std_mon_twr::map_scheme, _CDF_tkr_std_mon_twr::map_size, _CDF_tkr_std_mon_twr::nclusters, _CDF_tkr_std_mon_twr::ntrue, _CDF_tkr_std_mon_twr::tower, and tower_analyze().

Referenced by CDF_tkr_std_compress().

static Tree18 tree18_encode ( unsigned int  w  )  [static]

Does a binary-like tree encode of an 18-bit number.

Returns:
The pattern to encode and the number of bits in the pattern
Parameters:
w The word to encode

Referenced by layer_map_pack().


Generated on Thu Aug 4 13:00:09 2011 by  doxygen 1.5.8