CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
36 
38  explicit CTPPSDetId(uint32_t id);
39 
41  CTPPSDetId(uint32_t SubDet, uint32_t Arm, uint32_t Station, uint32_t RomanPot = 0);
42 
43  //-------------------- bit assignment --------------------
44 
45  static const uint32_t startArmBit, maskArm, maxArm, lowMaskArm;
47  static const uint32_t startRPBit, maskRP, maxRP, lowMaskRP;
48 
49  //-------------------- component getters and setters --------------------
50 
51  uint32_t arm() const { return ((id_ >> startArmBit) & maskArm); }
52 
53  void setArm(uint32_t arm) {
54  id_ &= ~(maskArm << startArmBit);
55  id_ |= ((arm & maskArm) << startArmBit);
56  }
57 
58  uint32_t station() const { return ((id_ >> startStationBit) & maskStation); }
59 
60  void setStation(uint32_t station) {
62  id_ |= ((station & maskStation) << startStationBit);
63  }
64 
65  uint32_t rp() const { return ((id_ >> startRPBit) & maskRP); }
66 
67  void setRP(uint32_t rp) {
68  id_ &= ~(maskRP << startRPBit);
69  id_ |= ((rp & maskRP) << startRPBit);
70  }
71 
72  //-------------------- id getters for higher-level objects --------------------
73 
74  CTPPSDetId armId() const { return CTPPSDetId(rawId() & (~lowMaskArm)); }
75 
76  CTPPSDetId stationId() const { return CTPPSDetId(rawId() & (~lowMaskStation)); }
77 
78  CTPPSDetId rpId() const { return CTPPSDetId(rawId() & (~lowMaskRP)); }
79 
80  //-------------------- name methods --------------------
81 
83  enum NameFlag { nShort, nFull, nPath };
84 
85  inline void subDetectorName(std::string &name, NameFlag flag = nFull) const {
86  if (flag == nPath)
87  name = subDetectorPaths[subdetId()];
88  else
89  name = subDetectorNames[subdetId()];
90  }
91 
92  inline void armName(std::string &name, NameFlag flag = nFull) const {
93  switch (flag) {
94  case nShort:
95  name = "";
96  break;
97  case nFull:
98  subDetectorName(name, flag);
99  name += "_";
100  break;
101  case nPath:
102  subDetectorName(name, flag);
103  name += "/sector ";
104  break;
105  }
106 
107  name += armNames[arm()];
108  }
109 
110  inline void stationName(std::string &name, NameFlag flag = nFull) const {
111  switch (flag) {
112  case nShort:
113  name = "";
114  break;
115  case nFull:
116  armName(name, flag);
117  name += "_";
118  break;
119  case nPath:
120  armName(name, flag);
121  name += "/station ";
122  break;
123  }
124 
125  name += stationNames[station()];
126  }
127 
128  inline void rpName(std::string &name, NameFlag flag = nFull) const {
129  switch (flag) {
130  case nShort:
131  name = "";
132  break;
133  case nFull:
134  stationName(name, flag);
135  name += "_";
136  break;
137  case nPath:
138  stationName(name, flag);
139  name += "/";
140  break;
141  }
142 
143  name += rpNames[rp()];
144  }
145 
146 private:
149  static const std::string armNames[];
150  static const std::string stationNames[];
151  static const std::string rpNames[];
152 };
153 
154 std::ostream &operator<<(std::ostream &os, const CTPPSDetId &id);
155 
156 namespace std {
157  template <>
158  struct hash<CTPPSDetId> {
160  typedef std::size_t result_type;
161  result_type operator()(const argument_type &id) const noexcept { return std::hash<uint64_t>()(id.rawId()); }
162  };
163 } // namespace std
164 
165 #endif
uint32_t station() const
Definition: CTPPSDetId.h:58
CTPPSDetId argument_type
Definition: CTPPSDetId.h:159
SubDetector
CTPPS sub-detectors.
Definition: CTPPSDetId.h:35
tuple SubDet
Definition: ntupleEnum.py:14
static const uint32_t maxStation
Definition: CTPPSDetId.h:46
std::size_t result_type
Definition: CTPPSDetId.h:160
NameFlag
type of name returned by *Name functions
Definition: CTPPSDetId.h:83
void setArm(uint32_t arm)
Definition: CTPPSDetId.h:53
void setRP(uint32_t rp)
Definition: CTPPSDetId.h:67
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
static const uint32_t startRPBit
Definition: CTPPSDetId.h:47
static const uint32_t maskStation
Definition: CTPPSDetId.h:46
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:78
static const uint32_t maskRP
Definition: CTPPSDetId.h:47
static const std::string armNames[]
Definition: CTPPSDetId.h:149
CTPPSDetId stationId() const
Definition: CTPPSDetId.h:76
static const uint32_t lowMaskStation
Definition: CTPPSDetId.h:46
static const uint32_t maskArm
Definition: CTPPSDetId.h:45
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 uint32_t maxArm
Definition: CTPPSDetId.h:45
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:128
uint32_t arm() const
Definition: CTPPSDetId.h:51
static const std::string subDetectorPaths[]
Definition: CTPPSDetId.h:148
void armName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:92
CTPPSDetId armId() const
Definition: CTPPSDetId.h:74
static const uint32_t maxRP
Definition: CTPPSDetId.h:47
static const std::string rpNames[]
Definition: CTPPSDetId.h:151
void setStation(uint32_t station)
Definition: CTPPSDetId.h:60
static const std::string subDetectorNames[]
Definition: CTPPSDetId.h:147
Definition: DetId.h:17
uint32_t id_
Definition: DetId.h:69
static const uint32_t startStationBit
Definition: CTPPSDetId.h:46
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
CTPPSDetId(uint32_t id)
Construct from a raw id.
Definition: CTPPSDetId.cc:35
result_type operator()(const argument_type &id) const noexcept
Definition: CTPPSDetId.h:161
static const uint32_t startArmBit
Definition: CTPPSDetId.h:45
void stationName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:110
static const std::string stationNames[]
Definition: CTPPSDetId.h:150
static const uint32_t lowMaskArm
Definition: CTPPSDetId.h:45
static const uint32_t lowMaskRP
Definition: CTPPSDetId.h:47
void subDetectorName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:85
uint32_t rp() const
Definition: CTPPSDetId.h:65