Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:53

0001 // system includes
0002 #include <iostream>
0003 #include <stdio.h>
0004 #include <sys/time.h>
0005 #include <sstream>
0006 
0007 // user include files
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0016 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
0017 
0018 class testSiStripQualityESProducer : public edm::one::EDAnalyzer<> {
0019 public:
0020   explicit testSiStripQualityESProducer(const edm::ParameterSet&);
0021   ~testSiStripQualityESProducer() = default;
0022 
0023   void analyze(const edm::Event&, const edm::EventSetup&);
0024 
0025 private:
0026   void printObject(const SiStripQuality*);
0027 
0028   const edm::ESGetToken<SiStripQuality, SiStripQualityRcd> qualityToken_;
0029   const edm::ESGetToken<SiStripQuality, SiStripQualityRcd> qualityTokenTwo_;
0030   bool printdebug_;
0031   unsigned long long m_cacheID_;
0032   bool firstIOV;
0033   bool twoRecordComparison_;
0034   SiStripQuality* m_Quality_;
0035 };
0036 
0037 testSiStripQualityESProducer::testSiStripQualityESProducer(const edm::ParameterSet& iConfig)
0038     : qualityToken_(esConsumes(edm::ESInputTag("", iConfig.getUntrackedParameter<std::string>("dataLabel", "")))),
0039       qualityTokenTwo_(esConsumes(edm::ESInputTag("", iConfig.getUntrackedParameter<std::string>("dataLabelTwo", "")))),
0040       printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", false)),
0041       m_cacheID_(0),
0042       firstIOV(true),
0043       twoRecordComparison_(iConfig.getUntrackedParameter<bool>("twoRecordComparison", false)) {}
0044 
0045 void testSiStripQualityESProducer::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
0046   unsigned long long cacheID = iSetup.get<SiStripQualityRcd>().cacheIdentifier();
0047 
0048   if (m_cacheID_ == cacheID)
0049     return;
0050 
0051   m_cacheID_ = cacheID;
0052 
0053   char canvas[1024] = "\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n";
0054 
0055   //&&&&&&&&&&&&&&&&&&
0056   //First Record
0057   //&&&&&&&&&&&&&&&&&&
0058   edm::ESHandle<SiStripQuality> SiStripQualityESH_ = iSetup.getHandle(qualityToken_);
0059   edm::LogInfo("testSiStripQualityESProducer")
0060       << canvas << "[testSiStripQualityESProducer::analyze] Print SiStripQualityRecord" << canvas << std::endl;
0061   printObject(SiStripQualityESH_.product());
0062 
0063   //&&&&&&&&&&&&&&&&&&
0064   //Second Record
0065   //&&&&&&&&&&&&&&&&&&
0066   edm::ESHandle<SiStripQuality> twoSiStripQualityESH_;
0067   if (twoRecordComparison_) {
0068     twoSiStripQualityESH_ = iSetup.getHandle(qualityTokenTwo_);
0069     edm::LogInfo("testSiStripQualityESProducer")
0070         << canvas << "[testSiStripQualityESProducer::analyze] Print Second SiStripQualityRecord" << canvas << std::endl;
0071     printObject(twoSiStripQualityESH_.product());
0072 
0073     edm::LogInfo("testSiStripQualityESProducer")
0074         << canvas << "[testSiStripQualityESProducer::analyze] Print difference (First - Second) SiStripQuality Rcd"
0075         << canvas << std::endl;
0076     const SiStripQuality& tmp1 = SiStripQualityESH_->difference(*twoSiStripQualityESH_);
0077     printObject(&tmp1);
0078     edm::LogInfo("testSiStripQualityESProducer")
0079         << canvas << "[testSiStripQualityESProducer::analyze] Print difference (Second - First) SiStripQuality Rcd"
0080         << canvas << std::endl;
0081     const SiStripQuality& tmp2 = twoSiStripQualityESH_->difference(*SiStripQualityESH_);
0082     printObject(&tmp2);
0083   }
0084 
0085   if (!firstIOV) {
0086     edm::LogInfo("testSiStripQualityESProducer")
0087         << canvas << "[testSiStripQualityESProducer::analyze] Print previous SiStripQuality Rcd " << canvas
0088         << std::endl;
0089     printObject(m_Quality_);
0090     edm::LogInfo("testSiStripQualityESProducer")
0091         << canvas << "[testSiStripQualityESProducer::analyze] Print difference (Current - Previous) SiStripQuality Rcd"
0092         << canvas << std::endl;
0093     const SiStripQuality& tmp1 = SiStripQualityESH_->difference(*m_Quality_);
0094     printObject(&tmp1);
0095     edm::LogInfo("testSiStripQualityESProducer")
0096         << canvas << "[testSiStripQualityESProducer::analyze] Print difference (Previous - Current) SiStripQuality Rcd"
0097         << canvas << std::endl;
0098     const SiStripQuality& tmp2 = m_Quality_->difference(*SiStripQualityESH_);
0099     printObject(&tmp2);
0100   }
0101 
0102   firstIOV = false;
0103   edm::LogInfo("testSiStripQualityESProducer")
0104       << "[testSiStripQualityESProducer::analyze] Constructing new object " << std::endl;
0105   m_Quality_ = new SiStripQuality(*SiStripQualityESH_);
0106 }
0107 
0108 void testSiStripQualityESProducer::printObject(const SiStripQuality* SiStripQuality_) {
0109   std::stringstream ss;
0110 
0111   SiStripBadStrip::RegistryIterator rbegin = SiStripQuality_->getRegistryVectorBegin();
0112   SiStripBadStrip::RegistryIterator rend = SiStripQuality_->getRegistryVectorEnd();
0113   uint32_t detid;
0114 
0115   if (rbegin == rend)
0116     return;
0117 
0118   for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
0119     detid = rp->detid;
0120     SiStripBadStrip::Range range = SiStripBadStrip::Range(SiStripQuality_->getDataVectorBegin() + rp->ibegin,
0121                                                           SiStripQuality_->getDataVectorBegin() + rp->iend);
0122 
0123     SiStripBadStrip::ContainerIterator it = range.first;
0124     ss << "Full Info";
0125 
0126     for (; it != range.second; ++it) {
0127       unsigned int value = (*it);
0128 
0129       ss << "\n\tdetid " << detid << " \t"
0130          << " firstBadStrip " << SiStripQuality_->decode(value).firstStrip << "\t "
0131          << " NconsecutiveBadStrips " << SiStripQuality_->decode(value).range << "\t "
0132          << " flag " << SiStripQuality_->decode(value).flag << "\t "
0133          << " packed integer 0x" << std::hex << value << std::dec << "\t ";
0134     }
0135 
0136     ss << "\n\nDetBase Info\n\t  IsModuleBad()=" << SiStripQuality_->IsModuleBad(detid)
0137        << "\t IsFiberBad(n)=" << SiStripQuality_->IsFiberBad(detid, 0) << " " << SiStripQuality_->IsFiberBad(detid, 1)
0138        << " " << SiStripQuality_->IsFiberBad(detid, 2) << "\t getBadFibers()=" << SiStripQuality_->getBadFibers(detid)
0139        << "\t IsApvBad()=" << SiStripQuality_->IsApvBad(detid, 0) << " " << SiStripQuality_->IsApvBad(detid, 1) << " "
0140        << SiStripQuality_->IsApvBad(detid, 2) << " " << SiStripQuality_->IsApvBad(detid, 3) << " "
0141        << SiStripQuality_->IsApvBad(detid, 4) << " " << SiStripQuality_->IsApvBad(detid, 5)
0142        << "\t getBadApvs()=" << SiStripQuality_->getBadApvs(detid);
0143     ss << "\n--------------------------------------------------\n";
0144   }
0145   ss << "\nGlobal Info";
0146   std::vector<SiStripQuality::BadComponent> BC = SiStripQuality_->getBadComponentList();
0147   ss << "\n\t detid \t IsModuleBad \t BadFibers \t BadApvs";
0148 
0149   for (size_t i = 0; i < BC.size(); ++i)
0150     ss << "\n\t" << BC[i].detid << "\t " << BC[i].BadModule << "\t " << BC[i].BadFibers << "\t " << BC[i].BadApvs
0151        << "\t ";
0152   ss << std::endl;
0153 
0154   edm::LogInfo("testSiStripQualityESProducer") << ss.str();
0155 }
0156 
0157 #include "FWCore/PluginManager/interface/ModuleDef.h"
0158 #include "FWCore/Framework/interface/MakerMacros.h"
0159 
0160 DEFINE_FWK_MODULE(testSiStripQualityESProducer);