Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:44

0001 
0002 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0003 #include "DataFormats/SiStripCommon/interface/SiStripNullKey.h"
0004 #include "DataFormats/SiStripCommon/interface/Constants.h"
0005 #include "DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h"
0006 #include "DataFormats/SiStripCommon/interface/ConstantsForDqm.h"
0007 #include "DataFormats/SiStripCommon/interface/ConstantsForView.h"
0008 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0009 #include <iomanip>
0010 
0011 // -----------------------------------------------------------------------------
0012 //
0013 SiStripFecKey::SiStripFecKey(const uint16_t& fec_crate,
0014                              const uint16_t& fec_slot,
0015                              const uint16_t& fec_ring,
0016                              const uint16_t& ccu_addr,
0017                              const uint16_t& ccu_chan,
0018                              const uint16_t& lld_chan,
0019                              const uint16_t& i2c_addr)
0020     : SiStripKey(),
0021       fecCrate_(fec_crate),
0022       fecSlot_(fec_slot),
0023       fecRing_(fec_ring),
0024       ccuAddr_(ccu_addr),
0025       ccuChan_(ccu_chan),
0026       lldChan_(lld_chan),
0027       i2cAddr_(i2c_addr) {
0028   // order is important!
0029   initFromValue();
0030   initFromKey();
0031   initFromPath();
0032   initGranularity();
0033 }
0034 
0035 // -----------------------------------------------------------------------------
0036 //
0037 SiStripFecKey::SiStripFecKey(const uint32_t& fec_key)
0038     : SiStripKey(fec_key),
0039       fecCrate_(sistrip::invalid_),
0040       fecSlot_(sistrip::invalid_),
0041       fecRing_(sistrip::invalid_),
0042       ccuAddr_(sistrip::invalid_),
0043       ccuChan_(sistrip::invalid_),
0044       lldChan_(sistrip::invalid_),
0045       i2cAddr_(sistrip::invalid_) {
0046   // order is important!
0047   initFromKey();
0048   initFromValue();
0049   initFromPath();
0050   initGranularity();
0051 }
0052 
0053 // -----------------------------------------------------------------------------
0054 //
0055 SiStripFecKey::SiStripFecKey(const std::string& path)
0056     : SiStripKey(path),
0057       fecCrate_(sistrip::invalid_),
0058       fecSlot_(sistrip::invalid_),
0059       fecRing_(sistrip::invalid_),
0060       ccuAddr_(sistrip::invalid_),
0061       ccuChan_(sistrip::invalid_),
0062       lldChan_(sistrip::invalid_),
0063       i2cAddr_(sistrip::invalid_) {
0064   // order is important!
0065   initFromPath();
0066   initFromValue();
0067   initFromKey();
0068   initGranularity();
0069 }
0070 
0071 // -----------------------------------------------------------------------------
0072 //
0073 SiStripFecKey::SiStripFecKey(const SiStripFecKey& input)
0074     : SiStripKey(),
0075       fecCrate_(input.fecCrate()),
0076       fecSlot_(input.fecSlot()),
0077       fecRing_(input.fecRing()),
0078       ccuAddr_(input.ccuAddr()),
0079       ccuChan_(input.ccuChan()),
0080       lldChan_(input.lldChan()),
0081       i2cAddr_(input.i2cAddr()) {
0082   key(input.key());
0083   path(input.path());
0084   granularity(input.granularity());
0085 }
0086 
0087 // -----------------------------------------------------------------------------
0088 //
0089 SiStripFecKey::SiStripFecKey(const SiStripKey& input)
0090     : SiStripKey(),
0091       fecCrate_(sistrip::invalid_),
0092       fecSlot_(sistrip::invalid_),
0093       fecRing_(sistrip::invalid_),
0094       ccuAddr_(sistrip::invalid_),
0095       ccuChan_(sistrip::invalid_),
0096       lldChan_(sistrip::invalid_),
0097       i2cAddr_(sistrip::invalid_) {
0098   const SiStripFecKey& fec_key = dynamic_cast<const SiStripFecKey&>(input);
0099   key(fec_key.key());
0100   path(fec_key.path());
0101   granularity(fec_key.granularity());
0102   fecCrate_ = fec_key.fecCrate();
0103   fecSlot_ = fec_key.fecSlot();
0104   fecRing_ = fec_key.fecRing();
0105   ccuAddr_ = fec_key.ccuAddr();
0106   ccuChan_ = fec_key.ccuChan();
0107   lldChan_ = fec_key.lldChan();
0108   i2cAddr_ = fec_key.i2cAddr();
0109 }
0110 
0111 // -----------------------------------------------------------------------------
0112 //
0113 SiStripFecKey::SiStripFecKey(const SiStripKey& input, const sistrip::Granularity& gran)
0114     : SiStripKey(), fecCrate_(0), fecSlot_(0), fecRing_(0), ccuAddr_(0), ccuChan_(0), lldChan_(0), i2cAddr_(0) {
0115   const SiStripFecKey& fec_key = dynamic_cast<const SiStripFecKey&>(input);
0116   if (gran == sistrip::FEC_CRATE || gran == sistrip::FEC_SLOT || gran == sistrip::FEC_RING ||
0117       gran == sistrip::CCU_ADDR || gran == sistrip::CCU_CHAN || gran == sistrip::LLD_CHAN || gran == sistrip::APV) {
0118     fecCrate_ = fec_key.fecCrate();
0119   }
0120 
0121   if (gran == sistrip::FEC_SLOT || gran == sistrip::FEC_RING || gran == sistrip::CCU_ADDR ||
0122       gran == sistrip::CCU_CHAN || gran == sistrip::LLD_CHAN || gran == sistrip::APV) {
0123     fecSlot_ = fec_key.fecSlot();
0124   }
0125 
0126   if (gran == sistrip::FEC_RING || gran == sistrip::CCU_ADDR || gran == sistrip::CCU_CHAN ||
0127       gran == sistrip::LLD_CHAN || gran == sistrip::APV) {
0128     fecRing_ = fec_key.fecRing();
0129   }
0130 
0131   if (gran == sistrip::CCU_ADDR || gran == sistrip::CCU_CHAN || gran == sistrip::LLD_CHAN || gran == sistrip::APV) {
0132     ccuAddr_ = fec_key.ccuAddr();
0133   }
0134 
0135   if (gran == sistrip::CCU_CHAN || gran == sistrip::LLD_CHAN || gran == sistrip::APV) {
0136     ccuChan_ = fec_key.ccuChan();
0137   }
0138 
0139   if (gran == sistrip::LLD_CHAN || gran == sistrip::APV) {
0140     lldChan_ = fec_key.lldChan();
0141   }
0142 
0143   if (gran == sistrip::APV) {
0144     i2cAddr_ = fec_key.i2cAddr();
0145   }
0146 
0147   initFromValue();
0148   initFromKey();
0149   initFromPath();
0150   initGranularity();
0151 }
0152 
0153 // -----------------------------------------------------------------------------
0154 //
0155 SiStripFecKey::SiStripFecKey()
0156     : SiStripKey(),
0157       fecCrate_(sistrip::invalid_),
0158       fecSlot_(sistrip::invalid_),
0159       fecRing_(sistrip::invalid_),
0160       ccuAddr_(sistrip::invalid_),
0161       ccuChan_(sistrip::invalid_),
0162       lldChan_(sistrip::invalid_),
0163       i2cAddr_(sistrip::invalid_) {
0164   ;
0165 }
0166 
0167 // -----------------------------------------------------------------------------
0168 //
0169 uint16_t SiStripFecKey::hybridPos(const uint16_t& i2c_addr) {
0170   if (i2c_addr < sistrip::APV_I2C_MIN || i2c_addr > sistrip::APV_I2C_MAX) {
0171     return sistrip::invalid_;
0172   }
0173   return (i2c_addr - sistrip::APV_I2C_MIN + 1);
0174 }
0175 
0176 // -----------------------------------------------------------------------------
0177 //
0178 uint16_t SiStripFecKey::i2cAddr(const uint16_t& hybrid_pos) {
0179   if (!hybrid_pos || hybrid_pos > (sistrip::APV_I2C_MAX - sistrip::APV_I2C_MIN + 1)) {
0180     return sistrip::invalid_;
0181   }
0182   return (hybrid_pos + sistrip::APV_I2C_MIN - 1);
0183 }
0184 
0185 // -----------------------------------------------------------------------------
0186 //
0187 uint16_t SiStripFecKey::i2cAddr(const uint16_t& lld_chan, const bool& first_apv) {
0188   if (lld_chan < sistrip::LLD_CHAN_MIN || lld_chan > sistrip::LLD_CHAN_MAX) {
0189     return sistrip::invalid_;
0190   }
0191   return (sistrip::APV_I2C_MIN + lld_chan * sistrip::APVS_PER_CHAN - (first_apv ? 2 : 1));
0192 }
0193 
0194 // -----------------------------------------------------------------------------
0195 //
0196 uint16_t SiStripFecKey::lldChan(const uint16_t& i2c_addr) {
0197   if (i2c_addr == 0) {
0198     return 0;
0199   } else if (i2c_addr < sistrip::APV_I2C_MIN || i2c_addr > sistrip::APV_I2C_MAX) {
0200     return sistrip::invalid_;
0201   }
0202   return ((i2c_addr - sistrip::APV_I2C_MIN) / 2 + 1);
0203 }
0204 
0205 // -----------------------------------------------------------------------------
0206 //
0207 bool SiStripFecKey::firstApvOfPair(const uint16_t& i2c_addr) {
0208   if (i2c_addr < sistrip::APV_I2C_MIN || i2c_addr > sistrip::APV_I2C_MAX) {
0209     return sistrip::invalid_;
0210   }
0211   return (((i2c_addr - sistrip::APV_I2C_MIN) % 2) == 0);
0212 }
0213 
0214 // -----------------------------------------------------------------------------
0215 //
0216 bool SiStripFecKey::isEqual(const SiStripKey& key) const {
0217   const SiStripFecKey& input = dynamic_cast<const SiStripFecKey&>(key);
0218   if (fecCrate_ == input.fecCrate() && fecSlot_ == input.fecSlot() && fecRing_ == input.fecRing() &&
0219       ccuAddr_ == input.ccuAddr() && ccuChan_ == input.ccuChan() && lldChan_ == input.lldChan() &&
0220       i2cAddr_ == input.i2cAddr()) {
0221     return true;
0222   } else {
0223     return false;
0224   }
0225 }
0226 
0227 // -----------------------------------------------------------------------------
0228 //
0229 bool SiStripFecKey::isConsistent(const SiStripKey& key) const {
0230   const SiStripFecKey& input = dynamic_cast<const SiStripFecKey&>(key);
0231   if (isEqual(input)) {
0232     return true;
0233   } else if ((fecCrate_ == 0 || input.fecCrate() == 0) && (fecSlot_ == 0 || input.fecSlot() == 0) &&
0234              (fecRing_ == 0 || input.fecRing() == 0) && (ccuAddr_ == 0 || input.ccuAddr() == 0) &&
0235              (lldChan_ == 0 || input.lldChan() == 0) && (i2cAddr_ == 0 || input.i2cAddr() == 0)) {
0236     return true;
0237   } else {
0238     return false;
0239   }
0240 }
0241 
0242 // -----------------------------------------------------------------------------
0243 //
0244 bool SiStripFecKey::isValid() const { return isValid(sistrip::APV); }
0245 
0246 // -----------------------------------------------------------------------------
0247 //
0248 bool SiStripFecKey::isValid(const sistrip::Granularity& gran) const {
0249   if (gran == sistrip::FEC_SYSTEM) {
0250     return true;
0251   } else if (gran == sistrip::UNDEFINED_GRAN || gran == sistrip::UNKNOWN_GRAN) {
0252     return false;
0253   }
0254 
0255   if (fecCrate_ != sistrip::invalid_) {
0256     if (gran == sistrip::FEC_CRATE) {
0257       return true;
0258     }
0259     if (fecSlot_ != sistrip::invalid_) {
0260       if (gran == sistrip::FEC_RING) {
0261         return true;
0262       }
0263       if (fecRing_ != sistrip::invalid_) {
0264         if (gran == sistrip::FEC_RING) {
0265           return true;
0266         }
0267         if (ccuAddr_ != sistrip::invalid_) {
0268           if (gran == sistrip::CCU_ADDR) {
0269             return true;
0270           }
0271           if (ccuChan_ != sistrip::invalid_) {
0272             if (gran == sistrip::CCU_CHAN) {
0273               return true;
0274             }
0275             if (lldChan_ != sistrip::invalid_) {
0276               if (gran == sistrip::LLD_CHAN) {
0277                 return true;
0278               }
0279               if (i2cAddr_ != sistrip::invalid_) {
0280                 if (gran == sistrip::APV) {
0281                   return true;
0282                 }
0283               }
0284             }
0285           }
0286         }
0287       }
0288     }
0289   }
0290   return false;
0291 }
0292 
0293 // -----------------------------------------------------------------------------
0294 //
0295 bool SiStripFecKey::isInvalid() const { return isInvalid(sistrip::APV); }
0296 
0297 // -----------------------------------------------------------------------------
0298 //
0299 bool SiStripFecKey::isInvalid(const sistrip::Granularity& gran) const {
0300   if (gran == sistrip::FEC_SYSTEM) {
0301     return false;
0302   } else if (gran == sistrip::UNDEFINED_GRAN || gran == sistrip::UNKNOWN_GRAN) {
0303     return false;
0304   }
0305 
0306   if (fecCrate_ == sistrip::invalid_) {
0307     if (gran == sistrip::FEC_CRATE) {
0308       return true;
0309     }
0310     if (fecSlot_ == sistrip::invalid_) {
0311       if (gran == sistrip::FEC_RING) {
0312         return true;
0313       }
0314       if (fecRing_ == sistrip::invalid_) {
0315         if (gran == sistrip::FEC_RING) {
0316           return true;
0317         }
0318         if (ccuAddr_ == sistrip::invalid_) {
0319           if (gran == sistrip::CCU_ADDR) {
0320             return true;
0321           }
0322           if (ccuChan_ == sistrip::invalid_) {
0323             if (gran == sistrip::CCU_CHAN) {
0324               return true;
0325             }
0326             if (lldChan_ == sistrip::invalid_) {
0327               if (gran == sistrip::LLD_CHAN) {
0328                 return true;
0329               }
0330               if (i2cAddr_ == sistrip::invalid_) {
0331                 if (gran == sistrip::APV) {
0332                   return true;
0333                 }
0334               }
0335             }
0336           }
0337         }
0338       }
0339     }
0340   }
0341   return false;
0342 }
0343 
0344 // -----------------------------------------------------------------------------
0345 //
0346 void SiStripFecKey::initFromValue() {
0347   // FEC crate
0348   if (not((fecCrate_ >= sistrip::FEC_CRATE_MIN && fecCrate_ <= sistrip::FEC_CRATE_MAX) || (fecCrate_ == 0))) {
0349     fecCrate_ = sistrip::invalid_;
0350   }
0351 
0352   // FEC slot
0353   if (not((fecSlot_ >= sistrip::CRATE_SLOT_MIN && fecSlot_ <= sistrip::CRATE_SLOT_MAX) || (fecSlot_ == 0))) {
0354     fecSlot_ = sistrip::invalid_;
0355   }
0356 
0357   // FEC ring
0358   if (not((fecRing_ >= sistrip::FEC_RING_MIN && fecRing_ <= sistrip::FEC_RING_MAX) || (fecRing_ == 0))) {
0359     fecRing_ = sistrip::invalid_;
0360   }
0361 
0362   // CCU addr
0363   if (not((ccuAddr_ >= sistrip::CCU_ADDR_MIN && ccuAddr_ <= sistrip::CCU_ADDR_MAX) || (ccuAddr_ == 0))) {
0364     ccuAddr_ = sistrip::invalid_;
0365   }
0366 
0367   // CCU chan
0368   if (not((ccuChan_ >= sistrip::CCU_CHAN_MIN && ccuChan_ <= sistrip::CCU_CHAN_MAX) || (ccuChan_ == 0))) {
0369     ccuChan_ = sistrip::invalid_;
0370   }
0371 
0372   // LLD channel
0373   if (not((lldChan_ >= sistrip::LLD_CHAN_MIN && lldChan_ <= sistrip::LLD_CHAN_MAX) || (lldChan_ == 0))) {
0374     lldChan_ = sistrip::invalid_;
0375   }
0376 
0377   // APV I2C address
0378   if (i2cAddr_ >= sistrip::APV_I2C_MIN && i2cAddr_ <= sistrip::APV_I2C_MAX) {
0379     if (lldChan_ && lldChan(i2cAddr_) != lldChan_) {
0380       i2cAddr_ = sistrip::invalid_;
0381       key(key() | (i2cAddrMask_ << i2cAddrOffset_));
0382     }
0383   } else if (i2cAddr_ != 0) {
0384     i2cAddr_ = sistrip::invalid_;
0385   }
0386 }
0387 
0388 // -----------------------------------------------------------------------------
0389 //
0390 void SiStripFecKey::initFromKey() {
0391   if (key() == sistrip::invalid32_) {
0392     // ---------- Set FecKey based on member data ----------
0393 
0394     // Initialise to null value
0395     key(0);
0396 
0397     // Extract FEC crate
0398     if (fecCrate_ >= sistrip::FEC_CRATE_MIN && fecCrate_ <= sistrip::FEC_CRATE_MAX) {
0399       key(key() | (fecCrate_ << fecCrateOffset_));
0400     } else if (fecCrate_ == 0) {
0401       key(key() | (fecCrate_ << fecCrateOffset_));
0402     } else {
0403       key(key() | (fecCrateMask_ << fecCrateOffset_));
0404     }
0405 
0406     // Extract FEC slot
0407     if (fecSlot_ >= sistrip::CRATE_SLOT_MIN && fecSlot_ <= sistrip::CRATE_SLOT_MAX) {
0408       key(key() | (fecSlot_ << fecSlotOffset_));
0409     } else if (fecSlot_ == 0) {
0410       key(key() | (fecSlot_ << fecSlotOffset_));
0411     } else {
0412       key(key() | (fecSlotMask_ << fecSlotOffset_));
0413     }
0414 
0415     // Extract FEC ring
0416     if (fecRing_ >= sistrip::FEC_RING_MIN && fecRing_ <= sistrip::FEC_RING_MAX) {
0417       key(key() | (fecRing_ << fecRingOffset_));
0418     } else if (fecRing_ == 0) {
0419       key(key() | (fecRing_ << fecRingOffset_));
0420     } else {
0421       key(key() | (fecRingMask_ << fecRingOffset_));
0422     }
0423 
0424     // Extract CCU addr
0425     if (ccuAddr_ >= sistrip::CCU_ADDR_MIN && ccuAddr_ <= sistrip::CCU_ADDR_MAX) {
0426       key(key() | (ccuAddr_ << ccuAddrOffset_));
0427     } else if (ccuAddr_ == 0) {
0428       key(key() | (ccuAddr_ << ccuAddrOffset_));
0429     } else {
0430       key(key() | (ccuAddrMask_ << ccuAddrOffset_));
0431     }
0432 
0433     // Extract CCU chan
0434     if (ccuChan_ >= sistrip::CCU_CHAN_MIN && ccuChan_ <= sistrip::CCU_CHAN_MAX) {
0435       key(key() | ((ccuChan_ - (sistrip::CCU_CHAN_MIN - 1)) << ccuChanOffset_));
0436     } else if (ccuChan_ == 0) {
0437       key(key() | (ccuChan_ << ccuChanOffset_));
0438     } else {
0439       key(key() | (ccuChanMask_ << ccuChanOffset_));
0440     }
0441 
0442     // Extract LLD channel
0443     if (lldChan_ >= sistrip::LLD_CHAN_MIN && lldChan_ <= sistrip::LLD_CHAN_MAX) {
0444       key(key() | (lldChan_ << lldChanOffset_));
0445     } else if (lldChan_ == 0) {
0446       key(key() | (lldChan_ << lldChanOffset_));
0447     } else {
0448       key(key() | (lldChanMask_ << lldChanOffset_));
0449     }
0450 
0451     // Extract APV I2C address
0452     if (i2cAddr_ >= sistrip::APV_I2C_MIN && i2cAddr_ <= sistrip::APV_I2C_MAX) {
0453       key(key() | ((firstApvOfPair(i2cAddr_) ? 1 : 2) << i2cAddrOffset_));  // key encodes APV number (1 or 2)
0454       if (lldChan_ && lldChan(i2cAddr_) != lldChan_) {
0455         i2cAddr_ = sistrip::invalid_;
0456         key(key() | (i2cAddrMask_ << i2cAddrOffset_));
0457       }
0458     } else if (i2cAddr_ == 0) {
0459       key(key() | (i2cAddr_ << i2cAddrOffset_));
0460     } else {
0461       key(key() | (i2cAddrMask_ << i2cAddrOffset_));
0462     }
0463 
0464   } else {
0465     // ---------- Set member data based on FEC key ----------
0466 
0467     fecCrate_ = (key() >> fecCrateOffset_) & fecCrateMask_;
0468     fecSlot_ = (key() >> fecSlotOffset_) & fecSlotMask_;
0469     fecRing_ = (key() >> fecRingOffset_) & fecRingMask_;
0470     ccuAddr_ = (key() >> ccuAddrOffset_) & ccuAddrMask_;
0471     ccuChan_ = (key() >> ccuChanOffset_) & ccuChanMask_;
0472     lldChan_ = (key() >> lldChanOffset_) & lldChanMask_;
0473     i2cAddr_ = (key() >> i2cAddrOffset_) & i2cAddrMask_;
0474 
0475     if (fecCrate_ == fecCrateMask_) {
0476       fecCrate_ = sistrip::invalid_;
0477     }
0478     if (fecSlot_ == fecSlotMask_) {
0479       fecSlot_ = sistrip::invalid_;
0480     }
0481     if (fecRing_ == fecRingMask_) {
0482       fecRing_ = sistrip::invalid_;
0483     }
0484     if (ccuAddr_ == ccuAddrMask_) {
0485       ccuAddr_ = sistrip::invalid_;
0486     }
0487     if (ccuChan_ == ccuChanMask_) {
0488       ccuChan_ = sistrip::invalid_;
0489     } else if (ccuChan_) {
0490       ccuChan_ += (sistrip::CCU_CHAN_MIN - 1);
0491     }
0492     if (lldChan_ == lldChanMask_) {
0493       lldChan_ = sistrip::invalid_;
0494     }
0495     if (i2cAddr_ == i2cAddrMask_) {
0496       i2cAddr_ = sistrip::invalid_;
0497     } else if (i2cAddr_ && lldChan_ != lldChanMask_) {
0498       i2cAddr_ = i2cAddr(lldChan_, 2 - i2cAddr_);
0499     }
0500   }
0501 }
0502 
0503 // -----------------------------------------------------------------------------
0504 //
0505 void SiStripFecKey::initFromPath() {
0506   if (path() == sistrip::null_) {
0507     // ---------- Set directory path based on member data ----------
0508 
0509     std::stringstream dir;
0510 
0511     dir << sistrip::root_ << sistrip::dir_ << sistrip::controlView_ << sistrip::dir_;
0512 
0513     // Add FEC crate
0514     if (fecCrate_) {
0515       dir << sistrip::fecCrate_ << fecCrate_ << sistrip::dir_;
0516 
0517       // Add FEC slot
0518       if (fecSlot_) {
0519         dir << sistrip::fecSlot_ << fecSlot_ << sistrip::dir_;
0520 
0521         // Add FEC ring
0522         if (fecRing_) {
0523           dir << sistrip::fecRing_ << fecRing_ << sistrip::dir_;
0524 
0525           // Add CCU address
0526           if (ccuAddr_) {
0527             dir << sistrip::ccuAddr_ << ccuAddr_ << sistrip::dir_;
0528 
0529             // Add CCU channel
0530             if (ccuChan_) {
0531               dir << sistrip::ccuChan_ << ccuChan_ << sistrip::dir_;
0532 
0533               // Add LLD channel
0534               if (lldChan_) {
0535                 dir << sistrip::lldChan_ << lldChan_ << sistrip::dir_;
0536 
0537                 // Add APV I2C address
0538                 if (i2cAddr_) {
0539                   dir << sistrip::apv_ << i2cAddr_ << sistrip::dir_;
0540                 }
0541               }
0542             }
0543           }
0544         }
0545       }
0546     }
0547 
0548     std::string temp(dir.str());
0549     path(temp);
0550 
0551   } else {
0552     // ---------- Set member data based on directory path ----------
0553 
0554     fecCrate_ = 0;
0555     fecSlot_ = 0;
0556     fecRing_ = 0;
0557     ccuAddr_ = 0;
0558     ccuChan_ = 0;
0559     lldChan_ = 0;
0560     i2cAddr_ = 0;
0561 
0562     // Check if root is found
0563     if (path().find(sistrip::root_) == std::string::npos) {
0564       std::string temp = path();
0565       path(std::string(sistrip::root_) + sistrip::dir_ + temp);
0566     }
0567 
0568     size_t curr = 0;  // current string position
0569     size_t next = 0;  // next string position
0570     next = path().find(sistrip::controlView_, curr);
0571 
0572     // Extract view
0573     curr = next;
0574     if (curr != std::string::npos) {
0575       next = path().find(sistrip::fecCrate_, curr);
0576       std::string control_view(
0577           path(), curr + (sizeof(sistrip::controlView_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0578 
0579       // Extract FEC crate
0580       curr = next;
0581       if (curr != std::string::npos) {
0582         next = path().find(sistrip::fecSlot_, curr);
0583         std::string fec_crate(
0584             path(), curr + (sizeof(sistrip::fecCrate_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0585         fecCrate_ = std::atoi(fec_crate.c_str());
0586 
0587         // Extract FEC slot
0588         curr = next;
0589         if (curr != std::string::npos) {
0590           next = path().find(sistrip::fecRing_, curr);
0591           std::string fec_slot(
0592               path(), curr + (sizeof(sistrip::fecSlot_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0593           fecSlot_ = std::atoi(fec_slot.c_str());
0594 
0595           // Extract FEC ring
0596           curr = next;
0597           if (curr != std::string::npos) {
0598             next = path().find(sistrip::ccuAddr_, curr);
0599             std::string fec_ring(
0600                 path(), curr + (sizeof(sistrip::fecRing_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0601             fecRing_ = std::atoi(fec_ring.c_str());
0602 
0603             // Extract CCU address
0604             curr = next;
0605             if (curr != std::string::npos) {
0606               next = path().find(sistrip::ccuChan_, curr);
0607               std::string ccu_addr(
0608                   path(), curr + (sizeof(sistrip::ccuAddr_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0609               ccuAddr_ = std::atoi(ccu_addr.c_str());
0610 
0611               // Extract CCU channel
0612               curr = next;
0613               if (curr != std::string::npos) {
0614                 next = path().find(sistrip::lldChan_, curr);
0615                 std::string ccu_chan(
0616                     path(), curr + (sizeof(sistrip::ccuChan_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0617                 ccuChan_ = std::atoi(ccu_chan.c_str());
0618 
0619                 // Extract LLD channel
0620                 curr = next;
0621                 if (curr != std::string::npos) {
0622                   next = path().find(sistrip::apv_, curr);
0623                   std::string lld_chan(
0624                       path(), curr + (sizeof(sistrip::lldChan_) - 1), next - (sizeof(sistrip::dir_) - 1) - curr);
0625                   lldChan_ = std::atoi(lld_chan.c_str());
0626 
0627                   // Extract I2C address
0628                   curr = next;
0629                   if (curr != std::string::npos) {
0630                     next = std::string::npos;
0631                     std::string i2c_addr(path(), curr + (sizeof(sistrip::apv_) - 1), next - curr);
0632                     i2cAddr_ = std::atoi(i2c_addr.c_str());
0633                   }
0634                 }
0635               }
0636             }
0637           }
0638         }
0639       }
0640     } else {
0641       std::stringstream ss;
0642       ss << sistrip::root_ << sistrip::dir_;
0643       //ss << sistrip::root_ << sistrip::dir_
0644       //<< sistrip::unknownView_ << sistrip::dir_;
0645       std::string temp(ss.str());
0646       path(temp);
0647     }
0648   }
0649 }
0650 
0651 // -----------------------------------------------------------------------------
0652 //
0653 void SiStripFecKey::initGranularity() {
0654   granularity(sistrip::FEC_SYSTEM);
0655   channel(0);
0656   if (fecCrate_ && fecCrate_ != sistrip::invalid_) {
0657     granularity(sistrip::FEC_CRATE);
0658     channel(fecCrate_);
0659     if (fecSlot_ && fecSlot_ != sistrip::invalid_) {
0660       granularity(sistrip::FEC_SLOT);
0661       channel(fecSlot_);
0662       if (fecRing_ && fecRing_ != sistrip::invalid_) {
0663         granularity(sistrip::FEC_RING);
0664         channel(fecRing_);
0665         if (ccuAddr_ && ccuAddr_ != sistrip::invalid_) {
0666           granularity(sistrip::CCU_ADDR);
0667           channel(ccuAddr_);
0668           if (ccuChan_ && ccuChan_ != sistrip::invalid_) {
0669             granularity(sistrip::CCU_CHAN);
0670             channel(ccuChan_);
0671             if (lldChan_ && lldChan_ != sistrip::invalid_) {
0672               granularity(sistrip::LLD_CHAN);
0673               channel(lldChan_);
0674               if (i2cAddr_ && i2cAddr_ != sistrip::invalid_) {
0675                 granularity(sistrip::APV);
0676                 channel(i2cAddr_);
0677               } else if (i2cAddr_ == sistrip::invalid_) {
0678                 granularity(sistrip::UNKNOWN_GRAN);
0679                 channel(sistrip::invalid_);
0680               }
0681             } else if (lldChan_ == sistrip::invalid_) {
0682               granularity(sistrip::UNKNOWN_GRAN);
0683               channel(sistrip::invalid_);
0684             }
0685           } else if (ccuChan_ == sistrip::invalid_) {
0686             granularity(sistrip::UNKNOWN_GRAN);
0687             channel(sistrip::invalid_);
0688           }
0689         } else if (ccuAddr_ == sistrip::invalid_) {
0690           granularity(sistrip::UNKNOWN_GRAN);
0691           channel(sistrip::invalid_);
0692         }
0693       } else if (fecRing_ == sistrip::invalid_) {
0694         granularity(sistrip::UNKNOWN_GRAN);
0695         channel(sistrip::invalid_);
0696       }
0697     } else if (fecSlot_ == sistrip::invalid_) {
0698       granularity(sistrip::UNKNOWN_GRAN);
0699       channel(sistrip::invalid_);
0700     }
0701   } else if (fecCrate_ == sistrip::invalid_) {
0702     granularity(sistrip::UNKNOWN_GRAN);
0703     channel(sistrip::invalid_);
0704   }
0705 }
0706 
0707 // -----------------------------------------------------------------------------
0708 //
0709 void SiStripFecKey::terse(std::stringstream& ss) const {
0710   ss << "FEC:crate/slot/ring/CCU/module/LLD/I2C= " << fecCrate() << "/" << fecSlot() << "/" << fecRing() << "/"
0711      << ccuAddr() << "/" << ccuChan() << "/" << lldChan() << "/" << i2cAddr();
0712   //   ss << " FecKey"
0713   //     //<< "=0x"
0714   //     //<< std::hex
0715   //     //<< std::setfill('0') << std::setw(8) << key() << std::setfill(' ')
0716   //     //<< std::dec
0717   //     //<< ", " << ( isValid() ? "Valid" : "Invalid" )
0718   //      << ", Crate=" << fecCrate()
0719   //      << ", Slot=" << fecSlot()
0720   //      << ", Ring=" << fecRing()
0721   //      << ", CCU=" << ccuAddr()
0722   //      << ", module=" << ccuChan()
0723   //      << ", LLD=" << lldChan()
0724   //      << ", I2C=" << i2cAddr();
0725 }
0726 
0727 // -----------------------------------------------------------------------------
0728 //
0729 void SiStripFecKey::print(std::stringstream& ss) const {
0730   ss << " [SiStripFecKey::print]" << std::endl
0731      << std::hex << " FEC key              : 0x" << std::setfill('0') << std::setw(8) << key() << std::endl
0732      << std::setfill(' ') << std::dec << " FEC VME crate        : " << fecCrate() << std::endl
0733      << " FEC VME slot         : " << fecSlot() << std::endl
0734      << " FEC control ring     : " << fecRing() << std::endl
0735      << " CCU I2C address      : " << ccuAddr() << std::endl
0736      << " CCU chan (FE module) : " << ccuChan() << std::endl
0737      << " LaserDriver channel  : " << lldChan() << std::endl
0738      << " APV I2C address      : " << i2cAddr() << std::endl
0739      << " Directory            : " << path() << std::endl
0740      << " Granularity          : " << SiStripEnumsAndStrings::granularity(granularity()) << std::endl
0741      << " Channel              : " << channel() << std::endl
0742      << " isValid              : " << isValid();
0743 }
0744 
0745 // -----------------------------------------------------------------------------
0746 //
0747 std::ostream& operator<<(std::ostream& os, const SiStripFecKey& input) {
0748   std::stringstream ss;
0749   input.print(ss);
0750   os << ss.str();
0751   return os;
0752 }
0753 
0754 // -----------------------------------------------------------------------------
0755 //
0756 ConsistentWithKey::ConsistentWithKey(const SiStripFecKey& key)
0757     : mask_(key.fecCrate() ? sistrip::invalid_ : 0,
0758             key.fecSlot() ? sistrip::invalid_ : 0,
0759             key.fecRing() ? sistrip::invalid_ : 0,
0760             key.ccuAddr() ? sistrip::invalid_ : 0,
0761             key.ccuChan() ? sistrip::invalid_ : 0,
0762             key.lldChan() ? sistrip::invalid_ : 0,
0763             key.i2cAddr() ? sistrip::invalid_ : 0) {
0764   ;
0765 }
0766 
0767 // -----------------------------------------------------------------------------
0768 //
0769 ConsistentWithKey::ConsistentWithKey() : mask_(SiStripNullKey()) { ; }
0770 
0771 // -----------------------------------------------------------------------------
0772 //
0773 bool ConsistentWithKey::operator()(const uint32_t& a, const uint32_t& b) const {
0774   return ((a & mask_.key()) < (b & mask_.key()));
0775 }