ATLAS Offline Software
Loading...
Searching...
No Matches
ErrorMatrixCompressor Class Reference

#include <ErrorMatrixCompressor.h>

Collaboration diagram for ErrorMatrixCompressor:

Classes

class  Triplet

Public Member Functions

 ErrorMatrixCompressor (int)
 ~ErrorMatrixCompressor ()
bool compress (const std::vector< double > &, std::vector< unsigned int > &)
bool restore (const std::vector< unsigned int > &, std::vector< double > &)
void setBiases (const int b[6])
void setUpperLimits (const int l[2])

Protected Member Functions

bool CholeskyDecomposition (double a[5][5], double L[5][5])
bool compressFR (const std::vector< FloatRep > &, std::vector< unsigned short > &)
bool restoreFR (const std::vector< unsigned short > &, std::vector< FloatRep > &)

Protected Attributes

short int m_biases [6]
short int m_limits [2]
double m_scales [5]
int m_bitStrip

Private Attributes

DecoderFloat_IEEE754 m_decoder
unsigned int m_srcMasks [16]
std::vector< Tripletm_tripVec

Detailed Description

Definition at line 124 of file ErrorMatrixCompressor.h.

Constructor & Destructor Documentation

◆ ErrorMatrixCompressor()

ErrorMatrixCompressor::ErrorMatrixCompressor ( int b)

Definition at line 82 of file ErrorMatrixCompressor.cxx.

83{
84 short int biasArray[6] = {116,120,118,116,116,102};
85
86
87 double T[5]={0.2,0.5,100.0,100.0,20000.0};
88
90 for(int i=0;i<6;i++)
91 {
92 m_biases[i]=biasArray[i];
93 }
94 for(int i=0;i<5;i++)
95 {
96 m_scales[i]=T[i];
97 }
98 m_limits[0]=15;
99 m_limits[1]=31;
100 m_srcMasks[0]= 0x80000000;
101 m_srcMasks[1]= 0xC0000000;
102 m_srcMasks[2]= 0xE0000000;
103 m_srcMasks[3]= 0xF0000000;
104 m_srcMasks[4]= 0xF8000000;
105 m_srcMasks[5]= 0xFC000000;
106 m_srcMasks[6]= 0xFE000000;
107 m_srcMasks[7]= 0xFF000000;
108 m_srcMasks[8]= 0xFF800000;
109 m_srcMasks[9]= 0xFFC00000;
110 m_srcMasks[10]=0xFFE00000;
111 m_srcMasks[11]=0xFFF00000;
112 m_srcMasks[12]=0xFFF80000;
113 m_srcMasks[13]=0xFFFC0000;
114 m_srcMasks[14]=0xFFFE0000;
115 m_srcMasks[15]=0xFFFF0000;
116 m_tripVec.clear();
117 m_tripVec.push_back(Triplet(0,1,3));
118 m_tripVec.push_back(Triplet(2,4,6));
119 m_tripVec.push_back(Triplet(5,7,8));
120 m_tripVec.push_back(Triplet(9,10,11));
121 m_tripVec.push_back(Triplet(14,12,13));
122}
std::vector< Triplet > m_tripVec
unsigned long long T

◆ ~ErrorMatrixCompressor()

ErrorMatrixCompressor::~ErrorMatrixCompressor ( )
inline

Definition at line 140 of file ErrorMatrixCompressor.h.

140{m_tripVec.clear();}

Member Function Documentation

◆ CholeskyDecomposition()

bool ErrorMatrixCompressor::CholeskyDecomposition ( double a[5][5],
double L[5][5] )
protected

Definition at line 141 of file ErrorMatrixCompressor.cxx.

