LDMX Software
DetectorID.h
1
2#ifndef DETDESCR_DETECTORID_H_
3#define DETDESCR_DETECTORID_H_
4
5#include <cstdint>
6#include <iostream>
7
8#include "Framework/Exception/Exception.h"
9
10namespace ldmx {
11
12typedef enum SubdetectorIDTypeEnum {
13 SD_NULL = 0,
14 SD_TRACKER_TAGGER = 1,
15 SD_TRIGGER_SCINT = 2,
16 SD_ACTVE_TARGET = 3,
17 SD_TRACKER_RECOIL = 4,
18 SD_ECAL = 5,
19 SD_HCAL = 6,
20 SD_SIM_SPECIAL = 7,
21 EID_TRACKER = 16,
22 EID_TRIGGER_SCINT = 17,
23 EID_ECAL = 18,
24 EID_HCAL = 19
25} SubdetectorIDType;
26
36 public:
37 typedef uint32_t RawValue;
38
39 static const RawValue SUBDETECTORID_MASK{0x3F};
40 static const RawValue SUBDETECTORID_SHIFT{26};
41 static const RawValue SUBDETECTOR_PAYLOAD_MASK{0x3FFFFFF};
42
44 DetectorID() : id_{0} {}
45
47 DetectorID(RawValue rawid) : id_{rawid} {}
48
53 DetectorID(SubdetectorIDType sdtype, RawValue raw_subpayload) {
54 id_ = ((RawValue(sdtype) & DetectorID::SUBDETECTORID_MASK)
55 << DetectorID::SUBDETECTORID_SHIFT) |
56 (raw_subpayload & DetectorID::SUBDETECTOR_PAYLOAD_MASK);
57 }
58
60 bool null() const { return id_ == 0; }
61
63 SubdetectorIDType subdet() const {
64 return SubdetectorIDType((id_ >> SUBDETECTORID_SHIFT) & SUBDETECTORID_MASK);
65 }
66
68 RawValue raw() const { return id_; }
69
74 void setRawValue(RawValue rawValue) { id_ = rawValue; }
75
76 bool operator<(const DetectorID& id) const { return id_ < id.id_; }
77
78 bool operator==(const DetectorID& id) const { return id_ == id.id_; }
79
80 bool operator!=(const DetectorID& id) const { return id_ != id.id_; }
81
82 protected:
84 RawValue id_;
85};
86
87} // namespace ldmx
88
89#define SUBDETECTORID_TEST(a, x) \
90 if (!null() && !(subdet() == x)) { \
91 EXCEPTION_RAISE("DetectorIDMismatch", "Attempted to create " + \
92 std::string(a) + \
93 " from mismatched source " + \
94 std::to_string(subdet())); \
95 }
96#define SUBDETECTORID_TEST2(a, x, y) \
97 if (!null() && !(subdet() == x || subdet() == y)) { \
98 EXCEPTION_RAISE("DetectorIDMismatch", "Attempted to create " + \
99 std::string(a) + \
100 " from mismatched source " + \
101 std::to_string(subdet())); \
102 }
103
104std::ostream& operator<<(std::ostream&, const ldmx::DetectorID&);
105
106#endif
Defines a 32-bit packed ID for uniquely identifying hits and detector components.
Definition DetectorID.h:35
void setRawValue(RawValue rawValue)
Set the raw value of the detector ID.
Definition DetectorID.h:74
bool null() const
Definition DetectorID.h:60
DetectorID(RawValue rawid)
Class constructor from a raw 32-bit integer.
Definition DetectorID.h:47
SubdetectorIDType subdet() const
Definition DetectorID.h:63
RawValue raw() const
Definition DetectorID.h:68
RawValue id_
The raw, packed value of the ID.
Definition DetectorID.h:84
DetectorID(SubdetectorIDType sdtype, RawValue raw_subpayload)
Class constructor from a subdetector id and a subdetector-specific section (masked to.
Definition DetectorID.h:53
DetectorID()
Class constructor for a null DetectorID.
Definition DetectorID.h:44