LDMX Software
SubsystemPacket.cxx
1
2#include "Packing/RawDataFile/SubsystemPacket.h"
3
4#include "Packing/Utility/Mask.h"
5
6namespace packing {
7namespace rawdatafile {
8
9SubsystemPacket::SubsystemPacket(uint32_t event, uint16_t id,
10 std::vector<uint32_t> data)
11 : event_{event}, id_{id}, data_{data} {
12 crc_ok_ = true;
13
14 utility::CRC crc;
15 crc << data_;
16
17 crc_ = crc.get();
18}
19
20std::vector<uint32_t> SubsystemPacket::header() const {
21 uint32_t word = ((id_ & utility::mask<16>) << 16) +
22 ((data_.size() & utility::mask<15>) << 1) + crc_ok_;
23 return {word, event_};
24}
25
26std::vector<uint32_t> SubsystemPacket::tail() const { return {crc_}; }
27
29 uint32_t word;
30 r >> word;
31
32 id_ = (word >> 16) & utility::mask<16>;
33 uint32_t len = (word >> 1) & utility::mask<15>;
34 crc_ok_ = word & utility::mask<1>;
35
36 r >> event_;
37
38 r.read(data_, len);
39
40 r >> crc_;
41
42 return r;
43}
44
46 std::vector<uint32_t> head{header()}, t{tail()};
47 w << head << data_ << t;
48 return w;
49}
50
52 std::vector<uint32_t> head{header()}, t{tail()};
53 c << head << data_ << t;
54 return c;
55}
56
57} // namespace rawdatafile
58} // namespace packing
utility::CRC & add(utility::CRC &c) const
add the subsystem packet to the input crc
std::vector< uint32_t > tail() const
get the tailing words
utility::Reader & read(utility::Reader &r)
read the subsystem packet from the input reader
std::vector< uint32_t > header() const
get the header words
SubsystemPacket()=default
default constructor for reading
utility::Writer & write(utility::Writer &w) const
write the subsystem packet to the input writer
The HGC ROC and FPGA use a CRC checksum to double check that the data transfer has been done correctl...
Definition CRC.h:50
uint32_t get()
Get the calculate checksum from the calculator.
Definition CRC.h:110
Reading a raw data file.
Definition Reader.h:19
Reader & read(WordType *w, std::size_t count)
Read the next 'count' words into the input handle.
Definition Reader.h:113
Writing a raw data file.
Definition Writer.h:19