LDMX Software
packing::LDMXRoRHeader Class Reference

the header that the LDMX DAQ Firmware block includes in the output data stream at the beginning of each data frame More...

#include <LDMXRoRHeader.h>

Public Member Functions

utility::Reader & read (utility::Reader &r)
 read the next LDMX RoR header into memory
 
bool valid () const
 true if the header was parsed successfully (sentinel matched and the unused flag bits are zero)
 
uint32_t flags () const
 flags set by the DAQ event formatter
 
bool dataDropped () const
 true if the formatter dropped this fragment's data (header only)
 
uint8_t lostBefore () const
 number of readout requests lost before this one, saturates at 255
 
uint8_t version () const
 version of LDMX data (should be zero)
 
uint8_t subsystem () const
 ID number for subsystem originating data (compiled into firmware)
 
uint8_t contributor () const
 ID number for contributor within subsystem (configured into firmware)
 
uint64_t timestamp () const
 get timestamp of this RoR
 

Static Public Member Functions

static std::tuple< int, int > subsystem (const std::string &name)
 Get the (subsystem, contributor) pair for the input subsystem name.
 
static std::string getSubsystemName (uint8_t subsystem_id, uint8_t contributor_id)
 Get the subsystem name from subsystem and contributor IDs.
 

Static Public Attributes

static const unsigned int SIZE = 16
 size of this header in bytes
 
static const std::unordered_map< std::string, int > SUBSYSTEM_ID
 The subsystem ID numbers organized by subsystem name.
 
static const std::unordered_map< std::string, int > CONTRIBUTOR_ID
 The contributor ID is a configurable parameter of the DAQ firmware.
 
static constexpr uint32_t FLAG_DATA_DROPPED {0x1}
 header-only fragment, see flags()
 

Private Attributes

bool valid_ {false}
 set to true only when all validity checks pass during read()
 
uint8_t version_
 version of LDMX data (should be zero)
 
uint8_t subsystem_
 ID number for subsystem originating data (compiled into firmware)
 
uint8_t contributor_
 ID number for contributor within subsystem (configured into firmware)
 
uint32_t flags_ {0}
 formatter flags, see flags()
 
uint64_t timestamp_
 timestamp of this Readout-Request (RoR)
 

Static Private Attributes

static constexpr uint32_t FLAG_MASK {0xff07}
 flag bits in use, the others must be zero
 

Detailed Description

the header that the LDMX DAQ Firmware block includes in the output data stream at the beginning of each data frame

This header is immediately preceeded by a RogueFrameHeader for data frames. It is separate only becuase some frames written to the file (mainly, the configuration stream) do not include this header as well as the RogueFrameHeader.

Definition at line 21 of file LDMXRoRHeader.h.

Member Function Documentation

◆ contributor()

uint8_t packing::LDMXRoRHeader::contributor ( ) const
inline

ID number for contributor within subsystem (configured into firmware)

Definition at line 108 of file LDMXRoRHeader.h.

108{ return contributor_; }
uint8_t contributor_
ID number for contributor within subsystem (configured into firmware)

References contributor_.

Referenced by eventbuilder::EventBuilder::produce().

◆ dataDropped()

bool packing::LDMXRoRHeader::dataDropped ( ) const
inline

true if the formatter dropped this fragment's data (header only)

Definition at line 100 of file LDMXRoRHeader.h.

100{ return flags_ & FLAG_DATA_DROPPED; }
static constexpr uint32_t FLAG_DATA_DROPPED
header-only fragment, see flags()
uint32_t flags_
formatter flags, see flags()

References FLAG_DATA_DROPPED, and flags_.

◆ flags()

uint32_t packing::LDMXRoRHeader::flags ( ) const
inline

flags set by the DAQ event formatter

bit 0: data dropped (busy), header-only fragment bit 1: raw data buffer overflow bit 2: bookkeeping error bits 8-15: readout requests lost before this one (no fragment at all), saturates at 255

Definition at line 96 of file LDMXRoRHeader.h.

96{ return flags_; }

References flags_.

Referenced by eventbuilder::EventBuilder::produce().

◆ getSubsystemName()

std::string packing::LDMXRoRHeader::getSubsystemName ( uint8_t subsystem_id,
uint8_t contributor_id )
static

Get the subsystem name from subsystem and contributor IDs.

Uses both the subsystem ID (compiled into firmware) and contributor ID (configured into firmware) to uniquely identify the subsystem. This is necessary because some subsystems share the same subsystem ID but have different contributor IDs (e.g., ecal and hcal both use subsystem ID 5 but have different contributor IDs at ESA25). The ESA26 HCal (subsystem 7, contributor 20) is named hcal as well.

Parameters
[in]subsystem_idthe subsystem ID from the RoR header
[in]contributor_idthe contributor ID from the RoR header
Returns
subsystem name string (lowercase: 'tdaq', 'ts', 'tracker', 'ecal', 'hcal') or a generic name if the combination is not recognized

