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

PndCRCCalculator calculates the CRC checksum from a given vector<char> More...

#include <PndCRCCalculator.h>

Inheritance diagram for PndCRCCalculator:

Public Member Functions

 PndCRCCalculator ()
 
 PndCRCCalculator (UInt_t order, ULong64_t polynom, ULong64_t CRCXor, UInt_t refIn, UInt_t refOut, UInt_t CRCInit_direct)
 
virtual ~PndCRCCalculator ()
 
ULong64_t CalculateCRCTableFast (std::vector< char > p, ULong64_t len)
 
ULong64_t ReflectBitsStream (ULong64_t crc, int bitnum)
 
void PrintCRCTable ()
 

Protected Member Functions

void GenerateCRCTable ()
 

Private Member Functions

 ClassDef (PndCRCCalculator, 1)
 

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

PndCRCCalculator calculates the CRC checksum from a given vector<char>

PndCRCCalculator is based on a look-up table initially calculated from the paramters of the used CRC code. The output of the calculator was cross-checked with the online CRC calculator: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html Both the generated look-up tables as the output match

Author
T.Stockmanns t.sto.nosp@m.ckma.nosp@m.nns@f.nosp@m.z-ju.nosp@m.elich.nosp@m..de

Definition at line 17 of file PndCRCCalculator.h.

Constructor & Destructor Documentation

PndCRCCalculator::PndCRCCalculator ( )

Definition at line 9 of file PndCRCCalculator.cxx.

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

9  :
10  fOrder(16), fPolynom(0x8005), fCRCXor(0x0000), fRefIn(0), fRefOut(0), fCRCInit_direct(0)
11 {
12  fCRCMask = ((((unsigned long)1<<(fOrder-1))-1)<<1)|1;
13  fCRCHighBit = (unsigned long)1<<(fOrder-1);
14 
16 }
const UInt_t fOrder
const ULong64_t fPolynom
const UInt_t fRefIn
const ULong64_t fCRCXor
const UInt_t fRefOut
ULong64_t fCRCInit_direct
PndCRCCalculator::PndCRCCalculator ( UInt_t  order,
ULong64_t  polynom,
ULong64_t  CRCXor,
UInt_t  refIn,
UInt_t  refOut,
UInt_t  CRCInit_direct 
)

Definition at line 18 of file PndCRCCalculator.cxx.

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

18  :
19  fOrder(order), fPolynom(polynom), fCRCXor(CRCXor), fRefIn(refIn), fRefOut(refOut), fCRCInit_direct(CRCInit_direct)
20 {
21  fCRCMask = ((((unsigned long)1<<(fOrder-1))-1)<<1)|1;
22  fCRCHighBit = (unsigned long)1<<(fOrder-1);
23 
25 }
const UInt_t fOrder
const ULong64_t fPolynom
const UInt_t fRefIn
const ULong64_t fCRCXor
const UInt_t fRefOut
ULong64_t fCRCInit_direct
PndCRCCalculator::~PndCRCCalculator ( )
virtual

Definition at line 28 of file PndCRCCalculator.cxx.

28  {
29  // TODO Auto-generated destructor stub
30 }

Member Function Documentation

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

Definition at line 47 of file PndCRCCalculator.cxx.

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

Referenced by CheckCRC().

47  {
48 
49  // fast lookup table algorithm without augmented zero bytes, e.g. used in pkzip.
50  // only usable with polynom orders of 8, 16, 24 or 32.
51 
52  ULong64_t crc = fCRCInit_direct;
53 
54  std::vector<char>::iterator it = p.begin();
55 
56  if (fRefIn) {
57  crc = ReflectBitsStream(crc, fOrder);
58  }
59 
60  if (!fRefIn) {
61  while (len--) {
62  crc = (crc << 8) ^ fCRCTab[((crc >> (fOrder - 8)) & 0xff) ^ (*it & 0xff)];
63  it++;
64  }
65  } else {
66  while (len--) {
67  crc = (crc >> 8) ^ fCRCTab[(crc & 0xff) ^ (*it & 0xff)];
68  it++;
69  }
70  }
71  if (fRefOut ^ fRefIn) {
72  crc = ReflectBitsStream(crc, fOrder);
73  }
74  crc ^= fCRCXor;
75  crc &= fCRCMask;
76 
77  return (crc);
78 }
const UInt_t fOrder
Double_t p
Definition: anasim.C:58
const UInt_t fRefIn
ULong64_t ReflectBitsStream(ULong64_t crc, int bitnum)
ULong64_t fCRCTab[256]
const ULong64_t fCRCXor
const UInt_t fRefOut
ULong64_t fCRCInit_direct
PndCRCCalculator::ClassDef ( PndCRCCalculator  ,
 
)
private
void PndCRCCalculator::GenerateCRCTable ( )
protected

