LDMX Software
CRC.h
1#ifndef PACKING_UTILITY_CRC_H_
2#define PACKING_UTILITY_CRC_H_
3
4#include <boost/crc.hpp>
5#include <span>
6#include <vector>
7
8namespace packing {
9namespace utility {
10
52class CRC {
53 public:
65 template <typename WordType,
66 std::enable_if_t<std::is_integral<WordType>::value, bool> = true>
67 CRC& operator<<(const WordType& w) {
68 crc_.process_bytes(&w, sizeof(WordType));
69 return *this;
70 }
71
86 template <typename ObjectType,
87 std::enable_if_t<std::is_class<ObjectType>::value, bool> = true>
88 CRC& operator<<(const ObjectType& o) {
89 return o.add(*this);
90 }
91
102 template <typename ContentType>
103 CRC& operator<<(const std::vector<ContentType>& vec) {
104 for (auto const& w : vec) *this << w;
105 return *this;
106 }
107
112 uint32_t get() { return crc_.checksum(); }
113
114 private:
116 boost::crc_32_type crc_;
117}; // CRC
118
125uint32_t crc32(std::span<const uint32_t> data);
126
134uint8_t econdCrc8(uint64_t data);
135
136} // namespace utility
137} // namespace packing
138
139#endif // PACKING_UTILITY_CRC_H_
The HGC ROC and FPGA use a CRC checksum to double check that the data transfer has been done correctl...
Definition CRC.h:52
CRC & operator<<(const WordType &w)
Stream an integral type into the calculator.
Definition CRC.h:67
boost::crc_32_type crc_
the object from Boost doing the summing
Definition CRC.h:116
uint32_t get()
Get the calculate checksum from the calculator.
Definition CRC.h:112
CRC & operator<<(const std::vector< ContentType > &vec)
Stream a vector of objects into the calculator.
Definition CRC.h:103
CRC & operator<<(const ObjectType &o)
Stream an instance of a class into the calculator.
Definition CRC.h:88