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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
#include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <iostream>
#include <iomanip>  // std::setw

//****************************************************************************//
namespace AlignPCLThresholdsHGImpl {
  template <typename T>
  const T &getParam(const std::vector<T> &params, size_t index) {
    if (index >= params.size())
      throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
    return params[index];
  }

  template <typename T>
  void setParam(std::vector<T> &params, size_t index, const T &value) {
    if (index >= params.size())
      throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
    params[index] = value;
  }

}  //namespace AlignPCLThresholdsHGImpl

//****************************************************************************//
void AlignPCLThresholdsHG::setFloatMap(const std::unordered_map<std::string, std::vector<float>> &floatMap) {
  floatMap_ = floatMap;
}

//****************************************************************************//
const std::vector<float> &AlignPCLThresholdsHG::getFloatVec(const std::string &AlignableId) const {
  const auto &it = floatMap_.find(AlignableId);

  if (it != floatMap_.end()) {
    return it->second;
  } else {
    throw cms::Exception("AlignPCLThresholdsHG") << "No float vector defined for Alignable id " << AlignableId << "\n";
  }
}

//****************************************************************************//
void AlignPCLThresholdsHG::setFractionCut(const std::string &AlignableId, const coordType &type, const float &cut) {
  // Set entry in map if not yet available
  const auto &it = floatMap_.find(AlignableId);
  if (it == floatMap_.end())
    floatMap_[AlignableId] = std::vector<float>(FSIZE, -1.);

  switch (type) {
    case X:
      return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_X, cut);
    case Y:
      return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_Y, cut);
    case Z:
      return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_Z, cut);
    case theta_X:
      return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_TX, cut);
    case theta_Y:
      return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_TY, cut);
    case theta_Z:
      return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_TZ, cut);
    default:
      throw cms::Exception("AlignPCLThresholdsHG")
          << "Requested setting fraction threshold for undefined coordinate" << type << "\n";
  }
}

//****************************************************************************//
std::array<float, 6> AlignPCLThresholdsHG::getFractionCut(const std::string &AlignableId) const {
  const std::vector<float> vec = getFloatVec(AlignableId);
  return {{AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_X),
           AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Y),
           AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Z),
           AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TX),
           AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TY),
           AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TZ)}};
}

//****************************************************************************//
float AlignPCLThresholdsHG::getFractionCut(const std::string &AlignableId, const coordType &type) const {
  const std::vector<float> vec = getFloatVec(AlignableId);
  switch (type) {
    case X:
      return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_X);
    case Y:
      return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Y);
    case Z:
      return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Z);
    case theta_X:
      return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TX);
    case theta_Y:
      return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TY);
    case theta_Z:
      return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TZ);
    default:
      throw cms::Exception("AlignPCLThresholdsHG")
          << "Requested fraction threshold for undefined coordinate" << type << "\n";
  }
}

//****************************************************************************//
const bool AlignPCLThresholdsHG::hasFloatMap(const std::string &AlignableId) const {
  const auto &it = floatMap_.find(AlignableId);
  return (it != floatMap_.end());
}

//****************************************************************************//
const int AlignPCLThresholdsHG::payloadVersion() const {
  switch (static_cast<int>(FSIZE) + static_cast<int>(ISIZE) + static_cast<int>(SSIZE)) {
    case 6:
      return 1;
    default:
      throw cms::Exception("AlignPCLThresholdsHG")
          << "Payload version with parameter size equal to "
          << static_cast<int>(FSIZE) + static_cast<int>(ISIZE) + static_cast<int>(SSIZE) << " is not defined.\n";
  }
}

