Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-10 05:40:54

0001 // system include files
0002 #include <sstream>
0003 #include <string>
0004 #include <iostream>
0005 #include <cstdio>
0006 #include <sys/time.h>
0007 
0008 // user include files
0009 #include "CondFormats/DataRecord/interface/SiStripBadStripRcd.h"
0010 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
0011 #include "DataFormats/DetId/interface/DetId.h"
0012 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0013 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0014 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ServiceRegistry/interface/Service.h"
0021 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0022 
0023 class TrackerTopology;
0024 class SiStripBadStrip;
0025 
0026 class SiStripBadComponentsDQMServiceReader : public edm::one::EDAnalyzer<> {
0027 public:
0028   explicit SiStripBadComponentsDQMServiceReader(const edm::ParameterSet&);
0029   ~SiStripBadComponentsDQMServiceReader() override = default;
0030 
0031   void analyze(const edm::Event&, const edm::EventSetup&) override;
0032 
0033   void printError(std::stringstream& ss, const bool error, const std::string& errorText);
0034 
0035   std::string detIdToString(DetId detid, const TrackerTopology& tTopo);
0036 
0037 private:
0038   const bool printdebug_;
0039   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0040   const edm::ESGetToken<SiStripBadStrip, SiStripBadStripRcd> badStripToken_;
0041 };
0042 
0043 using namespace std;
0044 
0045 SiStripBadComponentsDQMServiceReader::SiStripBadComponentsDQMServiceReader(const edm::ParameterSet& iConfig)
0046     : printdebug_(iConfig.getUntrackedParameter<bool>("printDebug", true)),
0047       tTopoToken_(esConsumes()),
0048       badStripToken_(esConsumes()) {}
0049 
0050 void SiStripBadComponentsDQMServiceReader::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
0051   //Retrieve tracker topology from geometry
0052   const auto& tTopo = iSetup.getData(tTopoToken_);
0053 
0054   uint32_t FedErrorMask = 1;      // bit 0
0055   uint32_t DigiErrorMask = 2;     // bit 1
0056   uint32_t ClusterErrorMask = 4;  // bit 2
0057 
0058   const auto& siStripBadStrip = iSetup.getData(badStripToken_);
0059   edm::LogInfo("SiStripBadComponentsDQMServiceReader")
0060       << "[SiStripBadComponentsDQMServiceReader::analyze] End Reading SiStripBadStrip" << std::endl;
0061 
0062   std::vector<uint32_t> detid;
0063   siStripBadStrip.getDetIds(detid);
0064 
0065   std::stringstream ss;
0066 
0067   // ss << " detid" << " \t\t\t" << "FED error" << " \t" << "Digi test failed" << " \t" << "Cluster test failed" << std::endl;
0068 
0069   ss << "subdet  layer   stereo  side \t detId \t\t Errors" << std::endl;
0070 
0071   for (size_t id = 0; id < detid.size(); id++) {
0072     SiStripBadStrip::Range range = siStripBadStrip.getRange(detid[id]);
0073 
0074     for (int it = 0; it < range.second - range.first; it++) {
0075       unsigned int value = (*(range.first + it));
0076       ss << detIdToString(detid[id], tTopo) << "\t" << detid[id] << "\t";
0077 
0078       uint32_t flag = static_cast<uint32_t>(siStripBadStrip.decode(value).flag);
0079 
0080       printError(ss, ((flag & FedErrorMask) == FedErrorMask), "Fed error, ");
0081       printError(ss, ((flag & DigiErrorMask) == DigiErrorMask), "Digi error, ");
0082       printError(ss, ((flag & ClusterErrorMask) == ClusterErrorMask), "Cluster error");
0083       ss << std::endl;
0084 
0085       if (printdebug_) {
0086         ss << " firstBadStrip " << siStripBadStrip.decode(value).firstStrip << "\t "
0087            << " NconsecutiveBadStrips " << siStripBadStrip.decode(value).range << "\t "  // << std::endl;
0088            << " flag " << siStripBadStrip.decode(value).flag << "\t "
0089            << " packed integer " << std::hex << value << std::dec << "\t " << std::endl;
0090       }
0091     }
0092     ss << std::endl;
0093   }
0094   edm::LogInfo("SiStripBadComponentsDQMServiceReader") << ss.str();
0095 }
0096 
0097 void SiStripBadComponentsDQMServiceReader::printError(std::stringstream& ss,
0098                                                       const bool error,
0099                                                       const std::string& errorText) {
0100   if (error) {
0101     ss << errorText << "\t ";
0102   } else {
0103     ss << "\t\t ";
0104   }
0105 }
0106 
0107 string SiStripBadComponentsDQMServiceReader::detIdToString(DetId detid, const TrackerTopology& tTopo) {
0108   std::string detector;
0109   int layer = 0;
0110   int stereo = 0;
0111   int side = -1;
0112 
0113   // Using the operator[] if the element does not exist it is created with the default value. That is 0 for integral types.
0114   switch (detid.subdetId()) {
0115     case StripSubdetector::TIB: {
0116       detector = "TIB";
0117       layer = tTopo.tibLayer(detid.rawId());
0118       stereo = tTopo.tibStereo(detid.rawId());
0119       break;
0120     }
0121     case StripSubdetector::TOB: {
0122       detector = "TOB";
0123       layer = tTopo.tobLayer(detid.rawId());
0124       stereo = tTopo.tobStereo(detid.rawId());
0125       break;
0126     }
0127     case StripSubdetector::TEC: {
0128       // is this module in TEC+ or TEC-?
0129       side = tTopo.tecSide(detid.rawId());
0130       detector = "TEC";
0131       layer = tTopo.tecWheel(detid.rawId());
0132       stereo = tTopo.tecStereo(detid.rawId());
0133       break;
0134     }
0135     case StripSubdetector::TID: {
0136       // is this module in TID+ or TID-?
0137       side = tTopo.tidSide(detid.rawId());
0138       detector = "TID";
0139       layer = tTopo.tidWheel(detid.rawId());
0140       stereo = tTopo.tidStereo(detid.rawId());
0141       break;
0142     }
0143   }
0144   std::string name(detector + "\t" + std::to_string(layer) + "\t" + std::to_string(stereo) + "\t");
0145   if (side == 1) {
0146     name += "-";
0147   } else if (side == 2) {
0148     name += "+";
0149   }
0150   //   if( side != -1 ) {
0151   //     name += std::to_string(side);
0152   //   }
0153 
0154   return name;
0155 }
0156 
0157 #include "FWCore/Framework/interface/MakerMacros.h"
0158 DEFINE_FWK_MODULE(SiStripBadComponentsDQMServiceReader);