LDMX Software
LDMXRoRHeader.cxx
1#include "Packing/LDMXRoRHeader.h"
2
3#include <cassert>
4
5namespace packing {
6
7const std::unordered_map<std::string, int> LDMXRoRHeader::SUBSYSTEM_ID = {
8 {"tdaq", 1}, {"ts", 2}, {"tracker", 4}, {"ecal", 5}, {"hcal", 5}};
9
10const std::unordered_map<std::string, int> LDMXRoRHeader::CONTRIBUTOR_ID = {
11 {"tdaq", -1}, {"ts", 1}, {"tracker", -1}, {"ecal", 40}, {"hcal", 20}};
12
13std::tuple<int, int> LDMXRoRHeader::subsystem(const std::string& name) {
14 auto subsys_it{SUBSYSTEM_ID.find(name)};
15 if (subsys_it == SUBSYSTEM_ID.end()) {
16 return std::make_tuple(-1, -1);
17 }
18
19 int subsys{subsys_it->second}, contrib{-1};
20 auto contrib_it{CONTRIBUTOR_ID.find(name)};
21 if (contrib_it != CONTRIBUTOR_ID.end()) {
22 contrib = contrib_it->second;
23 }
24 return std::make_tuple(subsys, contrib);
25}
26
27std::string LDMXRoRHeader::getSubsystemName(uint8_t subsystem_id,
28 uint8_t contributor_id) {
29 // Check each subsystem's IDs to find a match
30 for (const auto& name_id_pair : SUBSYSTEM_ID) {
31 const auto& name = name_id_pair.first;
32 int subsys_id = name_id_pair.second;
33
34 if (subsys_id != subsystem_id) {
35 continue; // Not a match on subsystem ID
36 }
37
38 // Check if contributor ID matches (if it's set)
39 auto contrib_it = CONTRIBUTOR_ID.find(name);
40 if (contrib_it != CONTRIBUTOR_ID.end()) {
41 int expected_contrib = contrib_it->second;
42 if (expected_contrib != -1 && expected_contrib != contributor_id) {
43 continue; // Contributor ID doesn't match, try next
44 }
45 }
46
47 // Found a match
48 return name;
49 }
50
51 // No match found, return generic name
52 return "subsystem" + std::to_string(subsystem_id) + "c" +
53 std::to_string(contributor_id);
54}
55
57 valid_ = false;
58
59 uint8_t sentinel;
60 uint32_t zero;
61
62 if (!(r >> version_ >> subsystem_ >> contributor_ >> sentinel)) {
63 return r;
64 }
65
66 // sentinel should be 0xa5; if not, this is not a valid LDMX data frame
67 if (sentinel != 0xa5) return r;
68
69 if (!(r >> zero)) return r;
70
71 // next 32b should be zero since they are unused
72 if (zero != 0) return r;
73
74 if (!(r >> timestamp_)) return r;
75
76 valid_ = true;
77 return r;
78}
79
80} // namespace packing
uint64_t timestamp_
timestamp of this Readout-Request (RoR)
uint8_t subsystem() const
ID number for subsystem originating data (compiled into firmware)
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)
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