LDMX Software
LDMXRoRHeader.cxx
1#include "Packing/LDMXRoRHeader.h"
2
3#include <cassert>
4#include <map>
5#include <utility>
6
7namespace packing {
8
9const std::unordered_map<std::string, int> LDMXRoRHeader::SUBSYSTEM_ID = {
10 {"tdaq", 1}, {"ts", 2}, {"tracker", 4}, {"ecal", 5}, {"hcal", 5}};
11
12const std::unordered_map<std::string, int> LDMXRoRHeader::CONTRIBUTOR_ID = {
13 {"tdaq", -1}, {"ts", 1}, {"tracker", -1}, {"ecal", 40}, {"hcal", 20}};
14
15std::tuple<int, int> LDMXRoRHeader::subsystem(const std::string& name) {
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}
28
29std::string LDMXRoRHeader::getSubsystemName(uint8_t subsystem_id,
30 uint8_t contributor_id) {
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}
63
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}
86
87} // namespace packing
uint64_t timestamp_
timestamp of this Readout-Request (RoR)
uint8_t subsystem() const
ID number for subsystem originating data (compiled into firmware)
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()
static std::string getSubsystemName(uint8_t subsystem_id, uint8_t contributor_id)
Get the subsystem name from subsystem and contributor IDs.
uint8_t contributor_
ID number for contributor within subsystem (configured into firmware)
uint32_t flags_
formatter flags, see flags()
static const std::unordered_map< std::string, int > SUBSYSTEM_ID
The subsystem ID numbers organized by subsystem name.
uint8_t version_
version of LDMX data (should be zero)
utility::Reader & read(utility::Reader &r)
read the next LDMX RoR header into memory
uint8_t subsystem_
ID number for subsystem originating data (compiled into firmware)
static const std::unordered_map< std::string, int > CONTRIBUTOR_ID
The contributor ID is a configurable parameter of the DAQ firmware.
Reading a raw data file.
Definition Reader.h:20