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 kDetOffset = 28;
21  static const int kSubdetOffset = 25;
22 
23 
24  enum Detector {Tracker=1, Muon=2, Ecal=3, Hcal=4, Calo=5, Forward=6,
27  DetId() : id_(0) { }
29  DetId(uint32_t id) : id_(id) { }
31  DetId(Detector det, int subdet) {
32  id_=((det&0xF)<<28)|((subdet&0x7)<<25);
33  }
34 
36  Detector det() const { return Detector((id_>>kDetOffset)&0xF); }
38  int subdetId() const { return ((id_>>kSubdetOffset)&0x7); }
39 
40  uint32_t operator()() const { return id_; }
41  operator uint32_t() const { return id_; }
42 
44  uint32_t rawId() const { return id_; }
46  bool null() const { return id_==0; }
47 
49  bool operator==(DetId id) const { return id_==id.id_; }
51  bool operator!=(DetId id) const { return id_!=id.id_; }
53  bool operator<(DetId id) const { return id_<id.id_; }
54 
55 protected:
56  uint32_t id_;
57 };
58 
60 inline bool operator==(uint32_t i, DetId id) { return i==id(); }
61 inline bool operator==(DetId id, uint32_t i) { return i==id(); }
63 inline bool operator!=(uint32_t i, DetId id) { return i!=id(); }
64 inline bool operator!=(DetId id, uint32_t i) { return i!=id(); }
66 inline bool operator<(uint32_t i, DetId id) { return i<id(); }
67 inline bool operator<(DetId id, uint32_t i) { return id()<i; }
68 
69 
70 //std::ostream& operator<<(std::ostream& s, const DetId& id);
71 
72 namespace std {
73  template<> struct hash<DetId> {
75  typedef std::size_t result_type;
76  result_type operator()(argument_type const& id) const noexcept {
77  return std::hash<uint32_t>()(id.rawId());
78  }
79  };
80 }
81 
82 #endif
std::size_t result_type
Definition: DetId.h:75
#define noexcept
static const int kSubdetOffset
Definition: DetId.h:21
DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:27
DetId(uint32_t id)
Create an id from a raw number.
Definition: DetId.h:29
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
Definition: Muon.py:1
bool operator==(DetId id) const
equality
Definition: DetId.h:49
bool operator!=(DetId id) const
inequality
Definition: DetId.h:51
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
Definition: DetId.h:18
result_type operator()(argument_type const &id) const noexcept
Definition: DetId.h:76
Detector
Definition: DetId.h:24
uint32_t id_
Definition: DetId.h:56
bool null() const
is this a null id ?
Definition: DetId.h:46
bool operator<(DetId id) const
comparison
Definition: DetId.h:53
static const int kDetOffset
Definition: DetId.h:20
DetId(Detector det, int subdet)
Create an id, filling the detector and subdetector fields as specified.
Definition: DetId.h:31
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
DetId argument_type
Definition: DetId.h:74
uint32_t operator()() const
Definition: DetId.h:40