Definition at line 80 of file PndCRCCalculator.cxx.

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

Referenced by PndCRCCalculator().

80  {
81  // make CRC lookup table used by table algorithms
82  ULong64_t bit, crc;
83  for (int i=0; i<256; i++) {
84  crc=(ULong64_t)i;
85  if (fRefIn)
86  {
87  crc=ReflectBitsStream(crc, 8);
88  }
89  crc<<= fOrder-8;
90 
91  for (int j=0; j<8; j++)
92  {
93  bit = crc & fCRCHighBit;
94  crc<<= 1;
95  if (bit)
96  {
97  crc^= fPolynom;
98  }
99  }
100  if (fRefIn)
101  {
102  crc = ReflectBitsStream(crc, fOrder);
103  }
104  crc&= fCRCMask;
105  fCRCTab[i]= crc;
106  }
107 }
Int_t i
Definition: run_full.C:25
const UInt_t fOrder
const ULong64_t fPolynom
const UInt_t fRefIn
ULong64_t ReflectBitsStream(ULong64_t crc, int bitnum)
ULong64_t fCRCTab[256]
void PndCRCCalculator::PrintCRCTable ( )

Definition at line 109 of file PndCRCCalculator.cxx.

References fCRCTab, and i.

110 {
111  for (int i = 0; i < 16; i++){
112  for (int j = 0; j < 16; j++){
113  std::cout << std::hex << fCRCTab[i*16 + j] << " ";
114  }
115  std::cout << std::endl;
116  }
117 }
Int_t i
Definition: run_full.C:25
ULong64_t fCRCTab[256]
ULong64_t PndCRCCalculator::ReflectBitsStream ( ULong64_t  crc,
int  bitnum 
)

Definition at line 119 of file PndCRCCalculator.cxx.

References i.

Referenced by CalculateCRCTableFast(), and GenerateCRCTable().

119  {
120 
121  // reflects the lower 'bitnum' bits of 'crc'
122 
123  ULong64_t i, j=1, crcout=0;
124 
125  for (i=(ULong64_t)1<<(bitnum-1); i; i>>=1)
126  {
127  if (crc & i)
128  {
129  crcout|=j;
130  }
131  j<<= 1;
132  }
133  return (crcout);
134 }
Int_t i
Definition: run_full.C:25

Member Data Documentation

ULong64_t PndCRCCalculator::fCRCHighBit
private

Definition at line 44 of file PndCRCCalculator.h.

Referenced by GenerateCRCTable(), and PndCRCCalculator().

ULong64_t PndCRCCalculator::fCRCInit_direct
private

Definition at line 45 of file PndCRCCalculator.h.

Referenced by CalculateCRCTableFast().

ULong64_t PndCRCCalculator::fCRCMask
private

Definition at line 43 of file PndCRCCalculator.h.

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

ULong64_t PndCRCCalculator::fCRCTab[256]
private

Definition at line 46 of file PndCRCCalculator.h.

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

const ULong64_t PndCRCCalculator::fCRCXor
private

Definition at line 39 of file PndCRCCalculator.h.

Referenced by CalculateCRCTableFast().

const UInt_t PndCRCCalculator::fOrder
private

Definition at line 37 of file PndCRCCalculator.h.

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

const ULong64_t PndCRCCalculator::fPolynom
private

Definition at line 38 of file PndCRCCalculator.h.

Referenced by GenerateCRCTable().

const UInt_t PndCRCCalculator::fRefIn
private

Definition at line 40 of file PndCRCCalculator.h.

Referenced by CalculateCRCTableFast(), and GenerateCRCTable().

const UInt_t PndCRCCalculator::fRefOut
private

Definition at line 41 of file PndCRCCalculator.h.

Referenced by CalculateCRCTableFast().


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