Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:13

0001 
0002 #include "DataFormats/SiStripCommon/interface/SiStripDetKey.h"
0003 #include "DataFormats/SiStripCommon/interface/Constants.h"
0004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0005 #include <iomanip>
0006 
0007 // -----------------------------------------------------------------------------
0008 //
0009 SiStripDetKey::SiStripDetKey(const uint16_t& partition)
0010     : SiStripKey(), partition_(partition), apvPairNumber_(sistrip::invalid_), apvWithinPair_(sistrip::invalid_) {
0011   // order is important!
0012   initFromValue();
0013   initFromKey();
0014   initFromPath();
0015   initGranularity();
0016 }
0017 
0018 // -----------------------------------------------------------------------------
0019 //
0020 SiStripDetKey::SiStripDetKey(const DetId& det_id, const uint16_t& apv_pair_number, const uint16_t& apv_within_pair)
0021     : SiStripKey(), partition_(sistrip::invalid_), apvPairNumber_(apv_pair_number), apvWithinPair_(apv_within_pair) {
0022   // order is important!
0023   initFromValue();
0024   initFromKey();
0025   initFromPath();
0026   initGranularity();
0027 }
0028 
0029 // -----------------------------------------------------------------------------
0030 //
0031 SiStripDetKey::SiStripDetKey(const SiStripDetId& det_id)
0032     : SiStripKey(),
0033       partition_(sistrip::invalid_),
0034       apvPairNumber_(sistrip::invalid_),
0035       apvWithinPair_(sistrip::invalid_) {
0036   // order is important!
0037   initFromValue();
0038   initFromKey();
0039   initFromPath();
0040   initGranularity();
0041 }
0042 
0043 // -----------------------------------------------------------------------------
0044 //
0045 SiStripDetKey::SiStripDetKey(const uint32_t& det_key)
0046     : SiStripKey(det_key),
0047       partition_(sistrip::invalid_),
0048       apvPairNumber_(sistrip::invalid_),
0049       apvWithinPair_(sistrip::invalid_) {
0050   // order is important!
0051   initFromKey();
0052   initFromValue();
0053   initFromPath();
0054   initGranularity();
0055 }
0056 
0057 // -----------------------------------------------------------------------------
0058 //
0059 SiStripDetKey::SiStripDetKey(const std::string& path)
0060     : SiStripKey(path),
0061       partition_(sistrip::invalid_),
0062       apvPairNumber_(sistrip::invalid_),
0063       apvWithinPair_(sistrip::invalid_) {
0064   // order is important!
0065   initFromPath();
0066   initFromValue();
0067   initFromKey();
0068   initGranularity();
0069 }
0070 
0071 // -----------------------------------------------------------------------------
0072 //
0073 SiStripDetKey::SiStripDetKey(const SiStripDetKey& input)
0074     : SiStripKey(),
0075       partition_(input.partition()),
0076       apvPairNumber_(input.apvPairNumber()),
0077       apvWithinPair_(input.apvWithinPair()) {
0078   key(input.key());
0079   path(input.path());
0080   granularity(input.granularity());
0081 }
0082 
0083 // -----------------------------------------------------------------------------
0084 //
0085 SiStripDetKey::SiStripDetKey(const SiStripKey& input)
0086     : SiStripKey(),
0087       partition_(sistrip::invalid_),
0088       apvPairNumber_(sistrip::invalid_),
0089       apvWithinPair_(sistrip::invalid_) {
0090   const SiStripDetKey& det_key = dynamic_cast<const SiStripDetKey&>(input);
0091   key(det_key.key());
0092   path(det_key.path());
0093   granularity(det_key.granularity());
0094   partition_ = det_key.partition();
0095   apvPairNumber_ = det_key.apvPairNumber();
0096   apvWithinPair_ = det_key.apvWithinPair();
0097 }
0098 
0099 // -----------------------------------------------------------------------------
0100 //
0101 SiStripDetKey::SiStripDetKey(const SiStripKey& input, const sistrip::Granularity& gran)
0102     : SiStripKey(), partition_(0), apvPairNumber_(0), apvWithinPair_(0) {
0103   const SiStripDetKey& det_key = dynamic_cast<const SiStripDetKey&>(input);
0104   if (gran == sistrip::PARTITION) {
0105     partition_ = det_key.partition();
0106   }
0107 
0108   initFromValue();
0109   initFromKey();
0110   initFromPath();
0111   initGranularity();
0112 }
0113 
0114 // -----------------------------------------------------------------------------
0115 //
0116 SiStripDetKey::SiStripDetKey()
0117     : SiStripKey(),
0118       partition_(sistrip::invalid_),
0119       apvPairNumber_(sistrip::invalid_),
0120       apvWithinPair_(sistrip::invalid_) {
0121   ;
0122 }
0123 
0124 // -----------------------------------------------------------------------------
0125 //
0126 bool SiStripDetKey::isEqual(const SiStripKey& key) const {
0127   const SiStripDetKey& input = dynamic_cast<const SiStripDetKey&>(key);
0128   if (partition_ == input.partition() && apvPairNumber_ == input.apvPairNumber() &&
0129       apvWithinPair_ == input.apvWithinPair()) {
0130     return true;
0131   } else {
0132     return false;
0133   }
0134 }
0135 
0136 // -----------------------------------------------------------------------------
0137 //
0138 bool SiStripDetKey::isConsistent(const SiStripKey& key) const {
0139   const SiStripDetKey& input = dynamic_cast<const SiStripDetKey&>(key);
0140   if (isEqual(input)) {
0141     return false;
0142   } else if ((partition_ == 0 || input.partition() == 0) && (apvPairNumber_ == 0 || input.apvPairNumber() == 0) &&
0143              (apvWithinPair_ == 0 || input.apvWithinPair() == 0)) {
0144     return true;
0145   } else {
0146     return false;
0147   }
0148 }
0149 
0150 // -----------------------------------------------------------------------------
0151 //
0152 bool SiStripDetKey::isValid() const { return isValid(sistrip::APV); }
0153 
0154 // -----------------------------------------------------------------------------
0155 //
0156 bool SiStripDetKey::isValid(const sistrip::Granularity& gran) const {
0157   if (gran == sistrip::TRACKER) {
0158     return true;
0159   } else if (gran == sistrip::UNDEFINED_GRAN || gran == sistrip::UNKNOWN_GRAN) {
0160     return false;
0161   }
0162 
0163   if (partition_ != sistrip::invalid_) {
0164     if (gran == sistrip::PARTITION) {
0165       return true;
0166     }
0167   }
0168   return false;
0169 }
0170 
0171 // -----------------------------------------------------------------------------
0172 //
0173 bool SiStripDetKey::isInvalid() const { return isInvalid(sistrip::APV); }
0174 
0175 // -----------------------------------------------------------------------------
0176 //
0177 bool SiStripDetKey::isInvalid(const sistrip::Granularity& gran) const {
0178   if (gran == sistrip::TRACKER) {
0179     return false;
0180   } else if (gran == sistrip::UNDEFINED_GRAN || gran == sistrip::UNKNOWN_GRAN) {
0181     return false;
0182   }
0183 
0184   if (partition_ == sistrip::invalid_) {
0185     if (gran == sistrip::PARTITION) {
0186       return true;
0187     }
0188   }
0189   return false;
0190 }
0191 
0192 // -----------------------------------------------------------------------------
0193 //
0194 void SiStripDetKey::initFromValue() {
0195   // partition
0196   if (partition_ > 4) {
0197     partition_ = sistrip::invalid_;
0198   }
0199 }
0200 
0201 // -----------------------------------------------------------------------------
0202 //
0203 void SiStripDetKey::initFromKey() {
0204   if (key() == sistrip::invalid32_) {
0205     // ---------- Set DetKey based on member data ----------
0206 
0207     // Initialise to null value
0208     key(0);
0209 
0210     // Extract partition
0211     if (partition_ >= 1 &&  //sistrip::PARTITION_MIN &&
0212         partition_ <= 4) {  //sistrip::PARTITION_MAX ) {
0213       key(key() | (partition_ << partitionOffset_));
0214     } else if (partition_ == 0) {
0215       key(key() | (partition_ << partitionOffset_));
0216     } else {
0217       key(key() | (partitionMask_ << partitionOffset_));
0218     }
0219 
0220   } else {
0221     // ---------- Set member data based on Det key ----------
0222 
0223     partition_ = (key() >> partitionOffset_) & partitionMask_;
0224 
0225     if (partition_ == partitionMask_) {
0226       partition_ = sistrip::invalid_;
0227     }
0228   }
0229 }
0230 
0231 // -----------------------------------------------------------------------------
0232 //
0233 void SiStripDetKey::initFromPath() {
0234   if (path() == sistrip::null_) {
0235     // ---------- Set directory path based on member data ----------
0236 
0237     std::stringstream dir;
0238 
0239     dir << sistrip::root_ << sistrip::dir_ << sistrip::detectorView_ << sistrip::dir_;
0240 
0241     // Add partition
0242     if (partition_) {
0243       dir << sistrip::partition_ << partition_ << sistrip::dir_;
0244     }
0245 
0246     std::string temp(dir.str());
0247     path(temp);
0248 
0249   } else {
0250     // ---------- Set member data based on directory path ----------
0251 
0252     partition_ = 0;
0253 
0254     // Check if root is found
0255     if (path().find(sistrip::root_) == std::string::npos) {
0256       std::string temp = path();
0257       path(std::string(sistrip::root_) + sistrip::dir_ + temp);
0258     }
0259 
0260     size_t curr = 0;  // current string position
0261     size_t next = 0;  // next string position
0262     next = path().find(sistrip::detectorView_, curr);
0263 
0264     // Extract view
0265     curr = next;
0266     if (curr != std::string::npos) {
0267       next = path().find(sistrip::partition_, curr);
0268       std::string detector_view(
0269           path(), curr + (sizeof(sistrip::detectorView_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0270       // Extract partition
0271       curr = next;
0272       if (curr != std::string::npos) {
0273         next = std::string::npos;
0274         std::string partition(
0275             path(), curr + (sizeof(sistrip::partition_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0276         partition_ = std::atoi(partition.c_str());
0277       }
0278     } else {
0279       std::stringstream ss;
0280       ss << sistrip::root_ << sistrip::dir_;
0281       //ss << sistrip::root_ << sistrip::dir_
0282       //<< sistrip::unknownView_ << sistrip::dir_;
0283       std::string temp(ss.str());
0284       path(temp);
0285     }
0286   }
0287 }
0288 
0289 // -----------------------------------------------------------------------------
0290 //
0291 void SiStripDetKey::initGranularity() {
0292   granularity(sistrip::TRACKER);
0293   channel(0);
0294   if (partition_ && partition_ != sistrip::invalid_) {
0295     granularity(sistrip::PARTITION);
0296     channel(partition_);
0297   } else if (partition_ == sistrip::invalid_) {
0298     granularity(sistrip::UNKNOWN_GRAN);
0299     channel(sistrip::invalid_);
0300   }
0301 }
0302 
0303 // -----------------------------------------------------------------------------
0304 //
0305 void SiStripDetKey::terse(std::stringstream& ss) const { ss << "DET:partition= " << partition(); }
0306 
0307 // -----------------------------------------------------------------------------
0308 //
0309 void SiStripDetKey::print(std::stringstream& ss) const {
0310   ss << " [SiStripDetKey::print]" << std::endl
0311      << std::hex << " 32-bit Det key : 0x" << std::setfill('0') << std::setw(8) << key() << std::endl
0312      << std::setfill(' ') << std::dec << " Partition      : " << partition() << std::endl
0313      << " Directory      : " << path() << std::endl
0314      << " Granularity    : " << SiStripEnumsAndStrings::granularity(granularity()) << std::endl
0315      << " Channel        : " << channel() << std::endl
0316      << " isValid        : " << isValid();
0317 }
0318 
0319 // -----------------------------------------------------------------------------
0320 //
0321 std::ostream& operator<<(std::ostream& os, const SiStripDetKey& input) {
0322   std::stringstream ss;
0323   input.print(ss);
0324   os << ss.str();
0325   return os;
0326 }