142{
143
144 int i,j,k;
145 double sum;
146 double p[5];
147
148 for(i=0;i<5;i++)
149 {
150 for(j=i;j<5;j++)
151 {
152 sum=a[i][j];
153 for(k=i-1;k>=0;k--)
154 sum-=a[i][k]*a[j][k];
155 if(i==j)
156 {
157 if(sum<=0.0)
158 {
159 return false;
160 }
161 p[i]=sqrt(sum);L[i][i]=p[i];
162 }
163 else
164 {
165 a[j][i]=sum/p[i];
166 L[j][i]=a[j][i];
167 }
168 }
169 }
170 return true;
171}
static Double_t a

◆ compress()

bool ErrorMatrixCompressor::compress ( const std::vector< double > & src,
std::vector< unsigned int > & dest )

Definition at line 173 of file ErrorMatrixCompressor.cxx.

174{
175 int i,j;
176 double L[5][5],C0[5][5],C[5][5];
177 float S[5][5];
178
179 dest.clear();
180
181 int idx=0;
182 for (i=0;i<5;i++)
183 for(j=0;j<=i;j++)
184 {
185 C[i][j]=src[idx];
186 C[j][i]=C0[i][j]=C0[j][i]=C[i][j];
187 idx++;
188 }
189
190 memset(&L[0][0],0,sizeof(L));
191
192 for(i=0;i<5;i++)
193 for(j=0;j<=i;j++)
194 {
195 C[i][j]*=(m_scales[i]*m_scales[j]);
196 C[j][i]=C[i][j];
197 }
198 if(!CholeskyDecomposition(C,L)) return false;
199 memset(&S[0][0],0,sizeof(S));
200 for(i=0;i<5;i++)
201 for(j=0;j<=i;j++) S[i][j]=L[i][j];
202
203 std::vector<FloatRep> vecFR;
204 vecFR.clear();
205
206 for(i=0;i<5;i++)
207 {
208 for(j=0;j<=i;j++)
209 {
210 m_decoder.setF(S[i][j]);
211 char sign=(S[i][j]<0)?1:0;
212 unsigned int mant=m_decoder.getMantissa();
213 unsigned short int ex=m_decoder.getExponent();
214 vecFR.push_back(FloatRep(sign,ex,mant));
215 }
216 }
217 std::vector<unsigned short> vShorts;
218 vShorts.clear();
219 if(!compressFR(vecFR,vShorts)) return false;
220
221 //re-packing as ints
222
223 // std::cout<<"Total "<<vShorts.size()<<" unsigned short"<<std::endl;
224
225 int nBits=0;
226 unsigned int buffer = 0x00000000;
227
228 for(std::vector<unsigned short>::iterator it = vShorts.begin(); it != vShorts.end();++it) {
229 // printf("short = 0x%X\n",(*it));
230 if(nBits==2) {
231 dest.push_back(buffer);
232 nBits=0;
233 buffer = 0x00000000;
234 }
235 if(nBits==0) {
236 buffer = (*it);
237 buffer = buffer << 16;
238 nBits++;
239 }
240 else {
241 buffer = buffer | (*it);
242 nBits++;
243 }
244 }
245 dest.push_back(buffer);
246 return true;
247}
int sign(int a)
bool compressFR(const std::vector< FloatRep > &, std::vector< unsigned short > &)
DecoderFloat_IEEE754 m_decoder
bool CholeskyDecomposition(double a[5][5], double L[5][5])
struct color C

◆ compressFR()

bool ErrorMatrixCompressor::compressFR ( const std::vector< FloatRep > & src,
std::vector< unsigned short > & dest )
protected

Definition at line 308 of file ErrorMatrixCompressor.cxx.

