Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:47

0001 // -*- C++ -*-
0002 //
0003 // Package:     src
0004 // Class  :     RPCCompDetId
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Author:      Marcello Maggi
0010 // Created:     Wed Nov  2 12:09:10 CET 2011
0011 #include <iostream>
0012 #include <sstream>
0013 #include <iomanip>
0014 #include "DataFormats/MuonDetId/interface/RPCCompDetId.h"
0015 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0016 
0017 RPCCompDetId::RPCCompDetId() : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(""), _type(0) {}
0018 
0019 RPCCompDetId::RPCCompDetId(uint32_t id) : DetId(id), _dbname(""), _type(0) {
0020   if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
0021     throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
0022                                          << " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
0023   }
0024 }
0025 
0026 RPCCompDetId::RPCCompDetId(DetId id) : DetId(id), _dbname(""), _type(0) {
0027   if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
0028     throw cms::Exception("InvalidDetId") << "RPCCompDetId ctor:"
0029                                          << " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
0030   }
0031 }
0032 
0033 RPCCompDetId::RPCCompDetId(int region, int ring, int station, int sector, int layer, int subsector, int type)
0034     : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(""), _type(type) {
0035   this->init(region, ring, station, sector, layer, subsector);
0036 }
0037 
0038 RPCCompDetId::RPCCompDetId(const std::string& name, int type)
0039     : DetId(DetId::Muon, MuonSubdetId::RPC), _dbname(name), _type(type) {
0040   this->init();
0041 }
0042 
0043 bool RPCCompDetId::operator<(const RPCCompDetId& r) const { return this->dbname() < r.dbname(); }
0044 
0045 int RPCCompDetId::region() const { return int((id_ >> RegionStartBit_) & RegionMask_) + allRegionId; }
0046 
0047 int RPCCompDetId::ring() const { return int((id_ >> RingStartBit_) & RingMask_) + allRingId; }
0048 
0049 int RPCCompDetId::wheel() const {
0050   int w = allRingId;
0051   if (this->region() == 0)
0052     w = this->ring();
0053   return w;
0054 }
0055 
0056 int RPCCompDetId::station() const { return int((id_ >> StationStartBit_) & StationMask_) + allStationId; }
0057 
0058 int RPCCompDetId::disk() const {
0059   int d = allStationId;
0060   if (this->region() != 0)
0061     d = this->station();
0062   return d;
0063 }
0064 
0065 int RPCCompDetId::sector() const { return int((id_ >> SectorStartBit_) & SectorMask_) + allSectorId; }
0066 
0067 int RPCCompDetId::layer() const { return int((id_ >> LayerStartBit_) & LayerMask_) + allLayerId; }
0068 
0069 int RPCCompDetId::subsector() const { return int((id_ >> SubSectorStartBit_) & SubSectorMask_) + allSubSectorId; }
0070 
0071 int RPCCompDetId::type() const { return _type; }
0072 
0073 std::string RPCCompDetId::dbname() const {
0074   std::string a = _dbname;
0075   if (a.empty()) {
0076     if (this->type() == 0) {
0077       a = this->gasDBname();
0078     }
0079   }
0080   return a;
0081 }
0082 
0083 void RPCCompDetId::init(int region, int ring, int station, int sector, int layer, int subsector) {
0084   int maxRing = maxRingForwardId;
0085   if (!region) {
0086     maxRing = maxRingBarrelId;
0087   }
0088 
0089   if (region < allRegionId || region > maxRegionId || ring < allRingId || ring > maxRing || station < allStationId ||
0090       station > maxStationId || sector < allSectorId || sector > maxSectorId || layer < allLayerId ||
0091       layer > maxLayerId || subsector < allSubSectorId || subsector > maxSubSectorId) {
0092     throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
0093                                          << " Invalid parameters: "
0094                                          << " region " << region << " ring " << ring << " station " << station
0095                                          << " sector " << sector << " layer " << layer << " subsector " << subsector
0096                                          << std::endl;
0097   }
0098   int regionInBits = region - allRegionId;
0099   int ringInBits = ring - allRingId;
0100   int stationInBits = station - allStationId;
0101   int sectorInBits = sector - allSectorId;
0102   int layerInBits = layer - allLayerId;
0103   int subSectorInBits = subsector - allSubSectorId;
0104 
0105   id_ |= (regionInBits & RegionMask_) << RegionStartBit_ | (ringInBits & RingMask_) << RingStartBit_ |
0106          (stationInBits & StationMask_) << StationStartBit_ | (sectorInBits & SectorMask_) << SectorStartBit_ |
0107          (layerInBits & LayerMask_) << LayerStartBit_ | (subSectorInBits & SubSectorMask_) << SubSectorStartBit_;
0108 }
0109 
0110 void RPCCompDetId::init() {
0111   if (this->type() == 0) {
0112     this->initGas();
0113   }
0114 }
0115 
0116 void RPCCompDetId::initGas() {
0117   std::string buf(this->dbname());
0118   // check if the name contains the dcs namespace
0119   if (buf.find(':') != buf.npos) {
0120     buf = buf.substr(buf.find(':') + 1, buf.npos);
0121   }
0122   _dbname = buf;
0123   // Check if endcap o barrel
0124   int region = 0;
0125   if (buf.substr(0, 1) == "W") {
0126     region = 0;
0127   } else if (buf.substr(0, 2) == "EP") {
0128     region = 1;
0129   } else if (buf.substr(0, 2) == "EM") {
0130     region = -1;
0131   } else {
0132     throw cms::Exception("InvalidDBName")
0133         << " RPCCompDetId: " << this->dbname() << " is not a valid DB Name for RPCCompDetId"
0134         << " det: " << det() << " subdet: " << subdetId();
0135   }
0136   int ring = allRingId;
0137   int station = allStationId;
0138   int sector = allSectorId;
0139   int layer = allLayerId;
0140   int subsector = allSubSectorId;
0141   //Barrel
0142   if (region == 0) {
0143     // Extract the Wheel (named ring)
0144     {
0145       std::stringstream os;
0146       os << buf.substr(2, 1);
0147       os >> ring;
0148       if (buf.substr(1, 1) == "M") {
0149         ring *= -1;
0150       }
0151     }
0152     //Extract the station
0153     {
0154       std::stringstream os;
0155       os << buf.substr(buf.find("RB") + 2, 1);
0156       os >> station;
0157     }
0158     //Extract the sector
0159     {
0160       std::stringstream os;
0161       os << buf.substr(buf.find('S') + 1, 2);
0162       os >> sector;
0163     }
0164     //Extract subsector of sectors 4 and 10
0165     {
0166       if (buf.find("4L") != buf.npos)
0167         subsector = 1;
0168       if (buf.find("4R") != buf.npos)
0169         subsector = 2;
0170     }
0171   } else {
0172     // Extract the Ring
0173     {
0174       std::stringstream os;
0175       os << buf.substr(buf.find("_R0") + 3, 1);
0176       os >> ring;
0177     }
0178     //Extract the disk (named station)
0179     {
0180       std::stringstream os;
0181       os << buf.substr(2, 1);
0182       os >> station;
0183     }
0184     //Extract the sector or chamber
0185     {
0186       std::stringstream os;
0187       os << buf.substr(buf.find("_C") + 2, 2);
0188       os >> sector;
0189     }
0190     //Extract layer
0191     {
0192       if (buf.find("UP") != buf.npos)
0193         layer = 1;
0194       if (buf.find("DW") != buf.npos)
0195         layer = 2;
0196     }
0197   }
0198   this->init(region, ring, station, sector, layer, subsector);
0199 }
0200 
0201 std::string RPCCompDetId::gasDBname() const {
0202   std::stringstream os;
0203   if (this->region() == 0) {
0204     // Barrel
0205     std::string wsign = "P";
0206     if (this->wheel() < 0)
0207       wsign = "M";
0208     std::string lr = "";
0209     if (this->subsector() == 1)
0210       lr = "L";
0211     if (this->subsector() == 2)
0212       lr = "R";
0213     os << "W" << wsign << abs(this->wheel()) << "_S" << std::setw(2) << std::setfill('0') << this->sector() << "_RB"
0214        << this->station() << lr;
0215   } else {
0216     // Endcap
0217     std::string esign = "P";
0218     if (this->region() < 0)
0219       esign = "M";
0220 
0221     os << "E" << esign << this->disk();
0222 
0223     if (this->disk() == 1) {
0224       os << "_R" << std::setw(2) << std::setfill('0') << this->ring() << "_C" << std::setw(2) << std::setfill('0')
0225          << this->sector() << "_C" << std::setw(2) << std::setfill('0') << this->sector() + 5;
0226     } else {
0227       os << "_R" << std::setw(2) << std::setfill('0') << this->ring() << "_R" << std::setw(2) << std::setfill('0')
0228          << this->ring() + 1 << "_C" << std::setw(2) << std::setfill('0') << this->sector() << "_C" << std::setw(2)
0229          << std::setfill('0') << this->sector() + 2;
0230     }
0231     std::string lay = "";
0232     if (this->layer() == 1)
0233       lay = "UP";
0234     else if (this->layer() == 2)
0235       lay = "DW";
0236 
0237     os << "_" << lay;
0238   }
0239   return os.str();
0240 }
0241 
0242 std::ostream& operator<<(std::ostream& os, const RPCCompDetId& id) {
0243   os << id.dbname();
0244 
0245   return os;
0246 }