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