File indexing completed on 2024-04-06 12:02:41
0001 #include "CondFormats/SiStripObjects/interface/SiStripSummary.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003
0004 #include <algorithm>
0005
0006 SiStripSummary::SiStripSummary(std::vector<std::string>& userDBContent) {
0007 userDBContent_ = userDBContent;
0008 runNr_ = 0;
0009 timeValue_ = 0;
0010 }
0011
0012 SiStripSummary::SiStripSummary(const SiStripSummary& input) {
0013 userDBContent_ = input.getUserDBContent();
0014 runNr_ = input.getTimeValue();
0015 timeValue_ = input.getRunNr();
0016 v_sum_.clear();
0017 indexes_.clear();
0018 v_sum_.insert(v_sum_.end(), input.v_sum_.begin(), input.v_sum_.end());
0019 indexes_.insert(indexes_.end(), input.indexes_.begin(), input.indexes_.end());
0020 }
0021
0022 bool SiStripSummary::put(const uint32_t& DetId, InputVector& input, std::vector<std::string>& userContent) {
0023 Registry::iterator p =
0024 std::lower_bound(indexes_.begin(), indexes_.end(), DetId, SiStripSummary::StrictWeakOrdering());
0025
0026 if (p == indexes_.end() || p->detid != DetId) {
0027
0028
0029
0030
0031 DetRegistry detregistry;
0032 detregistry.detid = DetId;
0033 detregistry.ibegin = v_sum_.size();
0034 indexes_.insert(p, detregistry);
0035 InputVector tmp(userDBContent_.size(), -9999);
0036
0037 for (size_t i = 0; i < userContent.size(); ++i)
0038 tmp[getPosition(userContent[i])] = input[i];
0039
0040 v_sum_.insert(v_sum_.end(), tmp.begin(), tmp.end());
0041 } else {
0042 if (p->detid == DetId) {
0043
0044
0045
0046 for (size_t i = 0; i < userContent.size(); ++i)
0047 v_sum_[p->ibegin + getPosition(userContent[i])] = input[i];
0048 }
0049 }
0050
0051 return true;
0052 }
0053
0054 bool SiStripSummary::put(sistripsummary::TrackerRegion region,
0055 InputVector& input,
0056 std::vector<std::string>& userContent) {
0057 uint32_t fakeDet = region;
0058 return put(fakeDet, input, userContent);
0059 }
0060
0061 const SiStripSummary::Range SiStripSummary::getRange(const uint32_t& DetId) const {
0062 RegistryIterator p = std::lower_bound(indexes_.begin(), indexes_.end(), DetId, SiStripSummary::StrictWeakOrdering());
0063 if (p == indexes_.end() || p->detid != DetId) {
0064 edm::LogWarning("SiStripSummary") << "not in range";
0065 return SiStripSummary::Range(v_sum_.end(), v_sum_.end());
0066 }
0067 return SiStripSummary::Range(v_sum_.begin() + p->ibegin, v_sum_.begin() + p->ibegin + userDBContent_.size());
0068 }
0069
0070 std::vector<uint32_t> SiStripSummary::getDetIds() const {
0071
0072 std::vector<uint32_t> DetIds_;
0073 SiStripSummary::RegistryIterator begin = indexes_.begin();
0074 SiStripSummary::RegistryIterator end = indexes_.end();
0075 for (SiStripSummary::RegistryIterator p = begin; p != end; ++p) {
0076 DetIds_.push_back(p->detid);
0077 }
0078 return DetIds_;
0079 }
0080
0081 const short SiStripSummary::getPosition(std::string elementName) const {
0082
0083
0084 std::vector<std::string>::const_iterator it = find(userDBContent_.begin(), userDBContent_.end(), elementName);
0085 short pos = -1;
0086 if (it != userDBContent_.end())
0087 pos = it - userDBContent_.begin();
0088 else
0089 edm::LogError("SiStripSummary") << "attempting to retrieve non existing historic DB object : " << elementName
0090 << std::endl;
0091 return pos;
0092 }
0093
0094 void SiStripSummary::setObj(const uint32_t& detID, std::string elementName, float value) {
0095
0096
0097 RegistryIterator p = std::lower_bound(indexes_.begin(), indexes_.end(), detID, SiStripSummary::StrictWeakOrdering());
0098 if (p == indexes_.end() || p->detid != detID) {
0099 throw cms::Exception("") << "not allowed to modify " << elementName
0100 << " in historic DB - SummaryObj needs to be available first !";
0101 }
0102
0103 const SiStripSummary::Range range = getRange(detID);
0104
0105 std::vector<float>::const_iterator it = range.first + getPosition(elementName);
0106 std::vector<float>::difference_type pos = -1;
0107 if (it != v_sum_.end()) {
0108 pos = it - v_sum_.begin();
0109 v_sum_.at(pos) = value;
0110 }
0111 }
0112
0113 std::vector<float> SiStripSummary::getSummaryObj(uint32_t& detID, const std::vector<std::string>& list) const {
0114 std::vector<float> SummaryObj;
0115 const SiStripSummary::Range range = getRange(detID);
0116 if (range.first != range.second) {
0117 for (unsigned int i = 0; i < list.size(); i++) {
0118 const short pos = getPosition(list.at(i));
0119
0120 if (pos != -1)
0121 SummaryObj.push_back(*((range.first) + pos));
0122 else
0123 SummaryObj.push_back(-999.);
0124 }
0125 } else
0126 for (unsigned int i = 0; i < list.size(); i++)
0127 SummaryObj.push_back(
0128 -99.);
0129
0130 return SummaryObj;
0131 }
0132
0133 std::vector<float> SiStripSummary::getSummaryObj(sistripsummary::TrackerRegion region,
0134 const std::vector<std::string>& list) const {
0135 uint32_t fakeDet = region;
0136 return getSummaryObj(fakeDet, list);
0137 }
0138
0139 std::vector<float> SiStripSummary::getSummaryObj(uint32_t& detID) const {
0140 std::vector<float> SummaryObj;
0141 const SiStripSummary::Range range = getRange(detID);
0142 if (range.first != range.second) {
0143 for (unsigned int i = 0; i < userDBContent_.size(); i++)
0144 SummaryObj.push_back(*((range.first) + i));
0145 } else {
0146 for (unsigned int i = 0; i < userDBContent_.size(); i++)
0147 SummaryObj.push_back(-99.);
0148 }
0149 return SummaryObj;
0150 }
0151
0152 std::vector<float> SiStripSummary::getSummaryObj() const { return v_sum_; }
0153
0154 std::vector<float> SiStripSummary::getSummaryObj(std::string elementName) const {
0155 std::vector<float> vSumElement;
0156 std::vector<uint32_t> DetIds_ = getDetIds();
0157 const short pos = getPosition(elementName);
0158
0159 if (pos != -1) {
0160 for (unsigned int i = 0; i < DetIds_.size(); i++) {
0161 const SiStripSummary::Range range = getRange(DetIds_.at(i));
0162 if (range.first != range.second) {
0163 vSumElement.push_back(*((range.first) + pos));
0164 } else {
0165 vSumElement.push_back(-99.);
0166 }
0167 }
0168 }
0169
0170 return vSumElement;
0171 }
0172
0173 void SiStripSummary::print() {
0174 std::cout << "Nr. of detector elements in SiStripSummary object is " << indexes_.size() << " RunNr= " << runNr_
0175 << " timeValue= " << timeValue_ << std::endl;
0176 }