309{
310 unsigned short buf=0x0000;
311 dest.clear();
312 int nMantLength=23-m_bitStrip;
313 if(nMantLength<8)
314 {
315 std::cout<<"Requested mantissa reduction is too large: 23->"<<nMantLength<<std::endl;
316 return false;
317 }
318 std::vector<FloatRep>::const_iterator fIt;
319 /*
320 for(fIt=src.begin();fIt!=src.end();++fIt)
321 {
322 printf("%d %d %d -> %2.8f\n",(*fIt).sign(),
323 (*fIt).exponent(),(*fIt).mantissa(),(*fIt).restore());
324 }
325 */
326 // 1. Check limits
327 fIt=src.begin();
328 int i,j;
329 for (i=0;i<5;i++)
330 for (j=0;j<=i;j++)
331 {
332 unsigned short int ex=(*fIt).exponent();
333 unsigned int mant=(*fIt).mantissa();
334 int bias,limit;
335 if(i==j)
336 {
337 bias=m_biases[i];
338 limit=m_limits[0];
339 }
340 else
341 {
342 bias=m_biases[5];
343 limit=m_limits[1];
344 }
345 if((ex!=0)&&(mant!=0))
346 {
347 if((ex<bias)||(ex-bias>limit))
348 {
349 // std::cout<<"i="<<i<<" j="<<j<<" ex="<<ex<<" bias="<<bias<<" lim="<<limit<<std::endl;
350 return false;
351 }
352 }
353 ++fIt;
354 }
355 // 2. Pack exponents: diag e + non-diag s1 + non-diag e1 + non-diag s2 + non-diag e2
356
357 i=0;
358 for(std::vector<Triplet>::iterator trIt=m_tripVec.begin();trIt!=m_tripVec.end();++trIt)
359 {
360 int i1,i2[2];
361 i1=(*trIt).m_d;
362 i2[0]=(*trIt).m_nd1;i2[1]=(*trIt).m_nd2;
363 //printf("%d %d %d\n",i1,i2[0],i2[1]);
364 buf=0x0000;
365 unsigned short e;
366
367 e=src[i1].exponent()-m_biases[i];
368 buf = buf | ((e<<12) & 0xF000);
369 if((src[i2[0]].exponent()==0)&&(src[i2[0]].mantissa()==0))
370 {
371 e=src[i2[0]].exponent();
372 buf = buf | 0x0800;//-0
373 }
374 else
375 {
376 if(src[i2[0]].sign())
377 buf = buf | 0x0800;
378 e=src[i2[0]].exponent()-m_biases[5];
379 }
380 buf = buf | ((e<<6) & 0x07C0);
381 if((src[i2[1]].exponent()==0)&&(src[i2[1]].mantissa()==0))
382 {
383 buf = buf | 0x0020;//-0
384 e=src[i2[1]].exponent();
385 }
386 else
387 {
388 e=src[i2[1]].exponent()-m_biases[5];
389 if(src[i2[1]].sign())
390 buf = buf | 0x0020;
391 }
392 buf = buf | (e & 0x001F);
393 // printf("Exponent 0x%X\n",buf);
394 dest.push_back(buf);
395 i++;
396 }
397 // 3. Pack reduced mantissas
398 fIt=src.begin();
399 unsigned int nPacked=0;
400 int nFreeBits=0,nBitsToStore=0,nBufferLength=0;
401 unsigned int srcBuffer=0x00000000;
402 // printf("L=%d\n",nMantLength);
403 while (nPacked<=src.size()+1)
404 {
405 if(nFreeBits==0)
406 {
407 if(nBufferLength!=0)
408 {
409 dest.push_back(buf);
410 // printf("Storing 0x%X\n",buf);
411 }
412 buf=0x0000;
413 nFreeBits=16;
414 nBufferLength++;
415 }
416 if(nBitsToStore==0)
417 {
418 if(nPacked!=0)
419 ++fIt;
420 if(fIt==src.end()) break;
421 nPacked++;
422 srcBuffer=((*fIt).mantissa()<<9);
423 // printf("Packing 0x%X = %ud\n",(*fIt).mantissa(),(*fIt).mantissa());
424 nBitsToStore=nMantLength;
425 }
426 int Np=(nBitsToStore>nFreeBits)?nFreeBits:nBitsToStore;
427 unsigned int mask=m_srcMasks[Np-1];
428 unsigned int slice = srcBuffer & mask;
429 slice = (slice >> (32-nFreeBits)) & 0x0000FFFF;
430 unsigned int tmp=(unsigned int)(slice);
431 // printf("Np=%d Tmp=0x%X\n",Np,tmp);
432 buf = buf | tmp;
433 srcBuffer = srcBuffer << Np;
434 // printf("dest=0x%X src=0x%X\n",buf,srcBuffer);
435 nFreeBits-=Np;
436 nBitsToStore-=Np;
437 //cout<<"F="<<nFreeBits<<" TS="<<nBitsToStore<<endl;
438 }
439 // printf("Storing 0x%X\n",buf);
440 dest.push_back(buf);
441 return true;
442}

