CMS 3D CMS Logo

RPCCompDetId.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: src
4 // Class : RPCCompDetId
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Author: Marcello Maggi
10 // Created: Wed Nov 2 12:09:10 CET 2011
11 #include <iostream>
12 #include <sstream>
13 #include <iomanip>
16 
17 RPCCompDetId::RPCCompDetId() : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(""), _type(0) {}
18 
19 RPCCompDetId::RPCCompDetId(uint32_t id) : DetId(id), _dbname(""), _type(0) {
20  if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
21  throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
22  << " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
23  }
24 }
25 
26 RPCCompDetId::RPCCompDetId(DetId id) : DetId(id), _dbname(""), _type(0) {
27  if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
28  throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
29  << " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
30  }
31 }
32 
34  : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(""), _type(type) {
35  this->init(region, ring, station, sector, layer, subsector);
36 }
37 
39  : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(name), _type(type) {
40  this->init();
41 }
42 
43 bool RPCCompDetId::operator<(const RPCCompDetId& r) const { return this->dbname() < r.dbname(); }
44 
46 
47 int RPCCompDetId::ring() const { return int((id_ >> RingStartBit_) & RingMask_) + allRingId; }
48 
49 int RPCCompDetId::wheel() const {
50  int w = allRingId;
51  if (this->region() == 0)
52  w = this->ring();
53  return w;
54 }
55 
57 
58 int RPCCompDetId::disk() const {
59  int d = allStationId;
60  if (this->region() != 0)
61  d = this->station();
62  return d;
63 }
64 
66 
68 
70 
71 int RPCCompDetId::type() const { return _type; }
72 
75  if (a.empty()) {
76  if (this->type() == 0) {
77  a = this->gasDBname();
78  }
79  }
80  return a;
81 }
82 
83 void RPCCompDetId::init(int region, int ring, int station, int sector, int layer, int subsector) {
85  if (!region) {
87  }
88 
89  if (region < allRegionId || region > maxRegionId || ring < allRingId || ring > maxRing || station < allStationId ||
90  station > maxStationId || sector < allSectorId || sector > maxSectorId || layer < allLayerId ||
91  layer > maxLayerId || subsector < allSubSectorId || subsector > maxSubSectorId) {
92  throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
93  << " Invalid parameters: "
94  << " region " << region << " ring " << ring << " station " << station
95  << " sector " << sector << " layer " << layer << " subsector " << subsector
96  << std::endl;
97  }
98  int regionInBits = region - allRegionId;
99  int ringInBits = ring - allRingId;
100  int stationInBits = station - allStationId;
101  int sectorInBits = sector - allSectorId;
102  int layerInBits = layer - allLayerId;
103  int subSectorInBits = subsector - allSubSectorId;
104 
105  id_ |= (regionInBits & RegionMask_) << RegionStartBit_ | (ringInBits & RingMask_) << RingStartBit_ |
106  (stationInBits & StationMask_) << StationStartBit_ | (sectorInBits & SectorMask_) << SectorStartBit_ |
107  (layerInBits & LayerMask_) << LayerStartBit_ | (subSectorInBits & SubSectorMask_) << SubSectorStartBit_;
108 }
109 
111  if (this->type() == 0) {
112  this->initGas();
113  }
114 }
115 
117  std::string buf(this->dbname());
118  // check if the name contains the dcs namespace
119  if (buf.find(':') != buf.npos) {
120  buf = buf.substr(buf.find(':') + 1, buf.npos);
121  }
122  _dbname = buf;
123  // Check if endcap o barrel
124  int region = 0;
125  if (buf.substr(0, 1) == "W") {
126  region = 0;
127  } else if (buf.substr(0, 2) == "EP") {
128  region = 1;
129  } else if (buf.substr(0, 2) == "EM") {
130  region = -1;
131  } else {
132  throw cms::Exception("InvalidDBName")
133  << " RPCCompDetId: " << this->dbname() << " is not a valid DB Name for RPCCompDetId"
134  << " det: " << det() << " subdet: " << subdetId();
135  }
136  int ring = allRingId;
137  int station = allStationId;
138  int sector = allSectorId;
139  int layer = allLayerId;
141  //Barrel
142  if (region == 0) {
143  // Extract the Wheel (named ring)
144  {
145  std::stringstream os;
146  os << buf.substr(2, 1);
147  os >> ring;
148  if (buf.substr(1, 1) == "M") {
149  ring *= -1;
150  }
151  }
152  //Extract the station
153  {
154  std::stringstream os;
155  os << buf.substr(buf.find("RB") + 2, 1);
156  os >> station;
157  }
158  //Extract the sector
159  {
160  std::stringstream os;
161  os << buf.substr(buf.find('S') + 1, 2);
162  os >> sector;
163  }
164  //Extract subsector of sectors 4 and 10
165  {
166  if (buf.find("4L") != buf.npos)
167  subsector = 1;
168  if (buf.find("4R") != buf.npos)
169  subsector = 2;
170  }
171  } else {
172  // Extract the Ring
173  {
174  std::stringstream os;
175  os << buf.substr(buf.find("_R0") + 3, 1);
176  os >> ring;
177  }
178  //Extract the disk (named station)
179  {
180  std::stringstream os;
181  os << buf.substr(2, 1);
182  os >> station;
183  }
184  //Extract the sector or chamber
185  {
186  std::stringstream os;
187  os << buf.substr(buf.find("_C") + 2, 2);
188  os >> sector;
189  }
190  //Extract layer
191  {
192  if (buf.find("UP") != buf.npos)
193  layer = 1;
194  if (buf.find("DW") != buf.npos)
195  layer = 2;
196  }
197  }
198  this->init(region, ring, station, sector, layer, subsector);
199 }
200 
202  std::stringstream os;
203  if (this->region() == 0) {
204  // Barrel
205  std::string wsign = "P";
206  if (this->wheel() < 0)
207  wsign = "M";
208  std::string lr = "";
209  if (this->subsector() == 1)
210  lr = "L";
211  if (this->subsector() == 2)
212  lr = "R";
213  os << "W" << wsign << abs(this->wheel()) << "_S" << std::setw(2) << std::setfill('0') << this->sector() << "_RB"
214  << this->station() << lr;
215  } else {
216  // Endcap
217  std::string esign = "P";
218  if (this->region() < 0)
219  esign = "M";
220 
221  os << "E" << esign << this->disk();
222 
223  if (this->disk() == 1) {
224  os << "_R" << std::setw(2) << std::setfill('0') << this->ring() << "_C" << std::setw(2) << std::setfill('0')
225  << this->sector() << "_C" << std::setw(2) << std::setfill('0') << this->sector() + 5;
226  } else {
227  os << "_R" << std::setw(2) << std::setfill('0') << this->ring() << "_R" << std::setw(2) << std::setfill('0')
228  << this->ring() + 1 << "_C" << std::setw(2) << std::setfill('0') << this->sector() << "_C" << std::setw(2)
229  << std::setfill('0') << this->sector() + 2;
230  }
231  std::string lay = "";
232  if (this->layer() == 1)
233  lay = "UP";
234  else if (this->layer() == 2)
235  lay = "DW";
236 
237  os << "_" << lay;
238  }
239  return os.str();
240 }
241 
242 std::ostream& operator<<(std::ostream& os, const RPCCompDetId& id) {
243  os << id.dbname();
244 
245  return os;
246 }
std::string _dbname
Definition: RPCCompDetId.h:114
static const int RegionMask_
Definition: RPCCompDetId.h:84
int sector() const
Definition: RPCCompDetId.cc:65
static const int maxStationId
Definition: RPCCompDetId.h:62
int subsector() const
Definition: RPCCompDetId.cc:69
static const int allRegionId
Definition: RPCCompDetId.h:52
static const int maxSubSectorId
Definition: RPCCompDetId.h:78
T w() const
static const int allSubSectorId
Definition: RPCCompDetId.h:79
static const int allRingId
Definition: RPCCompDetId.h:59
static const unsigned int LayerMask_
Definition: RPCCompDetId.h:100
int region() const
Definition: RPCCompDetId.cc:45
static const int allSectorId
Definition: RPCCompDetId.h:71
static const int RegionStartBit_
Definition: RPCCompDetId.h:83
int layer() const
Definition: RPCCompDetId.cc:67
bool operator<(const RPCCompDetId &r) const
Sort Operator based on the name.
Definition: RPCCompDetId.cc:43
int disk() const
Definition: RPCCompDetId.cc:58
int station() const
Definition: RPCCompDetId.cc:56
int type() const
Definition: RPCCompDetId.cc:71
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
static const int StationStartBit_
Definition: RPCCompDetId.h:91
static const int RingStartBit_
Definition: RPCCompDetId.h:87
static const int SubSectorStartBit_
Definition: RPCCompDetId.h:103
static const int allStationId
Definition: RPCCompDetId.h:63
Definition: Muon.py:1
std::string gasDBname() const
static const int maxLayerId
Definition: RPCCompDetId.h:74
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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 int allLayerId
Definition: RPCCompDetId.h:75
static const unsigned int StationMask_
Definition: RPCCompDetId.h:92
d
Definition: ztail.py:151
static const unsigned int SectorMask_
Definition: RPCCompDetId.h:96
static const int maxRingBarrelId
Definition: RPCCompDetId.h:57
int wheel() const
Definition: RPCCompDetId.cc:49
Definition: DetId.h:17
int ring() const
Definition: RPCCompDetId.cc:47
static const unsigned int SubSectorMask_
Definition: RPCCompDetId.h:104
static const int maxRegionId
Definition: RPCCompDetId.h:51
uint32_t id_
Definition: DetId.h:69
static constexpr int RPC
Definition: MuonSubdetId.h:13
std::string dbname() const
Definition: RPCCompDetId.cc:73
double a
Definition: hdecay.h:121
static const int maxSectorId
Definition: RPCCompDetId.h:66
static const int maxRingForwardId
Definition: RPCCompDetId.h:55
std::ostream & operator<<(std::ostream &os, const RPCCompDetId &id)
static const unsigned int RingMask_
Definition: RPCCompDetId.h:88
static const int LayerStartBit_
Definition: RPCCompDetId.h:99
static const int SectorStartBit_
Definition: RPCCompDetId.h:95