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

#include <GenericCrc.h>

Collaboration diagram for GenericCrc:

Public Member Functions

 GenericCrc ()
 Provides a library of known CRC(like) algorithms.
 ~GenericCrc ()
uint32_t crc9fibre (const std::vector< uint32_t > &inwords, size_t num_bits) const
 Functions calculating CRC over input data.
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}
order
Configure Herwig7.
setEventNumber uint32_t

◆ 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{
14
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: