CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
18 
19 RPCCompDetId::RPCCompDetId(uint32_t id):DetId(id),_dbname(""),_type(0) {
21  throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
22  << " det: " << det()
23  << " subdet: " << subdetId()
24  << " is not a valid RPC id";
25  }
26 }
27 
28 
29 
30 RPCCompDetId::RPCCompDetId(DetId id):DetId(id),_dbname(""),_type(0) {
32  throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
33  << " det: " << det()
34  << " subdet: " << subdetId()
35  << " is not a valid RPC id";
36  }
37 }
38 
39 
40 
42  int ring,
43  int station,
44  int sector,
45  int layer,
46  int subsector,
47  int type):
48  DetId(DetId::Muon, MuonSubdetId::RPC),_dbname(""),_type(type)
49 {
50  this->init(region,ring,station,sector,layer,subsector);
51 }
52 
54  DetId(DetId::Muon, MuonSubdetId::RPC),_dbname(name),_type(type)
55 {
56  this->init();
57 }
58 
59 bool
61  return this->dbname()<r.dbname();
62 }
63 
64 int
66  return int((id_>>RegionStartBit_) & RegionMask_) + allRegionId;
67 }
68 
69 int
71  return int((id_>>RingStartBit_) & RingMask_) + allRingId;
72 }
73 
74 
75 int
77  int w=allRingId;
78  if (this->region()==0)
79  w=this->ring();
80  return w;
81 }
82 
83 int
85  return int((id_>>StationStartBit_) & StationMask_) + allStationId;
86 }
87 
88 int
90  int d=allStationId;
91  if (this->region()!=0)
92  d=this->station();
93  return d;
94 }
95 
96 
97 int
99  return int((id_>>SectorStartBit_) & SectorMask_) + allSectorId;
100 }
101 
102 
103 int
105  return int((id_>>LayerStartBit_) & LayerMask_) + allLayerId;
106 }
107 
108 
109 int
112 }
113 
114 
115 int
117  return _type;
118 }
119 
123  if (a.size() == 0){
124  if(this->type() == 0){
125  a=this->gasDBname();
126  }
127  }
128  return a;
129 }
130 
131 void
133  int ring,
134  int station,
135  int sector,
136  int layer,
137  int subsector)
138 {
140  if (!region)
141  {
142  maxRing=maxRingBarrelId;
143  }
144 
145  if ( region < allRegionId || region > maxRegionId ||
146  ring < allRingId || ring > maxRing ||
147  station < allStationId || station > maxStationId ||
148  sector < allSectorId || sector > maxSectorId ||
149  layer < allLayerId || layer > maxLayerId ||
150  subsector < allSubSectorId || subsector > maxSubSectorId ){
151 
152  throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
153  << " Invalid parameters: "
154  << " region "<<region
155  << " ring "<<ring
156  << " station "<<station
157  << " sector "<<sector
158  << " layer "<<layer
159  << " subsector "<<subsector
160  << std::endl;
161  }
162  int regionInBits = region - allRegionId;
163  int ringInBits = ring - allRingId;
164  int stationInBits = station - allStationId;
165  int sectorInBits = sector - allSectorId;
166  int layerInBits = layer - allLayerId;
167  int subSectorInBits = subsector- allSubSectorId;
168 
169  id_ |= ( regionInBits & RegionMask_) << RegionStartBit_ |
170  ( ringInBits & RingMask_) << RingStartBit_ |
171  ( stationInBits & StationMask_) << StationStartBit_ |
172  ( sectorInBits & SectorMask_) << SectorStartBit_ |
173  ( layerInBits & LayerMask_) << LayerStartBit_ |
174  ( subSectorInBits & SubSectorMask_) << SubSectorStartBit_ ;
175 }
176 
177 void
179 {
180  if (this->type()==0){
181  this->initGas();
182  }
183 }
184 
185 void
187 {
188  std::string buf(this->dbname());
189  // check if the name contains the dcs namespace
190  if (buf.find(':')!=buf.npos){
191  buf = buf.substr(buf.find(':')+1,buf.npos);
192  }
193  _dbname=buf;
194  // Check if endcap o barrel
195  int region=0;
196  if(buf.substr(0,1)=="W"){
197  region=0;
198  }else if(buf.substr(0,2)=="EP"){
199  region=1;
200  }else if(buf.substr(0,2)=="EM"){
201  region=-1;
202  }else{
203  throw cms::Exception("InvalidDBName")<<" RPCCompDetId: "<<this->dbname()
204  <<" is not a valid DB Name for RPCCompDetId"
205  << " det: " << det()
206  << " subdet: " << subdetId();
207  }
208  int ring=allRingId;
209  int station = allStationId;
210  int sector=allSectorId;
211  int layer=allLayerId;
213  //Barrel
214  if (region==0) {
215  // Extract the Wheel (named ring)
216  {
217  std::stringstream os;
218  os<<buf.substr(2,1);
219  os>>ring;
220  if (buf.substr(1,1)=="M"){
221  ring *= -1;
222  }
223  }
224  //Extract the station
225  {
226  std::stringstream os;
227  os<<buf.substr(buf.find("RB")+2,1);
228  os>>station;
229  }
230  //Extract the sector
231  {
232  std::stringstream os;
233  os<<buf.substr(buf.find("S")+1,2);
234  os>>sector;
235  }
236  //Extract subsector of sectors 4 and 10
237  {
238  if (buf.find("4L")!=buf.npos)
239  subsector=1;
240  if (buf.find("4R")!=buf.npos)
241  subsector=2;
242  }
243  }else{
244  // Extract the Ring
245  {
246  std::stringstream os;
247  os<<buf.substr(buf.find("_R0")+3,1);
248  os>>ring;
249  }
250  //Extract the disk (named station)
251  {
252  std::stringstream os;
253  os<<buf.substr(2,1);
254  os>>station;
255  }
256  //Extract the sector or chamber
257  {
258  std::stringstream os;
259  os<<buf.substr(buf.find("_C")+2,2);
260  os>>sector;
261  }
262  //Extract layer
263  {
264  if (buf.find("UP")!=buf.npos)
265  layer=1;
266  if (buf.find("DW")!=buf.npos)
267  layer=2;
268  }
269  }
270  this->init(region,ring,station,sector,layer,subsector);
271 }
272 
275  std::stringstream os;
276  if(this->region()==0){
277  // Barrel
278  std::string wsign="P";
279  if (this->wheel()<0)wsign= "M";
280  std::string lr="";
281  if (this->subsector()==1) lr="L";
282  if (this->subsector()==2) lr="R";
283  os<<"W"<<wsign<<abs(this->wheel())<<"_S"<<std::setw(2)<<std::setfill('0')<<this->sector()<<"_RB"<<this->station()<<lr;
284  } else {
285  // Endcap
286  std::string esign="P";
287  if (this->region()<0)
288  esign="M";
289 
290  os<<"E"<<esign<<this->disk();
291 
292 
293  if (this->disk()==1){
294  os<<"_R"<<std::setw(2)<<std::setfill('0')<<this->ring()
295  <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()
296  <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()+5;
297  }else{
298  os<<"_R"<<std::setw(2)<<std::setfill('0')<<this->ring()
299  <<"_R"<<std::setw(2)<<std::setfill('0')<<this->ring()+1
300  <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()
301  <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()+2;
302 
303  }
304  std::string lay="";
305  if(this->layer()==1)
306  lay="UP";
307  else if (this->layer()==2)
308  lay="DW";
309 
310  os<<"_"<<lay;
311 
312  }
313  return os.str();
314 }
315 
316 std::ostream& operator<<( std::ostream& os, const RPCCompDetId& id ){
317 
318  os <<id.dbname();
319 
320  return os;
321 }
322 
323 
324 
325 
326 
327 
type
Definition: HCALResponse.h:21
std::string _dbname
Definition: RPCCompDetId.h:129
static const int RegionMask_
Definition: RPCCompDetId.h:94
static const int maxStationId
Definition: RPCCompDetId.h:71
static const int allRegionId
Definition: RPCCompDetId.h:61
static const int maxSubSectorId
Definition: RPCCompDetId.h:88
static const int allSubSectorId
Definition: RPCCompDetId.h:89
static const int allRingId
Definition: RPCCompDetId.h:68
static const unsigned int LayerMask_
Definition: RPCCompDetId.h:110
static const int allSectorId
Definition: RPCCompDetId.h:80
static const int RegionStartBit_
Definition: RPCCompDetId.h:93
int sector() const
Definition: RPCCompDetId.cc:98
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
int type() const
static const int StationStartBit_
Definition: RPCCompDetId.h:101
static const int RingStartBit_
Definition: RPCCompDetId.h:97
int subsector() const
std::string gasDBname() const
static const int SubSectorStartBit_
Definition: RPCCompDetId.h:113
static const int allStationId
Definition: RPCCompDetId.h:72
static const int maxLayerId
Definition: RPCCompDetId.h:83
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string dbname() const
static const int allLayerId
Definition: RPCCompDetId.h:84
static const unsigned int StationMask_
Definition: RPCCompDetId.h:102
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
int station() const
Definition: RPCCompDetId.cc:84
static const unsigned int SectorMask_
Definition: RPCCompDetId.h:106
static const int maxRingBarrelId
Definition: RPCCompDetId.h:66
Definition: DetId.h:18
static const unsigned int SubSectorMask_
Definition: RPCCompDetId.h:114
static const int maxRegionId
Definition: RPCCompDetId.h:60
uint32_t id_
Definition: DetId.h:55
static const int RPC
Definition: MuonSubdetId.h:14
double a
Definition: hdecay.h:121
static const int maxSectorId
Definition: RPCCompDetId.h:75
static const int maxRingForwardId
Definition: RPCCompDetId.h:64
T w() const
int wheel() const
Definition: RPCCompDetId.cc:76
int layer() const
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
bool operator<(const RPCCompDetId &r) const
Sort Operator based on the name.
Definition: RPCCompDetId.cc:60
static const unsigned int RingMask_
Definition: RPCCompDetId.h:98
int region() const
Definition: RPCCompDetId.cc:65
int disk() const
Definition: RPCCompDetId.cc:89
static const int LayerStartBit_
Definition: RPCCompDetId.h:109
static const int SectorStartBit_
Definition: RPCCompDetId.h:105
int ring() const
Definition: RPCCompDetId.cc:70