LDMX Software
DAQSampleHeader.cxx
1#include "Packing/DAQSampleHeader.h"
2
3#include "Packing/Utility/Mask.h"
4
5using packing::utility::MASK;
6
7namespace packing {
8
9void DAQSampleHeader::from(uint32_t word) {
10 version_ = ((word >> 28) & MASK<4>);
11 econd_id_ = ((word >> 18) & MASK<10>);
12 i_l1a_ = ((word >> 13) & MASK<5>);
13 is_soi_ = (((word >> 12) & MASK<1>) == 1);
14 econd_len_ = (word & MASK<12>);
15}
16
17uint32_t DAQSampleHeader::to() const {
18 return (((version_ & MASK<4>) << 28) | ((econd_id_ & MASK<10>) << 18) |
19 ((i_l1a_ & MASK<5>) << 13) | ((is_soi_ ? 1 : 0) << 12) |
20 (econd_len_ & MASK<12>));
21}
22
23bool DAQSampleHeader::isValid(uint32_t word) {
25 h.from(word);
26 return h.version_ == VERSION and not h.isEndingTrailer() and
27 ((word >> 9) & MASK<3>) == 0;
28}
29
31 return ((i_l1a_ == 0x1f) and (econd_id_ == 0x3ff));
32}
33
34uint32_t DAQSampleHeader::trailerNumSamples(uint32_t word) {
35 return (word & MASK<5>);
36}
37
38uint32_t DAQSampleHeader::endingTrailer(uint32_t n_samples) {
39 DAQSampleHeader h{.version_ = VERSION,
40 .econd_id_ = 0x3ff,
41 .i_l1a_ = 0x1f,
42 .is_soi_ = false,
43 .econd_len_ = 0};
44 return h.to() | (1u << 11) | (n_samples & MASK<5>);
45}
46
47std::ostream& operator<<(std::ostream& o, const DAQSampleHeader& h) {
48 return (o << "DAQSampleHeader { " << "version: " << h.version_ << ", "
49 << "econd_id: " << h.econd_id_ << ", " << "i_l1a: " << h.i_l1a_
50 << ", " << "is_soi: " << h.is_soi_ << ", "
51 << "econd_len: " << h.econd_len_ << " }");
52}
53
54} // namespace packing
The capture header that the DAQ firmware inserts before each ECON-D event packet (one per sample) and...
uint32_t version_
format version
bool is_soi_
is this the sample of interest?
bool isEndingTrailer() const
A special form of this DAQ header is used to signal the end of a multi-sample sequence.
uint32_t i_l1a_
index of this sample within the event
void from(uint32_t word)
decode a DAQSampleHeader from the input word
static uint32_t endingTrailer(uint32_t n_samples=0)
construct the special trailer form of this header
uint32_t econd_id_
configured ID of the ECON
static const uint32_t VERSION
expected format version
uint32_t to() const
construct a header word from our data
uint32_t econd_len_
length of the ECON-D packet following this header in 32b words
static bool isValid(uint32_t word)
check if the decoded word looks like a capture header
static uint32_t trailerNumSamples(uint32_t word)
number of samples written in the ending trailer