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 SD_TRACKER_TESTSTAND = 8,
22 EID_TRACKER = 16,
23 EID_TRIGGER_SCINT = 17,
24 EID_ECAL = 18,
25 EID_HCAL = 19
26} SubdetectorIDType;
27
37 public:
38 typedef uint32_t RawValue;
39
40 static const RawValue SUBDETECTORID_MASK{0x3F};
41 static const RawValue SUBDETECTORID_SHIFT{26};
42 static const RawValue SUBDETECTOR_PAYLOAD_MASK{0x3FFFFFF};
43
45 DetectorID() : id_{0} {}
46
48 DetectorID(RawValue rawid) : id_{rawid} {}
49
54 DetectorID(SubdetectorIDType sdtype, RawValue raw_subpayload) {
55 id_ = ((RawValue(sdtype) & DetectorID::SUBDETECTORID_MASK)
56 << DetectorID::SUBDETECTORID_SHIFT) |
57 (raw_subpayload & DetectorID::SUBDETECTOR_PAYLOAD_MASK);
58 }
59
61 bool null() const { return id_ == 0; }
62
64 SubdetectorIDType subdet() const {
65 return SubdetectorIDType((id_ >> SUBDETECTORID_SHIFT) & SUBDETECTORID_MASK);
66 }
67
69 RawValue raw() const { return id_; }
70
75 void setRawValue(RawValue rawValue) { id_ = rawValue; }
76
77 bool operator<(const DetectorID& id) const { return id_ < id.id_; }
78
79 bool operator==(const DetectorID& id) const { return id_ == id.id_; }
80
81 bool operator!=(const DetectorID& id) const { return id_ != id.id_; }
82
83 protected:
85 RawValue id_;
86};
87
88} // namespace ldmx
89
90#define SUBDETECTORID_TEST(a, x) \
91 if (!null() && !(subdet() == x)) { \
92 EXCEPTION_RAISE("DetectorIDMismatch", "Attempted to create " + \
93 std::string(a) + \
94 " from mismatched source " + \
95 std::to_string(subdet())); \
96 }
97#define SUBDETECTORID_TEST2(a, x, y) \
98 if (!null() && !(subdet() == x || subdet() == y)) { \
99 EXCEPTION_RAISE("DetectorIDMismatch", "Attempted to create " + \
100 std::string(a) + \
101 " from mismatched source " + \
102 std::to_string(subdet())); \
103 }
104#define SUBDETECTORID_TEST3(a, x, y, z) \
105 if (!null() && !(subdet() == x || subdet() == y || subdet() == z)) { \
106 EXCEPTION_RAISE("DetectorIDMismatch", "Attempted to create " + \
107 std::string(a) + \
108 " from mismatched source " + \
109 std::to_string(subdet())); \
110 }
111
112std::ostream& operator<<(std::ostream&, const ldmx::DetectorID&);
113
114#endif
Defines a 32-bit packed ID for uniquely identifying hits and detector components.
Definition DetectorID.h:36
void setRawValue(RawValue rawValue)
Set the raw value of the detector ID.
Definition DetectorID.h:75
bool null() const
Definition DetectorID.h:61
DetectorID(RawValue rawid)
Class constructor from a raw 32-bit integer.
Definition DetectorID.h:48
SubdetectorIDType subdet() const
Definition DetectorID.h:64
RawValue raw() const
Definition DetectorID.h:69
RawValue id_
The raw, packed value of the ID.
Definition DetectorID.h:85
DetectorID(SubdetectorIDType sdtype, RawValue raw_subpayload)
Class constructor from a subdetector id and a subdetector-specific section (masked to.
Definition DetectorID.h:54
DetectorID()
Class constructor for a null DetectorID.
Definition DetectorID.h:45