Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
#include "CondFormats/SiPixelObjects/interface/SiPixelFEDChannelContainer.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <iostream>
#include <iomanip>  // std::setw

//****************************************************************************//
void SiPixelFEDChannelContainer::setScenario(const std::string &theScenarioId,
                                             const SiPixelFEDChannelCollection &theBadFEDChannels) {
  if (m_scenarioMap.find(theScenarioId) != m_scenarioMap.end()) {
    edm::LogWarning("SiPixelFEDChannelContainer")
        << "Scenario: " << theScenarioId << " is already in the map!" << std::endl;
    return;
  } else {
    m_scenarioMap.emplace(theScenarioId, theBadFEDChannels);
  }
}

//****************************************************************************//
SiPixelFEDChannelContainer::SiPixelFEDChannelCollection SiPixelFEDChannelContainer::getSiPixelBadFedChannels(
    const std::string &theScenarioId) const {
  SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);

  if (it != m_scenarioMap.end()) {
    return it->second;
  } else {
    throw cms::Exception("SiPixelFEDChannelContainer")
        << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
  }
}

//****************************************************************************//
const SiPixelFEDChannelContainer::SiPixelFEDChannelCollection &SiPixelFEDChannelContainer::getSiPixelBadFedChannels(
    const std::string &theScenarioId) {
  SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);

  if (it != m_scenarioMap.end()) {
    return it->second;
  } else {
    throw cms::Exception("SiPixelFEDChannelContainer")
        << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
  }
}

//****************************************************************************//
const std::vector<PixelFEDChannel> &SiPixelFEDChannelContainer::getSiPixelBadFedChannelsInDetId(
    const std::string &theScenarioId, DetId theDetId) {
  SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);

  if (it == m_scenarioMap.end()) {
    throw cms::Exception("SiPixelFEDChannelContainer")
        << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
  } else {
    SiPixelFEDChannelCollection::const_iterator it2 = (it->second).find(theDetId);

    if (it2 == (it->second).end()) {
      throw cms::Exception("SiPixelFEDChannelContainer")
          << "No Bad Pixel FEDChannels defined for DetId:" << theDetId << " in Scenario id: " << theScenarioId << "\n";
    }
    return it2->second;
  }
}

//****************************************************************************//
std::unique_ptr<PixelFEDChannelCollection> SiPixelFEDChannelContainer::getDetSetBadPixelFedChannels(
    const std::string &theScenarioId) const {
  SiPixelBadFEDChannelsScenarioMap::const_iterator it = m_scenarioMap.find(theScenarioId);

  if (it == m_scenarioMap.end()) {
    throw cms::Exception("SiPixelFEDChannelContainer")
        << "No Bad Pixel FEDChannels defined for Scenario id: " << theScenarioId << "\n";
  }

  std::unique_ptr<PixelFEDChannelCollection> disabled_channelcollection =
      std::make_unique<edmNew::DetSetVector<PixelFEDChannel> >();
  auto SiPixelBadFedChannels = it->second;
  for (const auto &entry : SiPixelBadFedChannels) {
    disabled_channelcollection->insert(entry.first, entry.second.data(), entry.second.size());
  }
  return disabled_channelcollection;
}

//****************************************************************************//
void SiPixelFEDChannelContainer::printAll() const {
  edm::LogVerbatim("SiPixelFEDChannelContainer") << "SiPixelFEDChannelContainer::printAll()";
  edm::LogVerbatim("SiPixelFEDChannelContainer") << " ================================================================="
                                                    "==================================================";
  for (auto it = m_scenarioMap.begin(); it != m_scenarioMap.end(); ++it) {
    edm::LogVerbatim("SiPixelFEDChannelContainer") << "run :" << it->first << "  \n ";
    for (const auto &thePixelFEDChannel : it->second) {
      DetId detId = thePixelFEDChannel.first;

      edm::LogVerbatim("SiPixelFEDChannelContainer") << "DetId :" << detId << "  \n ";

      for (const auto &entry : thePixelFEDChannel.second) {
        //unsigned int fed, link, roc_first, roc_last;
        edm::LogVerbatim("SiPixelFEDChannelContainer")
            << " fed : " << entry.fed << " link : " << entry.link << " roc_first : " << entry.roc_first
            << " roc_last: : " << entry.roc_last;
      }
    }
  }
}

//****************************************************************************//
void SiPixelFEDChannelContainer::print(std::ostream &os) const {
  for (auto it = m_scenarioMap.begin(); it != m_scenarioMap.end(); ++it) {
    os << "run :" << it->first << "  \n ";
    for (const auto &thePixelFEDChannel : it->second) {
      DetId detId = thePixelFEDChannel.first;
      os << "DetId :" << detId << "  \n ";
      for (const auto &entry : thePixelFEDChannel.second) {
        os << " fed : " << entry.fed << " link : " << entry.link << " roc_first : " << entry.roc_first
           << " roc_last: : " << entry.roc_last;
      }
    }
  }
}

//****************************************************************************//
std::vector<std::string> SiPixelFEDChannelContainer::getScenarioList() const {
  std::vector<std::string> scenarios;
  scenarios.reserve(m_scenarioMap.size());

  for (auto it = m_scenarioMap.begin(); it != m_scenarioMap.end(); ++it) {
    scenarios.push_back(it->first);
  }
  return scenarios;
}

//****************************************************************************//
std::ostream &operator<<(std::ostream &os, SiPixelFEDChannelContainer FEDChannels) {
  std::stringstream ss;
  FEDChannels.print(ss);
  os << ss.str();
  return os;
}