ATLAS Offline Software
Public Member Functions | List of all members
GenericCrc Class Reference

#include <GenericCrc.h>

Collaboration diagram for GenericCrc:

Public Member Functions

 GenericCrc ()
 Provides a library of known CRC(like) algorithms. More...
 
 ~GenericCrc ()
 
uint32_t crc9fibre (const std::vector< uint32_t > &inwords, size_t num_bits) const
 Functions calculating CRC over input data. More...
 
uint32_t crc20rod (const std::vector< uint32_t > &inwords, size_t num_bits) const
 

Detailed Description

Definition at line 9 of file GenericCrc.h.

Constructor & Destructor Documentation

◆ GenericCrc()

GenericCrc::GenericCrc ( )
inline

Provides a library of known CRC(like) algorithms.

GenericCrc is a stateless class which just provides a collection of CRC-like functions for various stages of data processing

Definition at line 20 of file GenericCrc.h.

20 {}

◆ ~GenericCrc()

GenericCrc::~GenericCrc ( )
inline

Definition at line 21 of file GenericCrc.h.

21 {}

Member Function Documentation

◆ crc20rod()

uint32_t GenericCrc::crc20rod ( const std::vector< uint32_t > &  inwords,
size_t  num_bits 
) const

Definition at line 33 of file GenericCrc.cxx.

34 {
35  int order = 20;
36  uint32_t val = 0xfffff;
37  //<<uint32_t poly = 0x18349f; // Old, wrong, polynomial used until December 2021
38  uint32_t poly = 0x18359f;
39  size_t num_words = inwords.size();
40  if ( (num_bits+31)/32 > num_words )
41  {
42  std::cout << "ERROR: not enough words (" << num_words << ") for " << num_bits << "-bit CRC calculation." << std::endl;
43  return 0;
44  }
45  for ( int i = 0 ; i < order ; ++i )
46  {
47  int flip = val&1;
48  val >>= 1;
49  if ( flip )
50  val ^= (poly>>1);
51  }
52  for ( size_t i = 0 ; i < num_bits ; ++i )
53  {
54  val <<= 1;
55  val |= (inwords[i/32]>>(31-i%32))&1;
56  if ((val>>order)&1)
57  val ^= poly;
58  }
59  for ( int i = 0 ; i < order ; ++i )
60  {
61  val <<= 1;
62  if ((val>>order)&1)
63  val ^= poly;
64  }
65  return val;
66 }

◆ crc9fibre()

uint32_t GenericCrc::crc9fibre ( const std::vector< uint32_t > &  inwords,
size_t  num_bits 
) const

Functions calculating CRC over input data.

CRC9 with polynomial 1011111011 over num_bits bits

Uses a more succinct CRC calculation and flexible in terms of digits, checked versus old code but only supports bit reversal = true

Definition at line 5 of file GenericCrc.cxx.

6 {
15  size_t num_words = inwords.size();
16  if ( (num_bits+31)/32 > num_words )
17  {
18  std::cout << "ERROR: not enough words (" << num_words << ") for " << num_bits << "-bit CRC calculation." << std::endl;
19  return 0;
20  }
21  uint32_t val = 0x1ff;
22  for ( size_t i = 0 ; i < num_bits ; ++i )
23  {
24  if ( (inwords.at(i/32)>>(i%32)) & 1 )
25  val ^= 1;
26  if ( val&1 )
27  val ^= 0x37d; // 1101111101 = polynomial reversed
28  val >>= 1;
29  }
30  return val;
31 }

The documentation for this class was generated from the following files:
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
MuonCalib::Legendre::poly
constexpr double poly(const double x)
Definition: LegendrePoly.h:116
lumiFormat.i
int i
Definition: lumiFormat.py:85
mc.order
order
Configure Herwig7.
Definition: mc.Herwig7_Dijet.py:12
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14