[Halld-offline] additional compression of data

Kei Moriya kmoriya at indiana.edu
Wed Aug 24 15:49:07 EDT 2011


Hi all,

There was a brief discussion during the meeting about
(additional) compression of the data.

Below are examples from a compression used for CLAS at CMU,
where 3 floats are compressed into 1 integer
(compression of 3 x 4 = 12 bytes to 4 bytes).
Encode3Rhos does the compression, and Decode3Rhos
extracts the original numbers. You can see that for
example the sign of the variable n1 is compressed into
a sign, or 1 bit of the int.

Once we are definitely sure which variables we are saving,
it would be a few hours of coding to find the right combination
of variables to save this way, and writing the encoding/decoding
functions.

A few caveats are:

1. The precision of each original value will be limited
(in the example 3 digits). Programming guards will be needed.

2. If the value of each original value exceeds a threshold
(in the example 1000), then there will be inconsistencies.
Knowledge of the limits of each number are needed.

3. Reorganizing the encoding/decoding can be cumbersome,
so I would recommend doing this once all the variables are
finalized.

Best regards,

	Kei
------------------------------------------------------------------------------

Int_t ATrack::Encode3Rhos(Float_t r1,Float_t r2,Float_t r3){
   // Encode 3 rhos into 1 integer. Rho is the corelation between 2 of the
   // tracking quantities, ex.) Rho(p,phi) = c13/sqrt(c11*c33). Thus, rho must
   // be between -1 and 1. Each rho is stored as 0.XXX, r3's sign is NOT stored
   // and thus must be known (several of the corelations have the same sign for
   // every track in CLAS, these are stored as r3), r1 and r2's signs are stored
   // r1's is the sign of the integer and r2's is a flag in the 10^10 place.
   Int_t n1,n2,n3,value;

   n1 = (int)(r1*1000.);
   n2 = (int)(r2*1000.);
   n3 = (int)(r3*1000.);

   value = abs(n1)*1000000 + abs(n2)*1000 + abs(n3);

   if(n2 < 0) value += 1000000000;
   if(n1 < 0) value *= -1;

   return value;
}
//_____________________________________________________________________________

Float_t ATrack::Decode3Rhos(Int_t encoded,Int_t n) const {
   // Decode the 3 rhos in encoded and return the nth one as a Float_t. This
   // function is the inverse of Encode3Rhos.
   Float_t r1 = 1.,r2 = 1.,r3 = 1.;

   if(encoded < 0){
     r1 = -1.;
     encoded *= -1;
   }
   if(abs(encoded)/1000000000 >= 1){
     r2 = -1.;
     encoded -= 1000000000;
   }
   r1 *= (encoded/1000000)/1000.;
   encoded -= (encoded/1000000)*1000000;
   r2 *= (encoded/1000)/1000.;
   encoded -= (encoded/1000)*1000;
   r3 = encoded/1000.;

   if(n == 1) return r1;
   if(n == 2) return r2;
   if(n == 3) return r3;
   return 0.0;
}
//_____________________________________________________________________________



More information about the Halld-offline mailing list