CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CalibFormats/SiStripObjects/src/SiStripRegionCabling.cc

Go to the documentation of this file.
00001 #include "CalibFormats/SiStripObjects/interface/SiStripRegionCabling.h"
00002 #include "FWCore/Utilities/interface/typelookup.h"
00003 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00004 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00005 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00006 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00007 
00008 using namespace sistrip;
00009 
00010 SiStripRegionCabling::SiStripRegionCabling(const uint32_t etadivisions, const uint32_t phidivisions, const double etamax) :
00011 
00012   etadivisions_(static_cast<int>(etadivisions)),
00013   phidivisions_(static_cast<int>(phidivisions)),
00014   etamax_(etamax),
00015   regioncabling_()
00016 
00017 {}
00018 
00019 const SiStripRegionCabling::PositionIndex SiStripRegionCabling::positionIndex(const Position position) const {
00020   int eta = static_cast<int>((position.first+etamax_)*etadivisions_/(2.*etamax_));
00021   int phi = static_cast<int>((position.second+M_PI)*phidivisions_/(2.*M_PI));
00022   return PositionIndex(static_cast<uint32_t>(eta),static_cast<uint32_t>(phi));
00023 }
00024 
00025 const uint32_t SiStripRegionCabling::region(const Position position) const {
00026   PositionIndex index = positionIndex(position); 
00027   return region(index);
00028 }
00029 
00030 SiStripRegionCabling::PositionIndex SiStripRegionCabling::increment(const PositionIndex index, int deta, int dphi) const {
00031   
00032   int eta = static_cast<int>(index.first)+deta;
00033   if (eta > etadivisions_-1) eta = etadivisions_-1;
00034   else if (eta < 0) eta = 0;
00035  
00036   int phi = static_cast<int>(index.second)+dphi;
00037   while (phi<0) phi+=phidivisions_;
00038   while (phi>phidivisions_-1) phi-=phidivisions_;
00039 
00040   return PositionIndex(static_cast<uint32_t>(eta),static_cast<uint32_t>(phi));
00041 }
00042 
00043 const SiStripRegionCabling::SubDet SiStripRegionCabling::subdetFromDetId(const uint32_t detid) {
00044 
00045   SiStripDetId::SubDetector subdet = SiStripDetId(detid).subDetector();
00046   if (subdet == 3) return TIB;
00047   else if (subdet == 4) return TID;
00048   else if (subdet == 5) return TOB;
00049   else if (subdet == 6) return TEC;
00050   else return ALLSUBDETS;
00051 }
00052 
00053 const uint32_t SiStripRegionCabling::layerFromDetId(const uint32_t detid) {
00054  
00055   SiStripRegionCabling::SubDet subdet = subdetFromDetId(detid);
00056   if (subdet == TIB) return TIBDetId(detid).layer();
00057   else if (subdet == TID) return TIDDetId(detid).wheel();
00058   else if (subdet == TOB) return TOBDetId(detid).layer(); 
00059   else if (subdet == TEC) return TECDetId(detid).wheel();
00060   else return ALLLAYERS;
00061 }
00062 
00063 const uint32_t SiStripRegionCabling::physicalLayerFromDetId(const uint32_t detid) {
00064   return physicalLayer(subdetFromDetId(detid),layerFromDetId(detid));
00065 }
00066 
00067 const uint32_t SiStripRegionCabling::physicalLayer(const SubDet subdet, const uint32_t layer) {
00068 
00069   if (subdet == TIB) return layer;
00070   else if (subdet == TOB) return TIBLAYERS + layer;
00071   else if (subdet == TID) return layer;
00072   else if (subdet == TEC) return TIDLAYERS + layer;
00073   else return ALLLAYERS;
00074 }
00075 
00076 // -----------------------------------------------------------------------------
00077 //
00078 void SiStripRegionCabling::print( std::stringstream& ss ) const {
00079   uint32_t valid = 0;
00080   uint32_t total = 0;
00081   ss << "[SiStripRegionCabling::" << __func__ << "] Printing REGION cabling:" << std::endl;
00082   ss << "Printing cabling for " << regioncabling_.size() << " regions" << std::endl;
00083   Cabling::const_iterator id = regioncabling_.begin();
00084   Cabling::const_iterator jd = regioncabling_.end();
00085   for ( ; id != jd; ++id ) {
00086     ss << "Printing cabling for " << id->size()
00087        << " regions for partition " << static_cast<int32_t>( id - regioncabling_.begin() )
00088        << std::endl;
00089     RegionCabling::const_iterator ir = id->begin();
00090     RegionCabling::const_iterator jr = id->end();
00091     for ( ; ir != jr; ++ir ) {
00092       ss << "Printing cabling for " << ir->size()
00093          << " wedges for region " << static_cast<int32_t>( ir - id->begin() )
00094          << std::endl;
00095       WedgeCabling::const_iterator iw = ir->begin();
00096       WedgeCabling::const_iterator jw = ir->end();
00097       for ( ; iw != jw; ++iw ) {
00098         ss << "Printing cabling for " << iw->size()
00099            << " elements for wedge " << static_cast<int32_t>( iw - ir->begin() )
00100            << std::endl;
00101         ElementCabling::const_iterator ie = iw->begin();
00102         ElementCabling::const_iterator je = iw->end();
00103         for ( ; ie != je; ++ie ) {
00104           ss << "Printing cabling for " << ie->second.size()
00105              << " connections for element (DetId) " << ie->first
00106              << std::endl;
00107           std::vector<FedChannelConnection>::const_iterator ic = ie->second.begin();
00108           std::vector<FedChannelConnection>::const_iterator jc = ie->second.end();
00109           for ( ; ic != jc; ++ic ) {
00110             if ( ic->isConnected() ) { valid++; }
00111             total++;
00112             ic->print(ss);
00113             ss << std::endl;
00114           }
00115         }
00116       }
00117     }
00118   }
00119   ss << "Number of connected:   " << valid << std::endl
00120      << "Number of connections: " << total << std::endl;
00121 }
00122 
00123