Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:32

0001 #include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <iostream>
0005 #include <iomanip>  // std::setw
0006 
0007 //****************************************************************************//
0008 void SiPixelFEDChannelContainer::setScenario(const std::string &theScenarioId,
0009                                              const SiPixelFEDChannelCollection &theBadFEDChannels) {
0010   if (m_scenarioMap.find(theScenarioId) != m_scenarioMap.end()) {
0011     edm::LogWarning("SiPixelFEDChannelContainer")
0012         << "Scenario: " << theScenarioId << " is already in the map!" << std::endl;
0013     return;
0014   } else {
0015     m_scenarioMap.emplace(theScenarioId, theBadFEDChannels);
0016   }
0017 }
0018 
0019 //****************************************************************************//
0020 SiPixelFEDChannelContainer::SiPixelFEDChannelCollection SiPixelFEDChannelContainer::getSiPixelBadFedChannels(
0021     const std::string &theScenarioId) const {
0022   SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);
0023 
0024   if (it != m_scenarioMap.end()) {
0025     return it->second;
0026   } else {
0027     throw cms::Exception("SiPixelFEDChannelContainer")
0028         << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
0029   }
0030 }
0031 
0032 //****************************************************************************//
0033 const SiPixelFEDChannelContainer::SiPixelFEDChannelCollection &SiPixelFEDChannelContainer::getSiPixelBadFedChannels(
0034     const std::string &theScenarioId) {
0035   SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);
0036 
0037   if (it != m_scenarioMap.end()) {
0038     return it->second;
0039   } else {
0040     throw cms::Exception("SiPixelFEDChannelContainer")
0041         << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
0042   }
0043 }
0044 
0045 //****************************************************************************//
0046 const std::vector<PixelFEDChannel> &SiPixelFEDChannelContainer::getSiPixelBadFedChannelsInDetId(
0047     const std::string &theScenarioId, DetId theDetId) {
0048   SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);
0049 
0050   if (it == m_scenarioMap.end()) {
0051     throw cms::Exception("SiPixelFEDChannelContainer")
0052         << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
0053   } else {
0054     SiPixelFEDChannelCollection::const_iterator it2 = (it->second).find(theDetId);
0055 
0056     if (it2 == (it->second).end()) {
0057       throw cms::Exception("SiPixelFEDChannelContainer")
0058           << "No Bad Pixel FEDChannels defined for DetId:" << theDetId << " in Scenario id: " << theScenarioId << "\n";
0059     }
0060     return it2->second;
0061   }
0062 }
0063 
0064 //****************************************************************************//
0065 std::unique_ptr<PixelFEDChannelCollection> SiPixelFEDChannelContainer::getDetSetBadPixelFedChannels(
0066     const std::string &theScenarioId) const {
0067   SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);
0068 
0069   if (it == m_scenarioMap.end()) {
0070     throw cms::Exception("SiPixelFEDChannelContainer")
0071         << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
0072   }
0073 
0074   std::unique_ptr<PixelFEDChannelCollection> disabled_channelcollection =
0075       std::make_unique<edmNew::DetSetVector<PixelFEDChannel> >();
0076   auto SiPixelBadFedChannels = it->second;
0077   for (const auto &entry : SiPixelBadFedChannels) {
0078     disabled_channelcollection->insert(entry.first, entry.second.data(), entry.second.size());
0079   }
0080   return disabled_channelcollection;
0081 }
0082 
0083 //****************************************************************************//
0084 void SiPixelFEDChannelContainer::printAll() const {
0085   edm::LogVerbatim("SiPixelFEDChannelContainer") << "SiPixelFEDChannelContainer::printAll()";
0086   edm::LogVerbatim("SiPixelFEDChannelContainer") << " ================================================================="
0087                                                     "==================================================";
0088   for (auto it = m_scenarioMap.begin(); it != m_scenarioMap.end(); ++it) {
0089     edm::LogVerbatim("SiPixelFEDChannelContainer") << "run :" << it->first << "  \n ";
0090     for (const auto &thePixelFEDChannel : it->second) {
0091       DetId detId = thePixelFEDChannel.first;
0092 
0093       edm::LogVerbatim("SiPixelFEDChannelContainer") << "DetId :" << detId << "  \n ";
0094 
0095       for (const auto &entry : thePixelFEDChannel.second) {
0096         //unsigned int fed, link, roc_first, roc_last;
0097         edm::LogVerbatim("SiPixelFEDChannelContainer")
0098             << " fed : " << entry.fed << " link : " << entry.link << " roc_first : " << entry.roc_first
0099             << " roc_last: : " << entry.roc_last;
0100       }
0101     }
0102   }
0103 }
0104 
0105 //****************************************************************************//
0106 void SiPixelFEDChannelContainer::print(std::ostream &os) const {
0107   for (auto it = m_scenarioMap.begin(); it != m_scenarioMap.end(); ++it) {
0108     os << "run :" << it->first << "  \n ";
0109     for (const auto &thePixelFEDChannel : it->second) {
0110       DetId detId = thePixelFEDChannel.first;
0111       os << "DetId :" << detId << "  \n ";
0112       for (const auto &entry : thePixelFEDChannel.second) {
0113         os << " fed : " << entry.fed << " link : " << entry.link << " roc_first : " << entry.roc_first
0114            << " roc_last: : " << entry.roc_last;
0115       }
0116     }
0117   }
0118 }
0119 
0120 //****************************************************************************//
0121 std::vector<std::string> SiPixelFEDChannelContainer::getScenarioList() const {
0122   std::vector<std::string> scenarios;
0123   scenarios.reserve(m_scenarioMap.size());
0124 
0125   for (auto it = m_scenarioMap.begin(); it != m_scenarioMap.end(); ++it) {
0126     scenarios.push_back(it->first);
0127   }
0128   return scenarios;
0129 }
0130 
0131 //****************************************************************************//
0132 std::ostream &operator<<(std::ostream &os, SiPixelFEDChannelContainer FEDChannels) {
0133   std::stringstream ss;
0134   FEDChannels.print(ss);
0135   os << ss.str();
0136   return os;
0137 }