Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:45

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/ServiceRegistry/interface/Service.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 
0005 #include "DQMServices/Core/interface/DQMStore.h"
0006 
0007 #include "SiStripDaqInfo.h"
0008 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0009 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0010 
0011 //Run Info
0012 #include "CondFormats/RunInfo/interface/RunInfo.h"
0013 
0014 // FED cabling and numbering
0015 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0016 
0017 #include <cassert>
0018 #include <cmath>
0019 #include <cstdio>
0020 #include <iomanip>
0021 #include <iostream>
0022 #include <sstream>
0023 #include <string>
0024 #include <vector>
0025 
0026 SiStripDaqInfo::SiStripDaqInfo(edm::ParameterSet const&)
0027     : fedCablingToken_{esConsumes<edm::Transition::BeginRun>()},
0028       tTopoToken_{esConsumes<edm::Transition::BeginRun>()},
0029       runInfoToken_{esConsumes<edm::Transition::BeginRun>()} {
0030   edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::Deleting SiStripDaqInfo ";
0031 }
0032 
0033 //
0034 // -- Book MEs for SiStrip Daq Fraction
0035 //
0036 void SiStripDaqInfo::bookStatus(DQMStore& dqm_store) {
0037   edm::LogInfo("SiStripDcsInfo") << " SiStripDaqInfo::bookStatus " << bookedStatus_;
0038   if (bookedStatus_)
0039     return;
0040 
0041   dqm_store.cd();
0042   std::string strip_dir = "";
0043   SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
0044   if (!strip_dir.empty())
0045     dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
0046   else
0047     dqm_store.setCurrentFolder("SiStrip/EventInfo");
0048 
0049   daqFraction_ = dqm_store.bookFloat("DAQSummary");
0050 
0051   dqm_store.cd();
0052   if (!strip_dir.empty())
0053     dqm_store.setCurrentFolder(strip_dir + "/EventInfo/DAQContents");
0054   else
0055     dqm_store.setCurrentFolder("SiStrip/EventInfo/DAQContents");
0056 
0057   std::vector<std::string> det_types;
0058   det_types.push_back("TIB");
0059   det_types.push_back("TOB");
0060   det_types.push_back("TIDF");
0061   det_types.push_back("TIDB");
0062   det_types.push_back("TECF");
0063   det_types.push_back("TECB");
0064 
0065   for (auto const& det : det_types) {
0066     std::string const me_name{"SiStrip_" + det};
0067     SubDetMEs local_mes{dqm_store.bookFloat(me_name), 0};
0068     subDetMEsMap_.emplace(det, local_mes);
0069   }
0070   bookedStatus_ = true;
0071   dqm_store.cd();
0072 }
0073 //
0074 // -- Fill with Dummy values
0075 //
0076 void SiStripDaqInfo::fillDummyStatus(DQMStore& dqm_store) {
0077   if (!bookedStatus_) {
0078     bookStatus(dqm_store);
0079   }
0080   assert(bookedStatus_);
0081 
0082   for (auto& pr : subDetMEsMap_) {
0083     pr.second.daqFractionME->Reset();
0084     pr.second.daqFractionME->Fill(-1.0);
0085   }
0086   daqFraction_->Reset();
0087   daqFraction_->Fill(-1.0);
0088 }
0089 
0090 void SiStripDaqInfo::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0091   edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo:: Begining of Run";
0092 
0093   // Check latest Fed cabling and create TrackerMapCreator
0094   if (fedCablingWatcher_.check(eSetup)) {
0095     fedCabling_ = &eSetup.getData(fedCablingToken_);
0096     readFedIds(fedCabling_, eSetup);
0097   }
0098   auto& dqm_store = *edm::Service<DQMStore>{};
0099   if (!bookedStatus_) {
0100     bookStatus(dqm_store);
0101   }
0102   if (nFedTotal_ == 0) {
0103     fillDummyStatus(dqm_store);
0104     edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::No FEDs Connected!!!";
0105     return;
0106   }
0107 
0108   float nFEDConnected = 0.0;
0109   constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
0110   constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
0111 
0112   if (!eSetup.tryToGet<RunInfoRcd>())
0113     return;
0114   auto sumFED = eSetup.getHandle(runInfoToken_);
0115   if (!sumFED)
0116     return;
0117 
0118   auto const& fedsInIds = sumFED->m_fed_in;
0119   for (auto const fedID : fedsInIds) {
0120     if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
0121       ++nFEDConnected;
0122   }
0123   edm::LogInfo("SiStripDaqInfo") << " SiStripDaqInfo::Total # of FEDs " << nFedTotal_ << " Connected FEDs "
0124                                  << nFEDConnected;
0125   if (nFEDConnected > 0) {
0126     daqFraction_->Reset();
0127     daqFraction_->Fill(nFEDConnected / nFedTotal_);
0128     readSubdetFedFractions(dqm_store, fedsInIds, eSetup);
0129   }
0130 }
0131 
0132 void SiStripDaqInfo::analyze(edm::Event const& event, edm::EventSetup const& eSetup) {}
0133 
0134 //
0135 // -- Read Sub Detector FEDs
0136 //
0137 void SiStripDaqInfo::readFedIds(const SiStripFedCabling* fedcabling, edm::EventSetup const& iSetup) {
0138   //Retrieve tracker topology from geometry
0139   const auto tTopo = &iSetup.getData(tTopoToken_);
0140 
0141   auto feds = fedCabling_->fedIds();
0142 
0143   nFedTotal_ = feds.size();
0144   for (auto const fed : feds) {
0145     auto fedChannels = fedCabling_->fedConnections(fed);
0146     for (auto const& conn : fedChannels) {
0147       if (!conn.isConnected())
0148         continue;
0149       uint32_t detId = conn.detId();
0150       if (detId == 0 || detId == 0xFFFFFFFF)
0151         continue;
0152       std::string subdet_tag;
0153       SiStripUtility::getSubDetectorTag(detId, subdet_tag, tTopo);
0154       subDetFedMap_[subdet_tag].push_back(fed);
0155       break;
0156     }
0157   }
0158 }
0159 //
0160 // -- Fill Subdet FEDIds
0161 //
0162 void SiStripDaqInfo::readSubdetFedFractions(DQMStore& dqm_store,
0163                                             std::vector<int> const& fed_ids,
0164                                             edm::EventSetup const& iSetup) {
0165   //Retrieve tracker topology from geometry
0166   const auto tTopo = &iSetup.getData(tTopoToken_);
0167 
0168   constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
0169   constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
0170 
0171   // initialiase
0172   for (auto const& pr : subDetFedMap_) {
0173     auto const& name = pr.first;
0174     auto iPos = subDetMEsMap_.find(name);
0175     if (iPos == subDetMEsMap_.end())
0176       continue;
0177     iPos->second.connectedFeds = 0;
0178   }
0179   // count sub detector feds
0180 
0181   for (auto const& [name, subdetIds] : subDetFedMap_) {
0182     auto iPos = subDetMEsMap_.find(name);
0183     if (iPos == subDetMEsMap_.end())
0184       continue;
0185     iPos->second.connectedFeds = 0;
0186     for (auto const subdetId : subdetIds) {
0187       bool fedid_found = false;
0188       for (auto const fedId : fed_ids) {
0189         if (fedId < siStripFedIdMin || fedId > siStripFedIdMax)
0190           continue;
0191         if (subdetId == fedId) {
0192           fedid_found = true;
0193           iPos->second.connectedFeds++;
0194           break;
0195         }
0196       }
0197       if (!fedid_found)
0198         findExcludedModule(dqm_store, subdetId, tTopo);
0199     }
0200     if (auto nFedSubDet = subdetIds.size(); nFedSubDet > 0) {
0201       iPos->second.daqFractionME->Reset();
0202       int const nFedsConnected = iPos->second.connectedFeds;
0203       iPos->second.daqFractionME->Fill(nFedsConnected * 1.0 / nFedSubDet);
0204     }
0205   }
0206 }
0207 //
0208 // -- find Excluded Modules
0209 //
0210 void SiStripDaqInfo::findExcludedModule(DQMStore& dqm_store,
0211                                         unsigned short const fed_id,
0212                                         TrackerTopology const* tTopo) {
0213   dqm_store.cd();
0214   std::string mdir = "MechanicalView";
0215   if (!SiStripUtility::goToDir(dqm_store, mdir)) {
0216     dqm_store.setCurrentFolder("SiStrip/" + mdir);
0217   }
0218   std::string mechanical_dir = dqm_store.pwd();
0219   auto fedChannels = fedCabling_->fedConnections(fed_id);
0220   int ichannel = 0;
0221   std::string tag = "ExcludedFedChannel";
0222   std::string bad_module_folder;
0223   for (auto const& conn : fedChannels) {
0224     if (!conn.isConnected())
0225       continue;
0226     uint32_t detId = conn.detId();
0227     if (detId == 0 || detId == 0xFFFFFFFF)
0228       continue;
0229 
0230     ichannel++;
0231     if (ichannel == 1) {
0232       std::string subdet_folder;
0233       SiStripFolderOrganizer folder_organizer;
0234       folder_organizer.getSubDetFolder(detId, tTopo, subdet_folder);
0235       if (!dqm_store.dirExists(subdet_folder)) {
0236         subdet_folder = mechanical_dir + subdet_folder.substr(subdet_folder.find(mdir) + mdir.size());
0237       }
0238       bad_module_folder = subdet_folder + "/" + "BadModuleList";
0239       dqm_store.setCurrentFolder(bad_module_folder);
0240     }
0241     std::ostringstream detid_str;
0242     detid_str << detId;
0243     std::string full_path = bad_module_folder + "/" + detid_str.str();
0244     MonitorElement* me = dqm_store.get(full_path);
0245     uint16_t flag = 0;
0246     if (me) {
0247       flag = me->getIntValue();
0248       me->Reset();
0249     } else
0250       me = dqm_store.bookInt(detid_str.str());
0251     SiStripUtility::setBadModuleFlag(tag, flag);
0252     me->Fill(flag);
0253   }
0254   dqm_store.cd();
0255 }
0256 #include "FWCore/Framework/interface/MakerMacros.h"
0257 DEFINE_FWK_MODULE(SiStripDaqInfo);