CMS 3D CMS Logo

CTPPSDetId.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of TOTEM offline software.
4  * Authors:
5  * Jan Kašpar (jan.kaspar@gmail.com)
6  *
7  ****************************************************************************/
8 
9 #ifndef DataFormats_CTPPSDetId_CTPPSDetId
10 #define DataFormats_CTPPSDetId_CTPPSDetId
11 
13 
15 
16 #include <iosfwd>
17 #include <iostream>
18 #include <string>
19 
32 class CTPPSDetId : public DetId {
33 public:
35  enum SubDetector {
41  };
42 
44  explicit CTPPSDetId(uint32_t id);
45 
47  CTPPSDetId(uint32_t SubDet, uint32_t Arm, uint32_t Station, uint32_t RomanPot = 0);
48 
49  //-------------------- bit assignment --------------------
50 
51  static const uint32_t startArmBit, maskArm, maxArm, lowMaskArm;
53  static const uint32_t startRPBit, maskRP, maxRP, lowMaskRP;
54 
55  //-------------------- component getters and setters --------------------
56 
57  uint32_t arm() const { return ((id_ >> startArmBit) & maskArm); }
58 
59  void setArm(uint32_t arm) {
60  id_ &= ~(maskArm << startArmBit);
61  id_ |= ((arm & maskArm) << startArmBit);
62  }
63 
64  uint32_t station() const { return ((id_ >> startStationBit) & maskStation); }
65 
66  void setStation(uint32_t station) {
69  }
70 
71  uint32_t rp() const { return ((id_ >> startRPBit) & maskRP); }
72 
73  void setRP(uint32_t rp) {
74  id_ &= ~(maskRP << startRPBit);
75  id_ |= ((rp & maskRP) << startRPBit);
76  }
77 
78  //-------------------- id getters for higher-level objects --------------------
79 
80  CTPPSDetId armId() const { return CTPPSDetId(rawId() & (~lowMaskArm)); }
81 
82  CTPPSDetId stationId() const { return CTPPSDetId(rawId() & (~lowMaskStation)); }
83 
84  CTPPSDetId rpId() const { return CTPPSDetId(rawId() & (~lowMaskRP)); }
85 
86  //-------------------- name methods --------------------
87 
89  enum NameFlag { nShort, nFull, nPath };
90 
92  if (flag == nPath)
94  else
96  }
97 
98  inline void armName(std::string &name, NameFlag flag = nFull) const {
99  switch (flag) {
100  case nShort:
101  name = "";
102  break;
103  case nFull:
105  name += "_";
106  break;
107  case nPath:
109  name += "/sector ";
110  break;
111  }
112 
113  name += armNames[arm()];
114  }
115 
116  inline void stationName(std::string &name, NameFlag flag = nFull) const {
117  switch (flag) {
118  case nShort:
119  name = "";
120  break;
121  case nFull:
122  armName(name, flag);
123  name += "_";
124  break;
125  case nPath:
126  armName(name, flag);
127  name += "/station ";
128  break;
129  }
130 
131  name += stationNames[station()];
132  }
133 
134  inline void rpName(std::string &name, NameFlag flag = nFull) const {
135  switch (flag) {
136  case nShort:
137  name = "";
138  break;
139  case nFull:
141  name += "_";
142  break;
143  case nPath:
145  name += "/";
146  break;
147  }
148 
149  name += rpNames[rp()];
150  }
151 
152 private:
155  static const std::string armNames[];
156  static const std::string stationNames[];
157  static const std::string rpNames[];
158 };
159 
160 std::ostream &operator<<(std::ostream &os, const CTPPSDetId &id);
161 
162 namespace std {
163  template <>
164  struct hash<CTPPSDetId> {
166  typedef std::size_t result_type;
167  result_type operator()(const argument_type &id) const noexcept { return std::hash<uint64_t>()(id.rawId()); }
168  };
169 } // namespace std
170 
171 #endif
CTPPSDetId argument_type
Definition: CTPPSDetId.h:165
SubDetector
CTPPS sub-detectors.
Definition: CTPPSDetId.h:35
static const uint32_t maxStation
Definition: CTPPSDetId.h:52
std::size_t result_type
Definition: CTPPSDetId.h:166
uint32_t arm() const
Definition: CTPPSDetId.h:57
NameFlag
type of name returned by *Name functions
Definition: CTPPSDetId.h:89
void setArm(uint32_t arm)
Definition: CTPPSDetId.h:59
void setRP(uint32_t rp)
Definition: CTPPSDetId.h:73
static const uint32_t startRPBit
Definition: CTPPSDetId.h:53
static const uint32_t maskStation
Definition: CTPPSDetId.h:52
static const uint32_t maskRP
Definition: CTPPSDetId.h:53
CTPPSDetId stationId() const
Definition: CTPPSDetId.h:82
static const std::string armNames[]
Definition: CTPPSDetId.h:155
static const uint32_t lowMaskStation
Definition: CTPPSDetId.h:52
static const uint32_t maskArm
Definition: CTPPSDetId.h:51
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:134
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:84
static const uint32_t maxArm
Definition: CTPPSDetId.h:51
void armName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:98
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static const std::string subDetectorPaths[]
Definition: CTPPSDetId.h:154
static const uint32_t maxRP
Definition: CTPPSDetId.h:53
static const std::string rpNames[]
Definition: CTPPSDetId.h:157
void setStation(uint32_t station)
Definition: CTPPSDetId.h:66
static const std::string subDetectorNames[]
Definition: CTPPSDetId.h:153
Definition: DetId.h:17
uint32_t rp() const
Definition: CTPPSDetId.h:71
CTPPSDetId armId() const
Definition: CTPPSDetId.h:80
std::ostream & operator<<(std::ostream &os, const CTPPSDetId &id)
Definition: CTPPSDetId.cc:76
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
uint32_t id_
Definition: DetId.h:69
uint32_t station() const
Definition: CTPPSDetId.h:64
static const uint32_t startStationBit
Definition: CTPPSDetId.h:52
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
CTPPSDetId(uint32_t id)
Construct from a raw id.
Definition: CTPPSDetId.cc:41
result_type operator()(const argument_type &id) const noexcept
Definition: CTPPSDetId.h:167
void stationName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:116
static const uint32_t startArmBit
Definition: CTPPSDetId.h:51
static const std::string stationNames[]
Definition: CTPPSDetId.h:156
static const uint32_t lowMaskArm
Definition: CTPPSDetId.h:51
void subDetectorName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:91
static const uint32_t lowMaskRP
Definition: CTPPSDetId.h:53