◆ restore()

bool ErrorMatrixCompressor::restore ( const std::vector< unsigned int > & src,
std::vector< double > & dest )

Definition at line 249 of file ErrorMatrixCompressor.cxx.

250{
251 int i,j;
252 float S[5][5];
253 double L[5][5],C[5][5];
254
255 dest.clear();
256
257 std::vector<FloatRep> vecFR;
258 vecFR.clear();
259
260 std::vector<unsigned short> vShorts;
261
262 vShorts.clear();
263
264 for (unsigned int ii : src) {
265 unsigned short s1,s2;
266
267 s1 = (unsigned short)((0xFFFF0000 & ii) >> 16);
268 s2 = (unsigned short)(0x0000FFFF & ii);
269 vShorts.push_back(s1);
270 //if(!((s2==0) && ((it+1)==src.end()))) //do not store last zero
271 vShorts.push_back(s2);
272 }
273
274 if(!restoreFR(vShorts,vecFR)) return false;
275
276 std::vector<FloatRep>::iterator fIt(vecFR.begin());
277 memset(&S[0][0],0,sizeof(S));
278 for(i=0;i<5;i++)
279 for(j=0;j<=i;j++)
280 {
281 if(fIt==vecFR.end()) break;
282 S[i][j]=(*fIt).restore();
283 ++fIt;
284 }
285
286 memset(&L[0][0],0,sizeof(L));
287 for(i=0;i<5;i++)
288 for(j=0;j<=i;j++) L[i][j]=S[i][j];
289 for(i=0;i<5;i++)
290 for(j=i;j<5;j++)
291 {
292 C[i][j]=0.0;
293 for(int k=0;k<5;k++)
294 C[i][j]+=L[i][k]*L[j][k];
295 C[j][i]=C[i][j];
296 }
297 for(i=0;i<5;i++)
298 for(j=0;j<=i;j++)
299 {
300 C[i][j]/=(m_scales[i]*m_scales[j]);
301 C[j][i]=C[i][j];
302 }
303 for(i=0;i<5;i++) for(j=0;j<=i;j++) dest.push_back(C[i][j]);
304 return true;
305}
bool restoreFR(const std::vector< unsigned short > &, std::vector< FloatRep > &)

◆ restoreFR()

bool ErrorMatrixCompressor::restoreFR ( const std::vector< unsigned short > & src,
std::vector< FloatRep > & dest )
protected

Definition at line 444 of file ErrorMatrixCompressor.cxx.

