LDMX Software
|
The HGC ROC and FPGA use a CRC checksum to double check that the data transfer has been done correctly. More...
#include <CRC.h>
Public Member Functions | |
template<typename WordType , std::enable_if_t< std::is_integral< WordType >::value, bool > = true> | |
CRC & | operator<< (const WordType &w) |
Stream an integral type into the calculator. | |
template<typename ObjectType , std::enable_if_t< std::is_class< ObjectType >::value, bool > = true> | |
CRC & | operator<< (const ObjectType &o) |
Stream an instance of a class into the calculator. | |
template<typename ContentType > | |
CRC & | operator<< (const std::vector< ContentType > &vec) |
Stream a vector of objects into the calculator. | |
uint32_t | get () |
Get the calculate checksum from the calculator. | |
Private Attributes | |
boost::crc_32_type | crc |
the object from Boost doing the summing | |
The HGC ROC and FPGA use a CRC checksum to double check that the data transfer has been done correctly.
Boost has a CRC checksum library that we can use to do this checking here as well.
Idea for this helper struct was found on StackOverflow https://stackoverflow.com/a/63237679 I've actually simplified it by limiting its use-case to our type of data which is integral types, classes with the 'add' method defined, and vectors of those types.
This is a very light class and is meant to be used as a calculator. It involves some fancy-shamncy template specialization using std::enable_if in order for the streaming operator to function.
class MyObject { public: CRC& add(CRC& c) { c << my_member_int_; } private: uint64_t my_member_int_; } my_object;
CRC c; c << 0xffff << std::vector<uint16_t>({0xffff, 0x00ff}) << my_object; uint32_t the_sum = c.get();
This design limits the inputs to the calculator to two main categories.
|
inline |
Get the calculate checksum from the calculator.
Definition at line 110 of file CRC.h.
References crc.
Referenced by packing::rawdatafile::File::close(), packing::rawdatafile::EventPacket::EventPacket(), packing::rawdatafile::File::File(), ecal::EcalRawEncoder::produce(), hcal::HcalRawDecoder::read(), and packing::rawdatafile::SubsystemPacket::SubsystemPacket().
|
inline |
Stream an instance of a class into the calculator.
Here, we assume that the class we are streaming into the calculator has a specific public method defined.
CRC& add(CRC& c)
and the user can insert the subcomponents to the calculator within this method.
o | instance of an arbitrary class |
Definition at line 86 of file CRC.h.
|
inline |
Stream a vector of objects into the calculator.
When the compiler deduces that the input to the stream is a vector, we simply call the stream operator on all members of the vector in sequence.
[in] | vec | vector of objects to insert into calculator |
Definition at line 101 of file CRC.h.
|
inline |
Stream an integral type into the calculator.
This is only enabled for integral types i.e. it looks like this definition doesn't exist for types that are non-integral. Look at the C++ reference for std::is_integral to see a full list of integral types.
w | integral-type word to insert into calculator |
Definition at line 65 of file CRC.h.
References crc.
|
private |
the object from Boost doing the summing
Definition at line 114 of file CRC.h.
Referenced by get(), and operator<<().