Definition at line 29 of file LDMXRoRHeader.cxx.

30 {
31 // Check each subsystem's IDs to find a match
32 for (const auto& name_id_pair : SUBSYSTEM_ID) {
33 const auto& name = name_id_pair.first;
34 int subsys_id = name_id_pair.second;
35
36 if (subsys_id != subsystem_id) {
37 continue; // Not a match on subsystem ID
38 }
39
40 // Check if contributor ID matches (if it's set)
41 auto contrib_it = CONTRIBUTOR_ID.find(name);
42 if (contrib_it != CONTRIBUTOR_ID.end()) {
43 int expected_contrib = contrib_it->second;
44 if (expected_contrib != -1 && expected_contrib != contributor_id) {
45 continue; // Contributor ID doesn't match, try next
46 }
47 }
48
49 // Found a match
50 return name;
51 }
52
53 // IDs that changed between test beams, the maps above hold the ESA25 ones
54 static const std::map<std::pair<int, int>, std::string> other_ids = {
55 {{7, 20}, "hcal"}}; // ESA26 HCal backplane
56 auto other_it{other_ids.find({subsystem_id, contributor_id})};
57 if (other_it != other_ids.end()) return other_it->second;
58
59 // No match found, return generic name
60 return "subsystem" + std::to_string(subsystem_id) + "c" +
61 std::to_string(contributor_id);
62}
static const std::unordered_map< std::string, int > SUBSYSTEM_ID
The subsystem ID numbers organized by subsystem name.
static const std::unordered_map< std::string, int > CONTRIBUTOR_ID
The contributor ID is a configurable parameter of the DAQ firmware.

References CONTRIBUTOR_ID, and SUBSYSTEM_ID.

Referenced by eventbuilder::EventBuilder::produce().

◆ lostBefore()

uint8_t packing::LDMXRoRHeader::lostBefore ( ) const
inline

number of readout requests lost before this one, saturates at 255

Definition at line 102 of file LDMXRoRHeader.h.

102{ return (flags_ >> 8) & 0xff; }

References flags_.

◆ read()

utility::Reader & packing::LDMXRoRHeader::read ( utility::Reader & r)

read the next LDMX RoR header into memory

Definition at line 64 of file LDMXRoRHeader.cxx.

64 {
65 valid_ = false;
66
67 uint8_t sentinel;
68
69 if (!(r >> version_ >> subsystem_ >> contributor_ >> sentinel)) {
70 return r;
71 }
72
73 // sentinel should be 0xa5; if not, this is not a valid LDMX data frame
74 if (sentinel != 0xa5) return r;
75
76 if (!(r >> flags_)) return r;
77
78 // only the low flag bits are used, the rest should be zero
79 if ((flags_ & ~FLAG_MASK) != 0) return r;
80
81 if (!(r >> timestamp_)) return r;
82
83 valid_ = true;
84 return r;
85}
uint64_t timestamp_
timestamp of this Readout-Request (RoR)
static constexpr uint32_t FLAG_MASK
flag bits in use, the others must be zero
bool valid_
set to true only when all validity checks pass during read()
uint8_t version_
version of LDMX data (should be zero)
uint8_t subsystem_
ID number for subsystem originating data (compiled into firmware)

References contributor_, FLAG_MASK, flags_, subsystem_, timestamp_, valid_, and version_.

Referenced by eventbuilder::EventBuilder::produce().

◆ subsystem() [1/2]

uint8_t packing::LDMXRoRHeader::subsystem ( ) const
inline

ID number for subsystem originating data (compiled into firmware)

Definition at line 106 of file LDMXRoRHeader.h.

106{ return subsystem_; }

References subsystem_.

Referenced by packing::SingleSubsystemUnpacker::configure().

◆ subsystem() [2/2]

std::tuple< int, int > packing::LDMXRoRHeader::subsystem ( const std::string & name)
static

Get the (subsystem, contributor) pair for the input subsystem name.

Note
For the 2025 slice test at SLAC, there was only ever one contributor per subsystem (-1 means that it was not set and can be ignored). In the future, there will be more than one contributor for some subsystems and so this function will need to be rewritten.
Parameters
[in]namesubsystem name ('tdaq','ts','tracker','hcal','ecal')
Returns
2-tuple of subsystem, contributor ID numbers. Returns the pair (-1, -1) if the name is not found in our maps above.

Definition at line 15 of file LDMXRoRHeader.cxx.

15 {
16 auto subsys_it{SUBSYSTEM_ID.find(name)};
17 if (subsys_it == SUBSYSTEM_ID.end()) {
18 return std::make_tuple(-1, -1);
19 }
20
21 int subsys{subsys_it->second}, contrib{-1};
22 auto contrib_it{CONTRIBUTOR_ID.find(name)};
23 if (contrib_it != CONTRIBUTOR_ID.end()) {
24 contrib = contrib_it->second;
25 }
26 return std::make_tuple(subsys, contrib);
27}

