FairRoot/PandaRoot
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
PndHammingDecoder Class Reference

#include <PndHammingDecoder.h>

Public Member Functions

 PndHammingDecoder ()
 
virtual ~PndHammingDecoder ()
 
UShort_t CheckHammingCode (ULong64_t dataword, int dataword_length)
 
ULong64_t CalculateCRCTableFast (std::vector< char > p, ULong64_t len)
 
ULong64_t ReflectBitsStream (ULong64_t crc, int bitnum)
 
std::vector< char > ConvertData (std::vector< ULong64_t > topixFrame)
 

Protected Member Functions

void GenerateCRCTable ()
 

Private Attributes

const UInt_t fOrder
 
const ULong64_t fPolynom
 
const ULong64_t fCRCXor
 
const UInt_t fRefIn
 
const UInt_t fRefOut
 
ULong64_t fCRCMask
 
ULong64_t fCRCHighBit
 
ULong64_t fCRCInit_direct
 
ULong64_t fCRCTab [256]
 

Detailed Description

Definition at line 13 of file PndHammingDecoder.h.

Constructor & Destructor Documentation

PndHammingDecoder::PndHammingDecoder ( )

Definition at line 13 of file PndHammingDecoder.cxx.

References fCRCHighBit, fCRCMask, fOrder, and GenerateCRCTable().

13  :
14  fOrder(16), fPolynom(0x8005), fCRCXor(0x0000), fRefIn(0), fRefOut(0), fCRCInit_direct(0)
15 {
16  fCRCMask = ((((unsigned long)1<<(fOrder-1))-1)<<1)|1;
17  fCRCHighBit = (unsigned long)1<<(fOrder-1);
18 
20 }
const ULong64_t fPolynom
const ULong64_t fCRCXor
const UInt_t fRefOut
PndHammingDecoder::~PndHammingDecoder ( )
virtual

Definition at line 22 of file PndHammingDecoder.cxx.

22  {
23  // TODO Auto-generated destructor stub
24 }

Member Function Documentation

ULong64_t PndHammingDecoder::CalculateCRCTableFast ( std::vector< char >  p,
ULong64_t  len 
)

Definition at line 75 of file PndHammingDecoder.cxx.

References fCRCInit_direct, fCRCMask, fCRCTab, fCRCXor, fOrder, fRefIn, fRefOut, and ReflectBitsStream().

Referenced by PndMvdReadInToPix4TBData::CheckDataIntegrity().

75  {
76 
77  // fast lookup table algorithm without augmented zero bytes, e.g. used in pkzip.
78  // only usable with polynom orders of 8, 16, 24 or 32.
79 
80  ULong64_t crc = fCRCInit_direct;
81 
82  std::vector<char>::iterator it=p.begin();
83 
84  if (fRefIn)
85  {
86  crc = ReflectBitsStream(crc, fOrder);
87  }
88 
89  if (!fRefIn)
90  {
91  while (len--)
92  {
93  crc = (crc << 8) ^ fCRCTab[ ((crc >> (fOrder-8)) & 0xff) ^ (*it & 0xff)];
94  it++;
95  }
96  }
97  else
98  {
99  while (len--)
100  {
101  crc = (crc >> 8) ^ fCRCTab[ (crc & 0xff) ^ (*it & 0xff)];
102  it++;
103  }
104  }
105  if (fRefOut^fRefIn)
106  {
107  crc = ReflectBitsStream(crc, fOrder);
108  }
109  crc^= fCRCXor;
110  crc&= fCRCMask;
111 
112  return(crc);
113 }
const ULong64_t fCRCXor
Double_t p
Definition: anasim.C:58
ULong64_t fCRCTab[256]
const UInt_t fRefOut
ULong64_t ReflectBitsStream(ULong64_t crc, int bitnum)
UShort_t PndHammingDecoder::CheckHammingCode ( ULong64_t  dataword,
int  dataword_length 
)

Definition at line 26 of file PndHammingDecoder.cxx.

References i.

Referenced by PndMvdReadInToPix4TBData::CheckDataIntegrity().

