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
#include "CondFormats/SiPixelObjects/interface/SiPixelVCal.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <algorithm>

bool SiPixelVCal::putSlopeAndOffset(const uint32_t& pixid, float& slopeValue, float& offsetValue) {
  std::map<unsigned int, VCal>::const_iterator id = m_vcal.find(pixid);
  if (id != m_vcal.end()) {
    edm::LogError("SiPixelVCal") << "SiPixelVCal for pixid " << pixid << " is already stored. Skipping this put"
                                 << std::endl;
    return false;
  } else {
    m_vcal[pixid] = {slopeValue, offsetValue};
  }
  return true;
}

SiPixelVCal::VCal SiPixelVCal::getSlopeAndOffset(const uint32_t& pixid) const {
  std::map<unsigned int, VCal>::const_iterator id = m_vcal.find(pixid);
  if (id != m_vcal.end())
    return id->second;
  else
    edm::LogError("SiPixelVCal") << "SiPixelVCal for pixid " << pixid << " is not stored" << std::endl;
  VCal vcal_default;
  return vcal_default;
}

float SiPixelVCal::getSlope(const uint32_t& pixid) const {
  std::map<unsigned int, VCal>::const_iterator id = m_vcal.find(pixid);
  if (id != m_vcal.end())
    return id->second.slope;
  else
    edm::LogError("SiPixelVCal") << "SiPixelVCal slope for pixid " << pixid << " is not stored" << std::endl;
  return 47.;
}

float SiPixelVCal::getOffset(const uint32_t& pixid) const {
  std::map<unsigned int, VCal>::const_iterator id = m_vcal.find(pixid);
  if (id != m_vcal.end())
    return id->second.offset;
  else
    edm::LogError("SiPixelVCal") << "SiPixelVCal offset for pixid " << pixid << " is not stored" << std::endl;
  return -60.;
}

SiPixelVCal::mapToDetId SiPixelVCal::getAllSlopes() const {
  std::map<uint32_t, float> slopes;
  std::transform(m_vcal.begin(),
                 m_vcal.end(),
                 std::inserter(slopes, slopes.end()),
                 [](std::pair<uint32_t, SiPixelVCal::VCal> vcalentry) -> std::pair<uint32_t, float> {
                   return std::make_pair(vcalentry.first, vcalentry.second.slope);
                 });
  return slopes;
}

SiPixelVCal::mapToDetId SiPixelVCal::getAllOffsets() const {
  std::map<uint32_t, float> offsets;
  std::transform(m_vcal.begin(),
                 m_vcal.end(),
                 std::inserter(offsets, offsets.end()),
                 [](std::pair<uint32_t, SiPixelVCal::VCal> vcalentry) -> std::pair<uint32_t, float> {
                   return std::make_pair(vcalentry.first, vcalentry.second.offset);
                 });
  return offsets;
}