LDMX Software
EventPacket.cxx
1
2#include "Packing/RawDataFile/EventPacket.h"
3
4#include "Packing/Utility/Mask.h"
5
6namespace packing {
7namespace rawdatafile {
8
10 uint32_t id,
11 const std::map<uint16_t, std::vector<uint32_t>>& unwrapped_subsys_data)
12 : id_{id}, event_length_in_words_{0} {
13 crc_ok_ = true;
14
15 utility::CRC crc;
16
17 for (auto const& [subsys_id, subsys_data] : unwrapped_subsys_data) {
18 subsys_data_.emplace_back(id_, subsys_id, subsys_data);
19 auto& subsys = subsys_data_.back();
20 crc << subsys;
21 event_length_in_words_ +=
22 subsys.header().size() + subsys.data().size() + subsys.tail().size();
23 }
24
25 crc_ = crc.get();
26}
27
28std::vector<uint32_t> EventPacket::header() const {
29 uint32_t word = ((subsys_data_.size() & utility::mask<16>) << 16) +
30 ((event_length_in_words_ & utility::mask<15>) << 1) + crc_ok_;
31 return {id_, word};
32}
33
34std::vector<uint32_t> EventPacket::tail() const { return {crc_}; }
35
37 r >> id_;
38
39 uint32_t word;
40 r >> word;
41
42 uint16_t num_subsys = (word >> 16) & utility::mask<16>;
43 event_length_in_words_ = (word >> 1) & utility::mask<15>;
44 crc_ok_ = word & utility::mask<1>;
45
46 r.read(subsys_data_, num_subsys);
47
48 r >> crc_;
49
50 return r;
51}
52
54 std::vector<uint32_t> h{header()}, t{tail()};
55 w << h << subsys_data_ << t;
56 return w;
57}
58
60 std::vector<uint32_t> h{header()}, t{tail()};
61 c << h << subsys_data_ << t;
62 return c;
63}
64
65} // namespace rawdatafile
66} // namespace packing
EventPacket()=default
default constructor for reading
std::vector< uint32_t > header() const
Get the header words.
utility::CRC & add(utility::CRC &c) const
add the event packet to the input crc
std::vector< uint32_t > tail() const
Get the tail words.
utility::Reader & read(utility::Reader &r)
read the event packet from the input reader
utility::Writer & write(utility::Writer &w) const
write the event 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