CMS 3D CMS Logo

DetId.h
Go to the documentation of this file.
1 #ifndef DATAFORMATS_DETID_H
2 #define DATAFORMATS_DETID_H
3 
4 
5 //FIXME shall be removed and implemented where the operator is defined
6 #include <ostream>
7 
8 #include <cstdint>
18 class DetId {
19 public:
20  static const int kDetMask = 0xF;
21  static const int kSubdetMask = 0x7;
22  static const int kDetOffset = 28;
23  static const int kSubdetOffset = 25;
24 
25 
26  enum Detector {Tracker=1, Muon=2, Ecal=3, Hcal=4, Calo=5, Forward=6,
30  constexpr DetId() : id_(0) { }
32  constexpr DetId(uint32_t id) : id_(id) { }
34  constexpr DetId(Detector det, int subdet)
35  : id_(((det&kDetMask)<<kDetOffset)|((subdet&kSubdetMask)<<kSubdetOffset))
36  {}
37 
39  constexpr Detector det() const { return Detector((id_>>kDetOffset)&kDetMask); }
41  constexpr int subdetId() const {
42  return ((HGCalEE==det()) || (HGCalHSi==det()) || (HGCalHSc==det()) ?
43  0 : ((id_>>kSubdetOffset)&kSubdetMask));
44  }
45 
46  constexpr uint32_t operator()() const { return id_; }
47  constexpr operator uint32_t() const { return id_; }
48 
50  constexpr uint32_t rawId() const { return id_; }
52  constexpr bool null() const { return id_==0; }
53 
55  constexpr bool operator==(DetId id) const { return id_==id.id_; }
57  constexpr bool operator!=(DetId id) const { return id_!=id.id_; }
59  constexpr bool operator<(DetId id) const { return id_<id.id_; }
60 
61 protected:
62  uint32_t id_;
63 };
64 
66 constexpr inline bool operator==(uint32_t i, DetId id) { return i==id(); }
67 constexpr inline bool operator==(DetId id, uint32_t i) { return i==id(); }
69 constexpr inline bool operator!=(uint32_t i, DetId id) { return i!=id(); }
70 constexpr inline bool operator!=(DetId id, uint32_t i) { return i!=id(); }
72 constexpr inline bool operator<(uint32_t i, DetId id) { return i<id(); }
73 constexpr inline bool operator<(DetId id, uint32_t i) { return id()<i; }
74 
75 
76 //std::ostream& operator<<(std::ostream& s, const DetId& id);
77 
78 namespace std {
79  template<> struct hash<DetId> {
81  typedef std::size_t result_type;
82  result_type operator()(argument_type const& id) const noexcept {
83  return std::hash<uint32_t>()(id.rawId());
84  }
85  };
86 }
87 
88 #endif
constexpr bool operator==(DetId id) const
equality
Definition: DetId.h:55
constexpr bool null() const
is this a null id ?
Definition: DetId.h:52
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::size_t result_type
Definition: DetId.h:81
constexpr bool operator<(DetId id) const
comparison
Definition: DetId.h:59
static const int kSubdetOffset
Definition: DetId.h:23
Definition: Muon.py:1
static const int kSubdetMask
Definition: DetId.h:21
constexpr DetId(Detector det, int subdet)
Create an id, filling the detector and subdetector fields as specified.
Definition: DetId.h:34
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
constexpr bool operator!=(DetId id) const
inequality
Definition: DetId.h:57
constexpr uint32_t operator()() const
Definition: DetId.h:46
#define noexcept
Definition: DetId.h:18
result_type operator()(argument_type const &id) const noexcept
Definition: DetId.h:82
constexpr DetId(uint32_t id)
Create an id from a raw number.
Definition: DetId.h:32
Detector
Definition: DetId.h:26
static const int kDetMask
Definition: DetId.h:20
uint32_t id_
Definition: DetId.h:62
static const int kDetOffset
Definition: DetId.h:22
DetId argument_type
Definition: DetId.h:80
#define constexpr
constexpr DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:30
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39