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 { return ((id_>>kSubdetOffset)&kSubdetMask); }
42 
43  constexpr uint32_t operator()() const { return id_; }
44  constexpr operator uint32_t() const { return id_; }
45 
47  constexpr uint32_t rawId() const { return id_; }
49  constexpr bool null() const { return id_==0; }
50 
52  constexpr bool operator==(DetId id) const { return id_==id.id_; }
54  constexpr bool operator!=(DetId id) const { return id_!=id.id_; }
56  constexpr bool operator<(DetId id) const { return id_<id.id_; }
57 
58 protected:
59  uint32_t id_;
60 };
61 
63 constexpr inline bool operator==(uint32_t i, DetId id) { return i==id(); }
64 constexpr inline bool operator==(DetId id, uint32_t i) { return i==id(); }
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 id()<i; }
71 
72 
73 //std::ostream& operator<<(std::ostream& s, const DetId& id);
74 
75 namespace std {
76  template<> struct hash<DetId> {
78  typedef std::size_t result_type;
79  result_type operator()(argument_type const& id) const noexcept {
80  return std::hash<uint32_t>()(id.rawId());
81  }
82  };
83 }
84 
85 #endif
constexpr bool operator==(DetId id) const
equality
Definition: DetId.h:52
constexpr bool null() const
is this a null id ?
Definition: DetId.h:49
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
std::size_t result_type
Definition: DetId.h:78
#define noexcept
constexpr bool operator<(DetId id) const
comparison
Definition: DetId.h:56
static const int kSubdetOffset
Definition: DetId.h:23
#define constexpr
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:54
constexpr uint32_t operator()() const
Definition: DetId.h:43
Definition: DetId.h:18
result_type operator()(argument_type const &id) const noexcept
Definition: DetId.h:79
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:59
static const int kDetOffset
Definition: DetId.h:22
DetId argument_type
Definition: DetId.h:77
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