445{
446 int i,nRestored,nFreeBits,nBitsToStore;
447 unsigned short buf=0x0000;
448 unsigned int destBuffer=0x00000000;
449 std::vector<unsigned short>::const_iterator uIt(src.begin());
450 dest.clear();
451
452 for(i=0;i<15;i++)
453 {
454 dest.push_back(FloatRep(0,0,0));
455 }
456
457 i=0;
458 for(;uIt!=src.end();++uIt)
459 {
460 int i0=m_tripVec[i].m_d;
461 int i1=m_tripVec[i].m_nd1;
462 int i2=m_tripVec[i].m_nd2;
463 buf=(*uIt);
464 char s=((buf & 0x0800)==0)?0:1;
465 dest[i1].sign(s);
466 s=((buf & 0x0020)==0)?0:1;
467 dest[i2].sign(s);
468 unsigned short e = ((buf & 0xF000) >> 12);
469 dest[i0].exponent(e+m_biases[i]);
470 e = ((buf & 0x07C0) >> 6);
471 dest[i1].exponent(e+m_biases[5]);
472 e = (buf & 0x001F);
473 dest[i2].exponent(e+m_biases[5]);
474 i++;
475 if(i==5) break;
476 }
477 if(i<5) return false;
478 nRestored=0;
479 nBitsToStore=0;
480 nFreeBits=0;
481 int nMantLength=23-m_bitStrip;
482 while(nRestored<=15)
483 {
484 if(nFreeBits==0)
485 {
486 if(nRestored!=0)
487 {
488 //printf("Dest 0x%X ",destBuffer);
489 destBuffer = destBuffer << m_bitStrip;
490 //printf("<< 0x%X = %lu\n",destBuffer,destBuffer);
491 dest[nRestored-1].mantissa(destBuffer);
492 }
493 ++nRestored;
494 destBuffer=0x00000000;
495 nFreeBits=nMantLength;
496 }
497 if(nBitsToStore==0)
498 {
499 if(uIt==src.end()) break;
500 ++uIt;
501 if(uIt==src.end())
502 {
503 //printf("Breaking ... nR=%d\n",nRestored);
504 break;
505 }
506 nBitsToStore=16;buf=(*uIt);//printf("Source 0x%X\n",buf);
507 }
508 int Np=(nFreeBits>nBitsToStore) ? nBitsToStore : nFreeBits;
509 unsigned int tmp = buf;
510 tmp = tmp >> (16-Np);
511 buf = (unsigned int)((buf << Np) & 0x0000FFFF);
512 //printf("F=%d TS=%d Np=%d 0x%X 0x%X\n",nFreeBits,nBitsToStore,Np,tmp,buf);
513 nBitsToStore-=Np;
514 //printf("Copy 0x%X ",destBuffer);
515 destBuffer = destBuffer << Np;
516 //printf("<< 0x%X ",destBuffer);
517 destBuffer = destBuffer | tmp;
518 //printf(" | 0x%X\n",destBuffer);
519 nFreeBits-=Np;
520 //printf("nR=%d\n",nRestored);
521 }
522 return true;
523}

◆ setBiases()

void ErrorMatrixCompressor::setBiases ( const int b[6])

Definition at line 124 of file ErrorMatrixCompressor.cxx.

125{
126 for(int i=0;i<6;i++)
127 {
128 m_biases[i]=b[i];
129 }
130}

◆ setUpperLimits()

void ErrorMatrixCompressor::setUpperLimits ( const int l[2])

Definition at line 132 of file ErrorMatrixCompressor.cxx.

133{
134 for(int i=0;i<2;i++)
135 {
136 m_limits[i]=l[i];
137 }
138}
l
Printing final latex table to .tex output file.

Member Data Documentation

◆ m_biases

short int ErrorMatrixCompressor::m_biases[6]
protected

Definition at line 153 of file ErrorMatrixCompressor.h.

◆ m_bitStrip

int ErrorMatrixCompressor::m_bitStrip
protected

Definition at line 157 of file ErrorMatrixCompressor.h.

◆ m_decoder

DecoderFloat_IEEE754 ErrorMatrixCompressor::m_decoder
private

Definition at line 160 of file ErrorMatrixCompressor.h.

◆ m_limits

short int ErrorMatrixCompressor::m_limits[2]
protected

Definition at line 154 of file ErrorMatrixCompressor.h.

◆ m_scales

double ErrorMatrixCompressor::m_scales[5]
protected

Definition at line 155 of file ErrorMatrixCompressor.h.

◆ m_srcMasks

unsigned int ErrorMatrixCompressor::m_srcMasks[16]
private

Definition at line 161 of file ErrorMatrixCompressor.h.

◆ m_tripVec

std::vector<Triplet> ErrorMatrixCompressor::m_tripVec
private

Definition at line 162 of file ErrorMatrixCompressor.h.


The documentation for this class was generated from the following files: