CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/MuonDetId/src/RPCCompDetId.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     src
00004 // Class  :     RPCCompDetId
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Author:      Marcello Maggi
00010 // Created:     Wed Nov  2 12:09:10 CET 2011
00011 // $Id: RPCCompDetId.cc,v 1.4 2012/02/04 23:27:47 eulisse Exp $
00012 #include <iostream>
00013 #include <sstream>
00014 #include <iomanip>
00015 #include "DataFormats/MuonDetId/interface/RPCCompDetId.h"
00016 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h" 
00017 
00018 RPCCompDetId::RPCCompDetId():DetId(DetId::Muon, MuonSubdetId::RPC),_dbname(""),_type(0){}
00019 
00020 RPCCompDetId::RPCCompDetId(uint32_t id):DetId(id),_dbname(""),_type(0) {
00021   if (det()!=DetId::Muon || subdetId()!=MuonSubdetId::RPC) {
00022     throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
00023                                          << " det: " << det()
00024                                          << " subdet: " << subdetId()
00025                                          << " is not a valid RPC id";  
00026   }
00027 }
00028 
00029 
00030 
00031 RPCCompDetId::RPCCompDetId(DetId id):DetId(id),_dbname(""),_type(0) {
00032   if (det()!=DetId::Muon || subdetId()!=MuonSubdetId::RPC) {
00033     throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
00034                                          << " det: " << det()
00035                                          << " subdet: " << subdetId()
00036                                          << " is not a valid RPC id";
00037   }
00038 }
00039 
00040 
00041 
00042 RPCCompDetId::RPCCompDetId(int region,
00043                            int ring,
00044                            int station,
00045                            int sector,
00046                            int layer,
00047                            int subsector,
00048                            int type):
00049   DetId(DetId::Muon, MuonSubdetId::RPC),_dbname(""),_type(type)
00050 {
00051   this->init(region,ring,station,sector,layer,subsector); 
00052 }
00053 
00054 RPCCompDetId::RPCCompDetId(const std::string& name, int type):
00055   DetId(DetId::Muon, MuonSubdetId::RPC),_dbname(name),_type(type)
00056 {
00057   this->init();
00058 }
00059 
00060 bool 
00061 RPCCompDetId::operator < (const RPCCompDetId& r) const{
00062   return this->dbname()<r.dbname();
00063 }
00064 
00065 int 
00066 RPCCompDetId::region() const{
00067   return int((id_>>RegionStartBit_) & RegionMask_) + allRegionId;
00068 }
00069 
00070 int
00071 RPCCompDetId::ring() const{
00072   return int((id_>>RingStartBit_) & RingMask_) + allRingId;
00073 }
00074 
00075 
00076 int
00077 RPCCompDetId::wheel() const{
00078   int w=allRingId;
00079   if (this->region()==0)
00080     w=this->ring();
00081   return w;
00082 }
00083 
00084 int
00085 RPCCompDetId::station() const{
00086   return int((id_>>StationStartBit_) & StationMask_) + allStationId;
00087 }
00088 
00089 int
00090 RPCCompDetId::disk() const{
00091   int d=allStationId;
00092   if (this->region()!=0)
00093     d=this->station();
00094   return d;
00095 }
00096 
00097 
00098 int
00099 RPCCompDetId::sector() const{
00100   return int((id_>>SectorStartBit_) & SectorMask_) + allSectorId;
00101 }
00102 
00103 
00104 int
00105 RPCCompDetId::layer() const{
00106   return int((id_>>LayerStartBit_) & LayerMask_) + allLayerId;
00107 }
00108 
00109 
00110 int
00111 RPCCompDetId::subsector() const{
00112   return int((id_>>SubSectorStartBit_) & SubSectorMask_) + allSubSectorId;
00113 }
00114 
00115 
00116 int
00117 RPCCompDetId::type() const{
00118   return _type;
00119 }
00120 
00121 std::string
00122 RPCCompDetId::dbname() const{
00123   std::string a=_dbname;
00124   if (a.size() == 0){
00125     if(this->type() == 0){
00126       a=this->gasDBname();
00127     }
00128   }
00129   return a;
00130 }
00131 
00132 void
00133 RPCCompDetId::init(int region,
00134                    int ring,
00135                    int station,
00136                    int sector,
00137                    int layer,
00138                    int subsector)
00139 {
00140   int maxRing=maxRingForwardId;
00141   if (!region)
00142     {
00143       maxRing=maxRingBarrelId;
00144     }
00145   
00146   if ( region     < allRegionId    || region    > maxRegionId ||
00147        ring       < allRingId      || ring      > maxRing ||
00148        station    < allStationId   || station   > maxStationId ||
00149        sector     < allSectorId    || sector    > maxSectorId ||
00150        layer      < allLayerId     || layer     > maxLayerId ||
00151        subsector  < allSubSectorId || subsector > maxSubSectorId ){
00152     
00153     throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
00154                                          << " Invalid parameters: "
00155                                          << " region "<<region
00156                                          << " ring "<<ring
00157                                          << " station "<<station
00158                                          << " sector "<<sector
00159                                          << " layer "<<layer
00160                                          << " subsector "<<subsector
00161                                          << std::endl;
00162   }
00163   int regionInBits    = region  -  allRegionId;
00164   int ringInBits      = ring     - allRingId;
00165   int stationInBits   = station  - allStationId;
00166   int sectorInBits    = sector   - allSectorId;
00167   int layerInBits     = layer    - allLayerId;
00168   int subSectorInBits = subsector- allSubSectorId;
00169 
00170   id_ |= ( regionInBits    & RegionMask_)    << RegionStartBit_    |
00171          ( ringInBits      & RingMask_)      << RingStartBit_      |
00172          ( stationInBits   & StationMask_)   << StationStartBit_   |
00173          ( sectorInBits    & SectorMask_)    << SectorStartBit_    |
00174          ( layerInBits     & LayerMask_)     << LayerStartBit_     |
00175          ( subSectorInBits & SubSectorMask_) << SubSectorStartBit_ ;
00176 }
00177 
00178 void 
00179 RPCCompDetId::init()
00180 {
00181   if (this->type()==0){
00182     this->initGas();
00183   }
00184 }
00185 
00186 void
00187 RPCCompDetId::initGas()
00188 {
00189   std::string buf(this->dbname()); 
00190   // check if the name contains the dcs namespace
00191   if (buf.find(':')!=buf.npos){
00192     buf = buf.substr(buf.find(':')+1,buf.npos);
00193   }
00194   _dbname=buf;
00195   // Check if endcap o barrel
00196   int region=0;
00197   if(buf.substr(0,1)=="W"){
00198     region=0;
00199   }else if(buf.substr(0,2)=="EP"){
00200     region=1;
00201   }else if(buf.substr(0,2)=="EM"){
00202     region=-1;
00203   }else{
00204     throw cms::Exception("InvalidDBName")<<" RPCCompDetId: "<<this->dbname()
00205                                          <<" is not a valid DB Name for RPCCompDetId"
00206                                          << " det: " << det()
00207                                          << " subdet: " << subdetId();
00208   }
00209   int ring=allRingId;
00210   int station = allStationId;
00211   int sector=allSectorId;
00212   int layer=allLayerId;
00213   int subsector=allSubSectorId;
00214     //Barrel
00215   if (region==0) {
00216     // Extract the Wheel (named ring)
00217     {
00218       std::stringstream os;
00219       os<<buf.substr(2,1);
00220       os>>ring;
00221       if (buf.substr(1,1)=="M"){
00222         ring *= -1;
00223       }
00224     }
00225     //Extract the station
00226     {
00227       std::stringstream os;
00228       os<<buf.substr(buf.find("RB")+2,1);
00229       os>>station;
00230     }
00231     //Extract the sector
00232     {
00233       std::stringstream os;
00234       os<<buf.substr(buf.find("S")+1,2);
00235       os>>sector;
00236     }
00237     //Extract subsector of sectors 4 and 10
00238     {
00239       if (buf.find("4L")!=buf.npos)
00240         subsector=1;
00241       if (buf.find("4R")!=buf.npos)
00242         subsector=2;
00243     }
00244   }else{
00245   // Extract the Ring 
00246     {
00247       std::stringstream os;
00248       os<<buf.substr(buf.find("_R0")+3,1);
00249       os>>ring;
00250     }
00251   //Extract the disk (named station)
00252     {
00253       std::stringstream os;
00254       os<<buf.substr(2,1);
00255       os>>station;
00256     }
00257     //Extract the sector or chamber
00258     {
00259       std::stringstream os;
00260       os<<buf.substr(buf.find("_C")+2,2);
00261       os>>sector;
00262     }
00263     //Extract layer
00264     {
00265       if (buf.find("UP")!=buf.npos)
00266         layer=1;
00267       if (buf.find("DW")!=buf.npos)
00268         layer=2;
00269     }
00270   }
00271   this->init(region,ring,station,sector,layer,subsector); 
00272 }
00273 
00274 std::string
00275 RPCCompDetId::gasDBname() const{
00276   std::stringstream os;
00277   if(this->region()==0){
00278     // Barrel
00279     std::string wsign="P";
00280     if (this->wheel()<0)wsign= "M";
00281     std::string lr="";
00282     if (this->subsector()==1) lr="L";
00283     if (this->subsector()==2) lr="R";
00284     os<<"W"<<wsign<<abs(this->wheel())<<"_S"<<std::setw(2)<<std::setfill('0')<<this->sector()<<"_RB"<<this->station()<<lr;
00285   } else {
00286     // Endcap
00287     std::string esign="P";
00288     if (this->region()<0)
00289       esign="M";
00290 
00291     os<<"E"<<esign<<this->disk();
00292 
00293 
00294     if (this->disk()==1){
00295       os<<"_R"<<std::setw(2)<<std::setfill('0')<<this->ring()
00296         <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()
00297         <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()+5;
00298     }else{
00299       os<<"_R"<<std::setw(2)<<std::setfill('0')<<this->ring()
00300         <<"_R"<<std::setw(2)<<std::setfill('0')<<this->ring()+1
00301         <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()
00302         <<"_C"<<std::setw(2)<<std::setfill('0')<<this->sector()+2;
00303      
00304     }
00305     std::string lay="";
00306     if(this->layer()==1)
00307       lay="UP";
00308     else if (this->layer()==2)
00309       lay="DW";
00310 
00311     os<<"_"<<lay;
00312       
00313  }
00314   return os.str();
00315 }
00316 
00317 std::ostream& operator<<( std::ostream& os, const RPCCompDetId& id ){
00318 
00319   os <<id.dbname();
00320 
00321   return os;
00322 }
00323 
00324 
00325 
00326 
00327 
00328