//****************************************************************************//
void AlignPCLThresholdsHG::printAll() const {
  edm::LogVerbatim out("AlignPCLThresholdsHG");

  out << "AlignPCLThresholdsHG::printAll()\n";
  out << "============================================================================================================="
         "======\n";
  out << "N records cut: " << this->getNrecords() << "\n";
  for (auto it = m_thresholds.begin(); it != m_thresholds.end(); ++it) {
    out << "==========================================================================================================="
           "========\n";

    std::stringstream ss;

    ss << "key : " << it->first << " \n"
       << "- Xcut             : " << std::setw(4) << (it->second).getXcut() << std::setw(5) << "   um"
       << "| sigXcut          : " << std::setw(4) << (it->second).getSigXcut() << std::setw(1) << " "
       << "| maxMoveXcut      : " << std::setw(4) << (it->second).getMaxMoveXcut() << std::setw(5) << "   um"
       << "| ErrorXcut        : " << std::setw(4) << (it->second).getErrorXcut() << std::setw(5) << "   um";

    if (floatMap_.find(it->first) != floatMap_.end()) {
      ss << "| X_fractionCut      : " << std::setw(4) << getFractionCut(it->first, X) << std::setw(5) << "\n";
    } else {
      ss << "\n";
    }

    ss << "- thetaXcut        : " << std::setw(4) << (it->second).getThetaXcut() << std::setw(5) << " urad"
       << "| sigThetaXcut     : " << std::setw(4) << (it->second).getSigThetaXcut() << std::setw(1) << " "
       << "| maxMoveThetaXcut : " << std::setw(4) << (it->second).getMaxMoveThetaXcut() << std::setw(5) << " urad"
       << "| ErrorThetaXcut   : " << std::setw(4) << (it->second).getErrorThetaXcut() << std::setw(5) << " urad";

    if (floatMap_.find(it->first) != floatMap_.end()) {
      ss << "| thetaX_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_X) << std::setw(5) << "\n";
    } else {
      ss << "\n";
    }

    ss << "- Ycut             : " << std::setw(4) << (it->second).getYcut() << std::setw(5) << "   um"
       << "| sigYcut          : " << std::setw(4) << (it->second).getSigXcut() << std::setw(1) << " "
       << "| maxMoveYcut      : " << std::setw(4) << (it->second).getMaxMoveYcut() << std::setw(5) << "   um"
       << "| ErrorYcut        : " << std::setw(4) << (it->second).getErrorYcut() << std::setw(5) << "   um";

    if (floatMap_.find(it->first) != floatMap_.end()) {
      ss << "| Y_fractionCut      : " << std::setw(4) << getFractionCut(it->first, Y) << std::setw(5) << "\n";
    } else {
      ss << "\n";
    }

    ss << "- thetaYcut        : " << std::setw(4) << (it->second).getThetaYcut() << std::setw(5) << " urad"
       << "| sigThetaYcut     : " << std::setw(4) << (it->second).getSigThetaYcut() << std::setw(1) << " "
       << "| maxMoveThetaYcut : " << std::setw(4) << (it->second).getMaxMoveThetaYcut() << std::setw(5) << " urad"
       << "| ErrorThetaYcut   : " << std::setw(4) << (it->second).getErrorThetaYcut() << std::setw(5) << " urad";

    if (floatMap_.find(it->first) != floatMap_.end()) {
      ss << "| thetaY_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_Y) << std::setw(5) << "\n";
    } else {
      ss << "\n";
    }

    ss << "- Zcut             : " << std::setw(4) << (it->second).getZcut() << std::setw(5) << "   um"
       << "| sigZcut          : " << std::setw(4) << (it->second).getSigZcut() << std::setw(1) << " "
       << "| maxMoveZcut      : " << std::setw(4) << (it->second).getMaxMoveZcut() << std::setw(5) << "   um"
       << "| ErrorZcut        : " << std::setw(4) << (it->second).getErrorZcut() << std::setw(5) << "   um";

    if (floatMap_.find(it->first) != floatMap_.end()) {
      ss << "| Z_fractionCut      : " << std::setw(4) << getFractionCut(it->first, Z) << std::setw(5) << "\n";
    } else {
      ss << "\n";
    }

    ss << "- thetaZcut        : " << std::setw(4) << (it->second).getThetaZcut() << std::setw(5) << " urad"
       << "| sigThetaZcut     : " << std::setw(4) << (it->second).getSigThetaZcut() << std::setw(1) << " "
       << "| maxMoveThetaZcut : " << std::setw(4) << (it->second).getMaxMoveThetaZcut() << std::setw(5) << " urad"
       << "| ErrorThetaZcut   : " << std::setw(4) << (it->second).getErrorThetaZcut() << std::setw(5) << " urad";

    if (floatMap_.find(it->first) != floatMap_.end()) {
      ss << "| thetaZ_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_Z) << std::setw(5) << "\n";
    } else {
      ss << "\n";
    }

    out << ss.str() << std::endl;

    if ((it->second).hasExtraDOF()) {
      for (unsigned int j = 0; j < (it->second).extraDOFSize(); j++) {
        std::array<float, 4> extraDOFCuts = getExtraDOFCutsForAlignable(it->first, j);

        out << "Extra DOF " << j << " with label: " << getExtraDOFLabelForAlignable(it->first, j);
        out << "- cut              : " << std::setw(4) << extraDOFCuts.at(0) << std::setw(5) << "    "
            << "| sigCut           : " << std::setw(4) << extraDOFCuts.at(1) << std::setw(1) << " "
            << "| maxMoveCut       : " << std::setw(4) << extraDOFCuts.at(2) << std::setw(5) << "    "
            << "| maxErrorCut      : " << std::setw(4) << extraDOFCuts.at(3) << std::setw(5) << "    ";
      }
    }
  }
}