Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:39

0001 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <iomanip>
0005 #include <string>
0006 
0007 using namespace sistrip;
0008 
0009 // -----------------------------------------------------------------------------
0010 //
0011 FedChannelConnection::FedChannelConnection(const uint16_t& fec_crate,
0012                                            const uint16_t& fec_slot,
0013                                            const uint16_t& fec_ring,
0014                                            const uint16_t& ccu_addr,
0015                                            const uint16_t& ccu_chan,
0016                                            const uint16_t& apv0,
0017                                            const uint16_t& apv1,
0018                                            const uint32_t& dcu_id,
0019                                            const uint32_t& det_id,
0020                                            const uint16_t& pairs,
0021                                            const uint16_t& fed_id,
0022                                            const uint16_t& fed_ch,
0023                                            const uint16_t& length,
0024                                            const bool& dcu,
0025                                            const bool& pll,
0026                                            const bool& mux,
0027                                            const bool& lld)
0028     : fecCrate_(fec_crate),
0029       fecSlot_(fec_slot),
0030       fecRing_(fec_ring),
0031       ccuAddr_(ccu_addr),
0032       ccuChan_(ccu_chan),
0033       apv0_(apv0),
0034       apv1_(apv1),
0035       dcuId_(dcu_id),
0036       detId_(det_id),
0037       nApvPairs_(pairs),
0038       fedCrate_(sistrip::invalid_),
0039       fedSlot_(sistrip::invalid_),
0040       fedId_(fed_id),
0041       fedCh_(fed_ch),
0042       length_(length),
0043       dcu0x00_(dcu),
0044       mux0x43_(mux),
0045       pll0x44_(pll),
0046       lld0x60_(lld) {
0047   ;
0048 }
0049 
0050 // -----------------------------------------------------------------------------
0051 //
0052 FedChannelConnection::FedChannelConnection()
0053     : fecCrate_(sistrip::invalid_),
0054       fecSlot_(sistrip::invalid_),
0055       fecRing_(sistrip::invalid_),
0056       ccuAddr_(sistrip::invalid_),
0057       ccuChan_(sistrip::invalid_),
0058       apv0_(sistrip::invalid_),
0059       apv1_(sistrip::invalid_),
0060       dcuId_(sistrip::invalid32_),
0061       detId_(sistrip::invalid32_),
0062       nApvPairs_(sistrip::invalid_),
0063       fedCrate_(sistrip::invalid_),
0064       fedSlot_(sistrip::invalid_),
0065       fedId_(sistrip::invalid_),
0066       fedCh_(sistrip::invalid_),
0067       length_(sistrip::invalid_),
0068       dcu0x00_(false),
0069       mux0x43_(false),
0070       pll0x44_(false),
0071       lld0x60_(false) {
0072   ;
0073 }
0074 
0075 // -----------------------------------------------------------------------------
0076 //
0077 bool operator<(const FedChannelConnection& conn1, const FedChannelConnection& conn2) {
0078   if (conn1.fedId() < conn2.fedId()) {
0079     return true;
0080   } else if (conn1.fedId() == conn2.fedId()) {
0081     return (conn1.fedCh() < conn2.fedCh() ? true : false);
0082   } else {
0083     return false;
0084   }
0085 }
0086 
0087 // -----------------------------------------------------------------------------
0088 //
0089 const uint16_t& FedChannelConnection::i2cAddr(const uint16_t& apv) const {
0090   if (apv == 0) {
0091     return apv0_;
0092   } else if (apv == 1) {
0093     return apv1_;
0094   } else {
0095     if (edm::isDebugEnabled()) {
0096       edm::LogWarning(mlCabling_) << "[FedChannelConnection::" << __func__ << "]"
0097                                   << " Unexpected APV I2C address!" << apv;
0098     }
0099     static const uint16_t i2c_addr = 0;
0100     return i2c_addr;
0101   }
0102 }
0103 
0104 // -----------------------------------------------------------------------------
0105 //
0106 uint16_t FedChannelConnection::lldChannel() const {
0107   if (apv0_ == 32 || apv1_ == 33) {
0108     return 1;
0109   } else if (apv0_ == 34 || apv1_ == 35) {
0110     return 2;
0111   } else if (apv0_ == 36 || apv1_ == 37) {
0112     return 3;
0113   } else if (apv0_ != sistrip::invalid_ || apv1_ != sistrip::invalid_) {
0114     if (edm::isDebugEnabled()) {
0115       edm::LogWarning(mlCabling_) << "[FedChannelConnection::" << __func__ << "]"
0116                                   << " Unexpected APV I2C addresses!"
0117                                   << " Apv0: " << apv0_ << " Apv1: " << apv1_;
0118     }
0119   }
0120   return sistrip::invalid_;
0121 }
0122 
0123 // -----------------------------------------------------------------------------
0124 /** */
0125 uint16_t FedChannelConnection::apvPairNumberDebug() const {
0126   if (nApvPairs_ == 2) {
0127     if (apv0_ == 32 || apv1_ == 33) {
0128       return 0;
0129     } else if (apv0_ == 36 || apv1_ == 37) {
0130       return 1;
0131     } else {
0132       if (edm::isDebugEnabled()) {
0133         edm::LogWarning(mlCabling_) << "[FedChannelConnection::" << __func__ << "]"
0134                                     << " APV I2C addresses (" << apv0_ << "/" << apv1_ << ") are incompatible with"
0135                                     << " number of APV pairs (" << nApvPairs_ << ") found for this module!";
0136       }
0137     }
0138   } else if (nApvPairs_ == 3) {
0139     if (apv0_ == 32 || apv1_ == 33) {
0140       return 0;
0141     } else if (apv0_ == 34 || apv1_ == 35) {
0142       return 1;
0143     } else if (apv0_ == 36 || apv1_ == 37) {
0144       return 2;
0145     } else {
0146       if (edm::isDebugEnabled()) {
0147         edm::LogWarning(mlCabling_) << "[FedChannelConnection::" << __func__ << "]"
0148                                     << " APV I2C addresses (" << apv0_ << "/" << apv1_ << ") are incompatible with"
0149                                     << " number of APV pairs (" << nApvPairs_ << ") found for this module!";
0150       }
0151     }
0152   } else {
0153     if (edm::isDebugEnabled()) {
0154       edm::LogWarning(mlCabling_) << "[FedChannelConnection::" << __func__ << "]"
0155                                   << " Unexpected number of APV pairs: " << nApvPairs_;
0156     }
0157   }
0158   return sistrip::invalid_;
0159 }
0160 
0161 // -----------------------------------------------------------------------------
0162 //
0163 void FedChannelConnection::print(std::stringstream& ss) const {
0164   ss << " [FedChannelConnection::" << __func__ << "]" << std::endl
0165      << " FedCrate/FedSlot/FedId/FeUnit/FeChan/FedCh : " << fedCrate() << "/" << fedSlot() << "/" << fedId() << "/"
0166      << SiStripFedKey::feUnit(fedCh()) << "/" << SiStripFedKey::feChan(fedCh()) << "/" << fedCh() << std::endl
0167      << " FecCrate/FecSlot/FecRing/CcuAddr/CcuChan   : " << fecCrate() << "/" << fecSlot() << "/" << fecRing() << "/"
0168      << ccuAddr() << "/" << ccuChan() << std::endl
0169      << " DcuId/DetId                                : " << std::hex << "0x" << std::setfill('0') << std::setw(8)
0170      << dcuId() << "/"
0171      << "0x" << std::setfill('0') << std::setw(8) << detId() << std::endl
0172      << std::dec << " LldChan/APV0/APV1                          : " << lldChannel() << "/" << i2cAddr(0) << "/"
0173      << i2cAddr(1) << std::endl
0174      << " pairNumber/nPairs/nStrips                  : " << apvPairNumber() << "/" << nApvPairs() << "/"
0175      << 256 * nApvPairs() << std::endl
0176      << " DCU/MUX/PLL/LLD found                      : " << std::boolalpha << dcu() << "/" << mux() << "/" << pll()
0177      << "/" << lld() << std::noboolalpha;
0178 }
0179 
0180 // -----------------------------------------------------------------------------
0181 //
0182 void FedChannelConnection::terse(std::stringstream& ss) const {
0183   ss << " FED:cr/sl/id/fe/ch/chan=" << fedCrate() << "/" << fedSlot() << "/" << fedId() << "/"
0184      << SiStripFedKey::feUnit(fedCh()) << "/" << SiStripFedKey::feChan(fedCh()) << "/" << fedCh() << ","
0185      << " FEC:cr/sl/ring/ccu/mod=" << fecCrate() << "/" << fecSlot() << "/" << fecRing() << "/" << ccuAddr() << "/"
0186      << ccuChan() << ","
0187      << " apvs=" << i2cAddr(0) << "/" << i2cAddr(1) << ","
0188      << " pair=" << apvPairNumber() + 1 << " (from " << nApvPairs() << "),"
0189      << " dcu/detid=" << std::hex << "0x" << std::setfill('0') << std::setw(8) << dcuId() << "/"
0190      << "0x" << std::setfill('0') << std::setw(8) << detId() << std::dec;
0191 }
0192 
0193 // -----------------------------------------------------------------------------
0194 //
0195 std::ostream& operator<<(std::ostream& os, const FedChannelConnection& conn) {
0196   std::stringstream ss;
0197   conn.print(ss);
0198   os << ss.str();
0199   return os;
0200 }