Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:43

0001 #include "DQMOffline/CalibTracker/plugins/SiStripDQMPopConSourceHandler.h"
0002 #include "CondFormats/SiStripObjects/interface/SiStripBadStrip.h"
0003 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0004 
0005 /**
0006   @class SiStripBadComponentsDQMService
0007   @author M. De Mattia, S. Dutta, D. Giordano
0008 
0009   @popcon::PopConSourceHandler to read modules flagged by the DQM as bad and write in the database.
0010 */
0011 class SiStripPopConBadComponentsHandlerFromDQM : public SiStripDQMPopConSourceHandler<SiStripBadStrip> {
0012 public:
0013   typedef dqm::legacy::MonitorElement MonitorElement;
0014   typedef dqm::legacy::DQMStore DQMStore;
0015 
0016   explicit SiStripPopConBadComponentsHandlerFromDQM(const edm::ParameterSet& iConfig, edm::ConsumesCollector&& iC);
0017   ~SiStripPopConBadComponentsHandlerFromDQM() override;
0018   // interface methods: implemented in template
0019   void initES(const edm::EventSetup&) override;
0020   void dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter& getter) override;
0021   SiStripBadStrip* getObj() const override;
0022 
0023 protected:
0024   std::string getMetaDataString() const override;
0025 
0026 private:
0027   edm::FileInPath fp_;
0028   SiStripBadStrip m_obj;
0029   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0030   const TrackerTopology* trackerTopo_;
0031 };
0032 
0033 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0034 
0035 #include "DQMServices/Core/interface/DQMStore.h"
0036 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0037 
0038 SiStripPopConBadComponentsHandlerFromDQM::SiStripPopConBadComponentsHandlerFromDQM(const edm::ParameterSet& iConfig,
0039                                                                                    edm::ConsumesCollector&& iC)
0040     : SiStripDQMPopConSourceHandler<SiStripBadStrip>(iConfig),
0041       fp_{iConfig.getUntrackedParameter<edm::FileInPath>("file",
0042                                                          edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile))},
0043       tTopoToken_(iC.esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()) {
0044   edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::SiStripBadComponentsDQMService]";
0045 }
0046 
0047 SiStripPopConBadComponentsHandlerFromDQM::~SiStripPopConBadComponentsHandlerFromDQM() {
0048   edm::LogInfo("SiStripBadComponentsDQMService") << "[SiStripBadComponentsDQMService::~SiStripBadComponentsDQMService]";
0049 }
0050 
0051 void SiStripPopConBadComponentsHandlerFromDQM::initES(const edm::EventSetup& setup) {
0052   trackerTopo_ = &setup.getData(tTopoToken_);
0053 }
0054 
0055 std::string SiStripPopConBadComponentsHandlerFromDQM::getMetaDataString() const {
0056   std::stringstream ss;
0057   ss << SiStripDQMPopConSourceHandler<SiStripBadStrip>::getMetaDataString();
0058   getObj()->printSummary(ss, trackerTopo_);
0059   return ss.str();
0060 }
0061 
0062 namespace {
0063   void getModuleFolderList(SiStripPopConBadComponentsHandlerFromDQM::DQMStore::IGetter& getter,
0064                            const std::string& pwd,
0065                            std::vector<std::string>& mfolders) {
0066     if (std::string::npos != pwd.find("module_")) {
0067       //    std::string mId = pwd.substr(pwd.find("module_")+7, 9);
0068       mfolders.push_back(pwd);
0069     } else {
0070       for (const auto& subdir : getter.getSubdirs()) {
0071         getter.cd(subdir);
0072         getModuleFolderList(getter, subdir, mfolders);
0073         getter.cd();
0074         getter.cd(pwd);
0075       }
0076     }
0077   }
0078 }  // namespace
0079 
0080 void SiStripPopConBadComponentsHandlerFromDQM::dqmEndJob(DQMStore::IBooker&, DQMStore::IGetter& getter) {
0081   //*LOOP OVER THE LIST OF SUMMARY OBJECTS TO INSERT IN DB*//
0082 
0083   m_obj = SiStripBadStrip();
0084 
0085   const auto detInfo = SiStripDetInfoFileReader::read(fp_.fullPath());
0086 
0087   getter.cd();
0088 
0089   const std::string mechanicalview_dir = "MechanicalView";
0090   if (!getter.dirExists(mechanicalview_dir))
0091     return;
0092 
0093   const std::vector<std::string> subdet_folder = {"TIB", "TOB", "TEC/side_1", "TEC/side_2", "TID/side_1", "TID/side_2"};
0094 
0095   int nDetsTotal = 0;
0096   int nDetsWithErrorTotal = 0;
0097   for (const auto& im : subdet_folder) {
0098     const std::string dname = mechanicalview_dir + "/" + im;
0099     getter.cd();
0100     if (!getter.dirExists(dname))
0101       continue;
0102     getter.cd(dname);
0103 
0104     std::vector<std::string> module_folders;
0105     getModuleFolderList(getter, dname, module_folders);
0106     int nDets = module_folders.size();
0107 
0108     int nDetsWithError = 0;
0109     const std::string bad_module_folder = dname + "/" + "BadModuleList";
0110     getter.cd();
0111     if (getter.dirExists(bad_module_folder)) {
0112       for (const MonitorElement* me : getter.getContents(bad_module_folder)) {
0113         nDetsWithError++;
0114         std::cout << me->getName() << " " << me->getIntValue() << std::endl;
0115         uint32_t detId = std::stoul(me->getName());
0116         short flag = me->getIntValue();
0117 
0118         std::vector<unsigned int> theSiStripVector;
0119 
0120         unsigned short firstBadStrip = 0, NconsecutiveBadStrips = 0;
0121         unsigned int theBadStripRange;
0122 
0123         // for(std::vector<uint32_t>::const_iterator is=BadApvList_.begin(); is!=BadApvList_.end(); ++is){
0124 
0125         //   firstBadStrip=(*is)*128;
0126         NconsecutiveBadStrips = detInfo.getNumberOfApvsAndStripLength(detId).first * 128;
0127 
0128         theBadStripRange = m_obj.encode(firstBadStrip, NconsecutiveBadStrips, flag);
0129 
0130         LogDebug("SiStripBadComponentsDQMService") << "detid " << detId << " \t"
0131                                                    << ", flag " << flag << std::endl;
0132 
0133         theSiStripVector.push_back(theBadStripRange);
0134         // }
0135 
0136         SiStripBadStrip::Range range(theSiStripVector.begin(), theSiStripVector.end());
0137         if (!m_obj.put(detId, range)) {
0138           edm::LogError("SiStripBadFiberBuilder")
0139               << "[SiStripBadFiberBuilder::analyze] detid already exists" << std::endl;
0140         }
0141       }
0142     }
0143     nDetsTotal += nDets;
0144     nDetsWithErrorTotal += nDetsWithError;
0145   }
0146   getter.cd();
0147 }
0148 
0149 SiStripBadStrip* SiStripPopConBadComponentsHandlerFromDQM::getObj() const { return new SiStripBadStrip(m_obj); }
0150 
0151 #include "FWCore/Framework/interface/MakerMacros.h"
0152 #include "DQMOffline/CalibTracker/plugins/SiStripPopConDQMEDHarvester.h"
0153 using SiStripPopConBadComponentsDQM = SiStripPopConDQMEDHarvester<SiStripPopConBadComponentsHandlerFromDQM>;
0154 DEFINE_FWK_MODULE(SiStripPopConBadComponentsDQM);