27 {
28  // This function expects a standard hamming encoded dataword (including hamming bits at 2^i positions) and returns the hamming bits
29  // If the dataword is correct, the hamming bits are 0
30  // If an error occured, the hamming bits are !=0
31  // If a 1-bit error occured, the hamming bits give the possions of the wrong bit
32 
33  ULong64_t shift=1;
34  ULong64_t hamming_code=0;
35 
36  if(dataword_length > 63)
37  {
38  std::cout << "Error: maximum length of datastream is 63" << std::endl;
39  return 0xffff;
40  }
41 
42  // loop over all hamming bits
43  for (int i = 0; pow(2,i) < dataword_length; ++i)
44  {
45  int start=pow(2,i);
46  int stepwidth=2*start;
47  int parity_bit=0;
48  for (int j = start; j < dataword_length+1; j+=stepwidth)
49  {
50  for (int k = j; k < j+stepwidth/2 && k < dataword_length+1; ++k)
51  {
52  parity_bit ^= ((dataword & (shift <<(k-1)))>> (k-1));
53  }
54  }
55  hamming_code += (parity_bit << i);
56  }
57  return hamming_code;
58 }
Int_t i
Definition: run_full.C:25
std::vector< char > PndHammingDecoder::ConvertData ( std::vector< ULong64_t >  topixFrame)

Definition at line 60 of file PndHammingDecoder.cxx.

References i.

Referenced by PndMvdReadInToPix4TBData::CheckDataIntegrity().

61 {
62  std::vector<char> topix_data;
63  for (unsigned int i = 1; i < topixFrame.size() - 1; i++) {
64  for (int j = 0; j < 8; j++) {
65  if (j == 0 or j == 1 or j == 2) {
66  topix_data.push_back(0x00);
67  } else {
68  topix_data.push_back((topixFrame[i] >> (7 - j) * 2 * 4) & 0xff);
69  }
70  }
71  }
72  return topix_data;
73 }
Int_t i
Definition: run_full.C:25
void PndHammingDecoder::GenerateCRCTable ( )
protected

Definition at line 115 of file PndHammingDecoder.cxx.

References fCRCHighBit, fCRCMask, fCRCTab, fOrder, fPolynom, fRefIn, i, and ReflectBitsStream().

Referenced by PndHammingDecoder().

115  {
116  // make CRC lookup table used by table algorithms
117  ULong64_t bit, crc;
118  for (int i=0; i<256; i++) {
119  crc=(ULong64_t)i;
120  if (fRefIn)
121  {
122  crc=ReflectBitsStream(crc, 8);
123  }
124  crc<<= fOrder-8;
125 
126  for (int j=0; j<8; j++)
127  {
128  bit = crc & fCRCHighBit;
129  crc<<= 1;
130  if (bit)
131  {
132  crc^= fPolynom;
133  }
134  }
135  if (fRefIn)
136  {
137  crc = ReflectBitsStream(crc, fOrder);
138  }
139  crc&= fCRCMask;
140  fCRCTab[i]= crc;
141  }
142 }
const ULong64_t fPolynom
Int_t i
Definition: run_full.C:25
ULong64_t fCRCTab[256]
ULong64_t ReflectBitsStream(ULong64_t crc, int bitnum)
ULong64_t PndHammingDecoder::ReflectBitsStream ( ULong64_t  crc,
int  bitnum 
)

Definition at line 144 of file PndHammingDecoder.cxx.

References i.

Referenced by CalculateCRCTableFast(), and GenerateCRCTable().

144  {
145 
146  // reflects the lower 'bitnum' bits of 'crc'
147 
148  ULong64_t i, j=1, crcout=0;
149 
150  for (i=(ULong64_t)1<<(bitnum-1); i; i>>=1)
151  {
152  if (crc & i)
153  {
154  crcout|=j;
155  }
156  j<<= 1;
157  }
158  return (crcout);
159 }
Int_t i
Definition: run_full.C:25

Member Data Documentation

ULong64_t PndHammingDecoder::fCRCHighBit
private

Definition at line 36 of file PndHammingDecoder.h.

Referenced by GenerateCRCTable(), and PndHammingDecoder().

ULong64_t PndHammingDecoder::fCRCInit_direct
private

Definition at line 37 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast().

ULong64_t PndHammingDecoder::fCRCMask
private

Definition at line 35 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast(), GenerateCRCTable(), and PndHammingDecoder().

ULong64_t PndHammingDecoder::fCRCTab[256]
private

Definition at line 38 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast(), and GenerateCRCTable().

const ULong64_t PndHammingDecoder::fCRCXor
private

Definition at line 31 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast().

const UInt_t PndHammingDecoder::fOrder
private

Definition at line 29 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast(), GenerateCRCTable(), and PndHammingDecoder().

const ULong64_t PndHammingDecoder::fPolynom
private

Definition at line 30 of file PndHammingDecoder.h.

Referenced by GenerateCRCTable().

const UInt_t PndHammingDecoder::fRefIn
private

Definition at line 32 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast(), and GenerateCRCTable().

const UInt_t PndHammingDecoder::fRefOut
private

Definition at line 33 of file PndHammingDecoder.h.

Referenced by CalculateCRCTableFast().


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