Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // system includes
0002 #include <sstream>
0003 
0004 // user includes
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0007 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0008 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 
0013 /**
0014    @class testSiStripFecKey 
0015    @author R.Bainbridge
0016    @brief Simple class that tests SiStripFecKey.
0017 */
0018 class testSiStripFecKey : public edm::one::EDAnalyzer<> {
0019 public:
0020   testSiStripFecKey(const edm::ParameterSet&);
0021   ~testSiStripFecKey();
0022 
0023   void beginJob();
0024   void analyze(const edm::Event&, const edm::EventSetup&);
0025 
0026 private:
0027   const uint32_t crate_;
0028   const uint32_t slot_;
0029   const uint32_t ring_;
0030   const uint32_t ccu_;
0031   const uint32_t module_;
0032   const uint32_t lld_;
0033   const uint32_t i2c_;
0034 };
0035 
0036 using namespace sistrip;
0037 
0038 // -----------------------------------------------------------------------------
0039 //
0040 testSiStripFecKey::testSiStripFecKey(const edm::ParameterSet& pset)
0041     : crate_(pset.getUntrackedParameter<uint32_t>("CRATE", sistrip::invalid32_)),
0042       slot_(pset.getUntrackedParameter<uint32_t>("SLOT", sistrip::invalid32_)),
0043       ring_(pset.getUntrackedParameter<uint32_t>("RING", sistrip::invalid32_)),
0044       ccu_(pset.getUntrackedParameter<uint32_t>("CCU", sistrip::invalid32_)),
0045       module_(pset.getUntrackedParameter<uint32_t>("MODULE", sistrip::invalid32_)),
0046       lld_(pset.getUntrackedParameter<uint32_t>("LLD", sistrip::invalid32_)),
0047       i2c_(pset.getUntrackedParameter<uint32_t>("I2C", sistrip::invalid32_)) {
0048   LogTrace(mlDqmCommon_) << "[testSiStripFecKey::" << __func__ << "]"
0049                          << " Constructing object...";
0050 }
0051 
0052 // -----------------------------------------------------------------------------
0053 //
0054 testSiStripFecKey::~testSiStripFecKey() {
0055   LogTrace(mlDqmCommon_) << "[testSiStripFecKey::" << __func__ << "]"
0056                          << " Destructing object...";
0057 }
0058 
0059 // -----------------------------------------------------------------------------
0060 //
0061 void testSiStripFecKey::beginJob() {
0062   uint32_t cntr = 0;
0063   std::vector<uint32_t> keys;
0064 
0065   // simple loop
0066   for (uint16_t iloop = 0; iloop < 1; iloop++) {
0067     // FEC crates
0068     for (uint16_t icrate = 0; icrate <= sistrip::FEC_CRATE_MAX + 1; icrate++) {
0069       if (icrate > 1 && icrate < sistrip::FEC_CRATE_MAX) {
0070         continue;
0071       }
0072 
0073       // FEC slots
0074       for (uint16_t ifec = 0; ifec <= sistrip::SLOTS_PER_CRATE + 1; ifec++) {
0075         if (ifec > 1 && ifec < sistrip::SLOTS_PER_CRATE) {
0076           continue;
0077         }
0078 
0079         // FEC rings
0080         for (uint16_t iring = 0; iring <= sistrip::FEC_RING_MAX + 1; iring++) {
0081           if (iring > 1 && iring < sistrip::FEC_RING_MAX) {
0082             continue;
0083           }
0084 
0085           // CCU addr
0086           for (uint16_t iccu = 0; iccu <= sistrip::CCU_ADDR_MAX + 1; iccu++) {
0087             if (iccu > 1 && iccu < sistrip::CCU_ADDR_MAX) {
0088               continue;
0089             }
0090 
0091             // CCU channel
0092             for (uint16_t ichan = 0; ichan <= sistrip::CCU_CHAN_MAX + 1; ichan++) {
0093               if (ichan > 1 && ichan != sistrip::CCU_CHAN_MIN && ichan < sistrip::CCU_CHAN_MAX - 1) {
0094                 continue;
0095               }
0096 
0097               // LLD channels
0098               for (uint16_t illd = 0; illd <= sistrip::LLD_CHAN_MAX + 1; illd++) {
0099                 if (illd > 1 && illd < sistrip::LLD_CHAN_MAX) {
0100                   continue;
0101                 }
0102 
0103                 // APV
0104                 for (uint16_t iapv = 0; iapv <= sistrip::APV_I2C_MAX + 1; iapv++) {
0105                   if (iapv > 1 && iapv != sistrip::APV_I2C_MIN && iapv < sistrip::APV_I2C_MAX) {
0106                     continue;
0107                   }
0108 
0109                   cntr++;
0110 
0111                   SiStripFecKey tmp1(icrate, ifec, iring, iccu, ichan, illd, iapv);
0112                   SiStripFecKey tmp2 = SiStripFecKey(tmp1.key());
0113                   SiStripFecKey tmp3 = SiStripFecKey(tmp1.path());
0114                   SiStripFecKey tmp4 = SiStripFecKey(tmp1);
0115                   SiStripFecKey tmp5;
0116                   tmp5 = tmp1;
0117 
0118                   keys.push_back(tmp1.key());
0119 
0120                   // Print out FEC
0121                   std::stringstream ss;
0122                   ss << "[SiStripFecKey::" << __func__ << "]" << std::endl
0123                      << " From loop   : "
0124                      << "FEC:crate/slot/ring/CCU/module/LLD/I2C= " << icrate << "/" << ifec << "/" << iring << "/"
0125                      << iccu << "/" << ichan << "/" << illd << "/" << iapv << std::endl
0126                      << " From values : ";
0127                   tmp1.terse(ss);
0128                   ss << std::endl << " From key    : ";
0129                   tmp1.terse(ss);
0130                   ss << std::endl << " From dir    : ";
0131                   tmp1.terse(ss);
0132                   ss << std::endl
0133                      << " Granularity : " << SiStripEnumsAndStrings::granularity(tmp1.granularity()) << std::endl
0134                      << " Directory   : " << tmp1.path() << std::endl
0135                      << std::boolalpha << " isValid     : " << tmp1.isValid() << "/" << tmp1.isValid(tmp1.granularity())
0136                      << "/" << tmp1.isValid(sistrip::APV) << " (general/granularity/apv)" << std::endl
0137                      << " isInvalid   : " << tmp1.isInvalid() << "/" << tmp1.isInvalid(tmp1.granularity()) << "/"
0138                      << tmp1.isInvalid(sistrip::APV) << " (general/granularity/apv)" << std::endl
0139                      << std::noboolalpha;
0140 
0141                   if (tmp1.isValid()) {
0142                     edm::LogVerbatim(mlDqmCommon_) << ss.str();
0143                   } else {
0144                     LogTrace(mlDqmCommon_) << ss.str();
0145                   }
0146                 }
0147               }
0148             }
0149           }
0150         }
0151       }
0152     }
0153   }
0154 
0155   edm::LogVerbatim(mlDqmCommon_) << "[SiStripFecKey::" << __func__ << "]"
0156                                  << " Processed " << cntr << " FED keys";
0157 
0158   std::sort(keys.begin(), keys.end());
0159 
0160   SiStripFecKey value(crate_, slot_, ring_, ccu_, module_, lld_, i2c_);
0161 
0162   typedef std::vector<uint32_t>::iterator iter;
0163   std::pair<iter, iter> temp = std::equal_range(keys.begin(), keys.end(), value.key(), ConsistentWithKey(value));
0164 
0165   if (temp.first != temp.second) {
0166     std::stringstream ss;
0167     ss << std::endl;
0168     for (iter ii = temp.first; ii != temp.second; ++ii) {
0169       SiStripFecKey(*ii).terse(ss);
0170       ss << std::endl;
0171     }
0172     LogTrace(mlDqmCommon_) << "[SiStripFecKey::" << __func__ << "]"
0173                            << " Beginning of list of matched keys: " << ss.str() << "[SiStripFecKey::" << __func__
0174                            << "]"
0175                            << " End of list of matched keys: ";
0176   }
0177 
0178   if (find(keys.begin(), keys.end(), value.key()) != keys.end()) {
0179     std::stringstream ss;
0180     ss << "[SiStripFecKey::" << __func__ << "]"
0181        << " Found key ";
0182     value.terse(ss);
0183     ss << " in list! ";
0184     LogTrace(mlDqmCommon_) << ss.str();
0185   }
0186 
0187   edm::LogVerbatim(mlDqmCommon_) << "[SiStripFecKey::" << __func__ << "]" << std::endl
0188                                  << " Total number of keys   : " << keys.size() << std::endl
0189                                  << " Number of matching key : " << temp.second - temp.first;
0190 }
0191 
0192 // -----------------------------------------------------------------------------
0193 //
0194 void testSiStripFecKey::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0195   LogTrace(mlDqmCommon_) << "[SiStripFecKey::" << __func__ << "]"
0196                          << " Analyzing run/event " << event.id().run() << "/" << event.id().event();
0197 }
0198 
0199 #include "FWCore/Framework/interface/MakerMacros.h"
0200 DEFINE_FWK_MODULE(testSiStripFecKey);