GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > LSEP / V1-0-1

Constituent: lsepw     Tag: linux-gcc


Interface   Data Structures   File List   Data Fields   Globals  

CDF_tkr.c File Reference

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

#include "LSEP/CDF.h"
#include "LSEP/CDF_vector.h"
#include "LSEP/CDF_tkr.h"
#include "LSEP/BFP.h"
#include "EDS/EDR_tkr.h"
#include "EDS/FFS.h"
#include "LDT/BTE.h"

Include dependency graph for CDF_tkr.c:


Data Structures

struct  _TowerMaps
 Captures the map of the tower classification and the XY layers for all 16 towers. More...
struct  _Tree18Result
 The result of encoding an 18-bit layer map. This consists of the right justified encoded bit pattern and the number of bits in the bit pattern. 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...

Typedefs

typedef _TowerMaps TowerMaps
 Typedef for struct _TowerMaps.
typedef _Tree18Result Tree18Result
 Typedef for struct _Tree18Result.
typedef _TotsRep TotsRep
 Typedef for struct _TotsRep.
typedef _TotsRet TotsRet
 Typedef for struct _TotsRet.
typedef int(* StripsPacker )(unsigned int *buffer, int position, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Call signature for the 4 tower level strip packing routines.

Functions

static Tree18Result tree18_encode (unsigned int w)
 Does a binary-like tree encode of an 18-bit number.
static __inline int layer_map_pack (unsigned int *buffer, int position, unsigned int map)
 Packs the specified layer map.
static TotsRet tots_acquire (TotsRep *tots, unsigned int present, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Packs the TOTs for the specified layers.
static unsigned int tots_map_compress (unsigned int *buffer, unsigned int position, unsigned int *map, unsigned int mapcnt, unsigned int lzeroes)
 Compresses what is essentially the exponent map of the TOTs.
static unsigned int tots_exp_pack (unsigned int *buffer, unsigned int position, TotsRep *tots, int ntots, unsigned int present)
 Compresses what is essentially the exponent map of the TOTs.
static unsigned int tots_man_pack (unsigned int *buffer, unsigned int position, TotsRep *tots, int ntots)
 Compresses what is essentially the exponent map of the TOTs.
static __inline int tots_pack (unsigned int *buffer, int position, const EDR_tkrTower *twrs, unsigned int twrMap)
 Driver routine to pack the strips from each non-empty layer.
static __inline int layer_maps_pack (unsigned int *buffer, int position, const EDR_tkrTower *twrs, unsigned int twrMap)
 Driver routine to pack the layer masks.
static int strips_pack_0 (unsigned int *buffer, int position, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Packs the strips for a Class 0 tower (only one hit strip/layer), no clusters.
static int strips_pack_1 (unsigned int *buffer, int position, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Packs the strips for a Class 1 tower (only one hit strip or one cluster/layer). This needs the address + cluster width + stop.
static int strips_pack_2 (unsigned int *buffer, int position, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Packs the strips for a Class 2 tower (multiple hits, clusters will be expanded.
static int strips_pack_3 (unsigned int *buffer, int position, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 Packs the strips for a Class 3 tower (multiple hits, clusters will not be expanded.
static __inline int strips_pack (unsigned int *buffer, int position, const EDR_tkrTower *twrs, unsigned int twrMap, unsigned int classMap)
 Driver routine to pack the strips from each non-empty layer.
static __inline unsigned int layer_map_size (unsigned int map)
 Computes the number of bits to encode the specified layer map.
static TowerMaps tower_classify (const EDR_tkrTower *twrs, unsigned int twrMap)
 Picks the optimal encoding method for all towers.
unsigned int CDF_tkrCompress (CDF_vector *bpv, const EDR_tkr *tkr)
 Compresses the TKR data.

Detailed Description

Implementation to produce Compressed Data Format for the TKR contributors.

Author:
JJRussell - russell@slac.stanford.edu
    CVS $Id: CDF_tkr.c,v 1.4 2005/12/05 18:24:40 russell Exp $


Typedef Documentation

int(* StripsPacker)(unsigned int *buffer, int position, const EDR_tkrLayer *lyrs, unsigned int layerMap)
 

Call signature for the 4 tower level strip packing routines.

Returns:
The next bit position to write
Parameters:
buffer The output buffer
position The current bit position
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

TotsRet
 

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.

TowerMaps
 

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_tkrCompress CDF_vector bpv,
const EDR_tkr *  tkr
 

Compresses the TKR data.

Returns:
The update bit position
Parameters:
bpv The output bit vector
tkr The unpacked TKR event

static __inline int layer_map_pack unsigned int *  buffer,
int  position,
unsigned int  map
[static]
 

Packs the specified layer map.

Returns:
The next bit position to write
Parameters:
buffer The output buffer
position The current bit position
map The layer map to pack

static __inline unsigned int layer_map_size unsigned int  map  )  [static]
 

Computes the number of bits to encode the specified layer map.

Returns:
The number of bits to encode the specified layer map
Parameters:
map The layer map to encode

static __inline int layer_maps_pack unsigned int *  buffer,
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:
buffer The output buffer
position The current bit position
twrs The array of towers for this tower
twrMap The array of struck layers for this tower

static __inline int strips_pack unsigned int *  buffer,
int  position,
const EDR_tkrTower *  twrs,
unsigned int  twrMap,
unsigned int  classMap
[static]
 

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

Returns:
The next writable bit position
Parameters:
buffer The output buffer
position The current bit position
twrs The array of unpacked tower information
twrMap The map of struck towers
classMap The big-endian style classMap

static int strips_pack_0 unsigned int *  buffer,
int  position,
const EDR_tkrLayer *  lyrs,
unsigned int  layerMap
[static]
 

Packs the strips for a Class 0 tower (only one hit strip/layer), no clusters.

Returns:
The next writable bit position
Parameters:
buffer The output buffer
position The current bit position
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

static int strips_pack_1 unsigned int *  buffer,
int  position,
const EDR_tkrLayer *  lyrs,
unsigned int  layerMap
[static]
 

Packs the strips for a Class 1 tower (only one hit strip or one cluster/layer). This needs the address + cluster width + stop.

Returns:
The next writable bit position
Parameters:
buffer The output buffer
position The current bit position
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

static int strips_pack_2 unsigned int *  buffer,
int  position,
const EDR_tkrLayer *  lyrs,
unsigned int  layerMap
[static]
 

Packs the strips for a Class 2 tower (multiple hits, clusters will be expanded.

Returns:
The next writable bit position
Parameters:
buffer The output buffer
position The current bit position
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

static int strips_pack_3 unsigned int *  buffer,
int  position,
const EDR_tkrLayer *  lyrs,
unsigned int  layerMap
[static]
 

Packs the strips for a Class 3 tower (multiple hits, clusters will not be expanded.

Returns:
The next writable bit position
Parameters:
buffer The output buffer
position The current bit position
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

static TotsRet tots_acquire TotsRep tots,
unsigned int  present,
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:
tots The output buffer
present Bit mask of 'ns' values present
lyrs The array of layers for this tower
layerMap The map of struck layers for this tower

static int tots_exp_pack unsigned int *  buffer,
unsigned int  position,
TotsRep tots,
int  ntots,
unsigned int  present
[static]
 

Compresses what is essentially the exponent map of the TOTs.

Returns:
The next bit position to write
Parameters:
buffer The output buffer
position The current bit position
tots The array of TOTs in leading zero format
ntots The number to pack
present A bit mask indicating which values of 'ns' are present

static int tots_man_pack unsigned int *  buffer,
unsigned int  position,
TotsRep tots,
int  ntots
[static]
 

Compresses what is essentially the exponent map of the TOTs.

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

static unsigned int tots_map_compress unsigned int *  buffer,
unsigned int  position,
unsigned int *  map,
unsigned int  mapcnt,
unsigned int  lzeroes
[static]
 

Compresses what is essentially the exponent map of the TOTs.

Returns:
The next bit position to write
Parameters:
buffer The output buffer
position The current bit position
map The map to compress
mapcnt The number of entries in the map
lzeroes The number of leading zeroes/32

static __inline int tots_pack unsigned int *  buffer,
int  position,
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:
buffer The output buffer
position The current bit position
twrs The array of unpacked tower information
twrMap The map of struck towers
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.)

At first glance the algorthm used by the CAL would be seem attractive. In that algorithm the PHA value number of leading is decomposed into two values, an exponent-like value that counts the number of leading zeros and a manitissa-like value that captures the significant bits (less the first leading 1, since it is implied).

However, the method for encoding the exponent does not work here. In the CAL, the number of leading zeros is around 7, here it is only 2-4. With this smaller number of bits, the scheme does not work.

The algorithm used here can be visualize by the following example. Suppose one has the following 4 TOTS, 0x61, 0x73, 0x00, 0x4, 0x18, 0x2c, 0x3d, 0x7d. Now write the bits patterns representing these values vertically (rather than the usual horizontal). Then peel off each row. For each column, only consider entries where no 1 has yet been encountered. Mark down a 0 if, on such entries, the value is 0 and a 1 if the value is 1. Once a value of 1 has been encountered, that column is no longer considered. Now turn this pattern into a string of bits

       Original     Decimated     Bit String
       00000000     00000000      00000000 11000001 00011 001 00 00 1 0
       11000001     11000001
       11000111       00011
       01001011       001
       00001111       00
       00010111       00
       01000000       1
       11100011        0

If the values are all small, then this is quite representative of what one will encounter. The leading bits will be sparsely populated, making this a canidate of a Binary Tree Encoding. Latter in the bit string the number of 0's and 1's become more or less equal. At that time, the Binary Tree Encoding method no longer will compress, but will inflate. To compensate for this, the rule is that as soon as the Binary Tree Encoding ceases to compress, a flag is set, and the remaining bits are emitted as is. (This is perfectly decodable, since the decoder will notice the same thing, i.e. it took more bits to encode than the actual value it represents.)

Once the above process is done, the 'manitissa-like' piece is emitted as is, but only outputting the significant bits. Continuing with the above example, but this time writing the significant digits

       Original     Decimated     Bit String
   7   00000000                   11 111 01 1011 00 1111 00 11111 01 00000
   6   11000001                   1110001
   5   11000111     11   111
   4   01001011     01  1011
   3   00001111     00  1111
   2   00010111     00 11111
   1   01000000     01 00000
   0   11100011     11100011

Note two things in the above

  1. The leading 1 is not included in the significant digits Its existence is implied by the count of signicant digits, i.e. the next bit up must be a 1, so it is unnecessary to include it
  2. Technically a zero is encoded a # significant digits = 1 + a 0. This gets around a pathology

On Monte Carlo events, typical compress sizes are on the order of 2. Almost all this comes from compressing the leading zeros in the exponent-like piece.

There are some tricks played to achieve performance. The main one is keeping track of the pattern of significant bits seen. By doing this one can avoid turning all the leading zeros into a bit array that will be binary tree encoded. Instead, a count is made of these leading zeros, using this pattern array to skip entire rows. For example, in the above, the pattern array would be 00111111, indicating that except for rows 6 and 7 never have the first significant bit. A representation of these leading zeros is trivial to compose without going to the usual expense of the Binary Tree Algorithm.

As a final trick, one notices there is no reason to encode the values in order. It is in fact, advantageous to order the rows from the sparest to the densest. This improves the compression of the exponent-like piece (at the expense of picking out the appropriate bits in the manitissa and reassembling them later.

But wait, there is more, one does not need to encode the final row. Because one already ones, apriori, how many TOTs there are, so, at the final row, one knows exactly which ones are left.

Note:
Currently I am not exploiting the rearrangement for two reasons
  1. It is computationally expensive to rearrange the manitissa bits
  2. The order is very dependent on the data itself. Until proven otherwise, will go with rows in descending order.

static TowerMaps tower_classify const EDR_tkrTower *  twrs,
unsigned int  twrMap
[static]
 

Picks the optimal encoding method for all towers.

Returns:
Big endian maps of the encoding classes and XY layers with hits
Parameters:
twrs The unpacked tower information
twrMap Map of the towers with hits
There are 4 encoding classes. There are classifed by whether one needs at 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

For the layer map, bit position 0, i.e. the MSb, contains X0, bit position 1 contains Y0.

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


Generated on Tue Dec 6 20:25:42 2005 by  doxygen 1.4.4