References CONTRIBUTOR_ID, and SUBSYSTEM_ID.

Referenced by eventbuilder::EventBuilder::produce().

◆ timestamp()

uint64_t packing::LDMXRoRHeader::timestamp ( ) const
inline

get timestamp of this RoR

Definition at line 110 of file LDMXRoRHeader.h.

110{ return timestamp_; }

References timestamp_.

Referenced by eventbuilder::EventBuilder::produce(), and packing::SingleSubsystemUnpacker::produce().

◆ valid()

bool packing::LDMXRoRHeader::valid ( ) const
inline

true if the header was parsed successfully (sentinel matched and the unused flag bits are zero)

Definition at line 86 of file LDMXRoRHeader.h.

86{ return valid_; }

References valid_.

Referenced by eventbuilder::EventBuilder::produce().

◆ version()

uint8_t packing::LDMXRoRHeader::version ( ) const
inline

version of LDMX data (should be zero)

Definition at line 104 of file LDMXRoRHeader.h.

104{ return version_; }

References version_.

Member Data Documentation

◆ contributor_

uint8_t packing::LDMXRoRHeader::contributor_
private

ID number for contributor within subsystem (configured into firmware)

Definition at line 120 of file LDMXRoRHeader.h.

Referenced by contributor(), and read().

◆ CONTRIBUTOR_ID

const std::unordered_map< std::string, int > packing::LDMXRoRHeader::CONTRIBUTOR_ID
static
Initial value:
= {
{"tdaq", -1}, {"ts", 1}, {"tracker", -1}, {"ecal", 40}, {"hcal", 20}}

The contributor ID is a configurable parameter of the DAQ firmware.

For the 2025 slice test at SLAC, there was only ever one contributor per subsystem and so there is just one integer per subsystem here. (-1 means that it was not set and can be ignored).

In the future, there will be more than one contributor for some subsystems.

The subsystem names are all lower case.

Definition at line 48 of file LDMXRoRHeader.h.

Referenced by getSubsystemName(), and subsystem().

◆ FLAG_DATA_DROPPED

uint32_t packing::LDMXRoRHeader::FLAG_DATA_DROPPED {0x1}
staticconstexpr

header-only fragment, see flags()

Definition at line 98 of file LDMXRoRHeader.h.

98{0x1};

Referenced by dataDropped(), and eventbuilder::EventBuilder::produce().

◆ FLAG_MASK

uint32_t packing::LDMXRoRHeader::FLAG_MASK {0xff07}
staticconstexprprivate

flag bits in use, the others must be zero

Definition at line 124 of file LDMXRoRHeader.h.

124{0xff07};

Referenced by read().

◆ flags_

uint32_t packing::LDMXRoRHeader::flags_ {0}
private

formatter flags, see flags()

Definition at line 122 of file LDMXRoRHeader.h.

122{0};

Referenced by dataDropped(), flags(), lostBefore(), and read().

◆ SIZE

const unsigned int packing::LDMXRoRHeader::SIZE = 16
static

size of this header in bytes

Definition at line 24 of file LDMXRoRHeader.h.

Referenced by packing::SingleSubsystemUnpacker::produce().

◆ subsystem_

uint8_t packing::LDMXRoRHeader::subsystem_
private

ID number for subsystem originating data (compiled into firmware)

Definition at line 118 of file LDMXRoRHeader.h.

Referenced by read(), and subsystem().

◆ SUBSYSTEM_ID

const std::unordered_map< std::string, int > packing::LDMXRoRHeader::SUBSYSTEM_ID
static
Initial value:
= {
{"tdaq", 1}, {"ts", 2}, {"tracker", 4}, {"ecal", 5}, {"hcal", 5}}

The subsystem ID numbers organized by subsystem name.

These ID numbers are compiled into the DAQ firmware. Since the same firmware was used for both the ECal and HCal, they both ended up having the same subsystem ID (5).

The subsystem names are all lower case.

Definition at line 34 of file LDMXRoRHeader.h.

Referenced by getSubsystemName(), and subsystem().

◆ timestamp_

uint64_t packing::LDMXRoRHeader::timestamp_
private

timestamp of this Readout-Request (RoR)

It is some combination of pulseID and bunchCount, but I'm unsure on how to decompose those at this time.

Definition at line 132 of file LDMXRoRHeader.h.

Referenced by read(), and timestamp().

◆ valid_

bool packing::LDMXRoRHeader::valid_ {false}
private

set to true only when all validity checks pass during read()

Definition at line 114 of file LDMXRoRHeader.h.

114{false};

Referenced by read(), and valid().

◆ version_

uint8_t packing::LDMXRoRHeader::version_
private

version of LDMX data (should be zero)

Definition at line 116 of file LDMXRoRHeader.h.

Referenced by read(), and version().


The documentation for this class was generated from the following files: