Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:05

0001 #include "CondFormats/DQMObjects/interface/HDQMSummary.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 #include <algorithm>
0005 
0006 HDQMSummary::HDQMSummary(std::vector<std::string>& userDBContent) {
0007   userDBContent_ = userDBContent;
0008   runNr_ = 0;
0009   timeValue_ = 0;
0010 }
0011 
0012 HDQMSummary::HDQMSummary(const HDQMSummary& 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 HDQMSummary::put(const uint32_t& DetId, InputVector& input, std::vector<std::string>& userContent) {
0023   Registry::iterator p = std::lower_bound(indexes_.begin(), indexes_.end(), DetId, HDQMSummary::StrictWeakOrdering());
0024 
0025   if (p == indexes_.end() || p->detid != DetId) {
0026     //First request for the given DetID
0027     //Create entries for all the declared userDBContent
0028     //and fill for the provided userContent
0029 
0030     DetRegistry detregistry;
0031     detregistry.detid = DetId;
0032     detregistry.ibegin = v_sum_.size();
0033     indexes_.insert(p, detregistry);
0034     InputVector tmp(userDBContent_.size(), -9999);
0035 
0036     for (size_t i = 0; i < userContent.size(); ++i)
0037       tmp[getPosition(userContent[i])] = input[i];
0038 
0039     v_sum_.insert(v_sum_.end(), tmp.begin(), tmp.end());
0040   } else {
0041     if (p->detid == DetId) {
0042       //I should already find the entries
0043       //fill for the provided userContent
0044 
0045       for (size_t i = 0; i < userContent.size(); ++i)
0046         v_sum_[p->ibegin + getPosition(userContent[i])] = input[i];
0047     }
0048   }
0049 
0050   return true;
0051 }
0052 
0053 const HDQMSummary::Range HDQMSummary::getRange(const uint32_t& DetId) const {
0054   RegistryIterator p = std::lower_bound(indexes_.begin(), indexes_.end(), DetId, HDQMSummary::StrictWeakOrdering());
0055   if (p == indexes_.end() || p->detid != DetId) {
0056     edm::LogWarning("HDQMSummary") << "not in range";
0057     return HDQMSummary::Range(v_sum_.end(), v_sum_.end());
0058   }
0059   return HDQMSummary::Range(v_sum_.begin() + p->ibegin, v_sum_.begin() + p->ibegin + userDBContent_.size());
0060 }
0061 
0062 std::vector<uint32_t> HDQMSummary::getDetIds() const {
0063   // returns vector of DetIds in map
0064   std::vector<uint32_t> DetIds_;
0065   HDQMSummary::RegistryIterator begin = indexes_.begin();
0066   HDQMSummary::RegistryIterator end = indexes_.end();
0067   for (HDQMSummary::RegistryIterator p = begin; p != end; ++p) {
0068     DetIds_.push_back(p->detid);
0069   }
0070   return DetIds_;
0071 }
0072 
0073 const short HDQMSummary::getPosition(std::string elementName) const {
0074   // returns position of elementName in UserDBContent_
0075 
0076   std::vector<std::string>::const_iterator it = find(userDBContent_.begin(), userDBContent_.end(), elementName);
0077   short pos = -1;
0078   if (it != userDBContent_.end())
0079     pos = it - userDBContent_.begin();
0080   else
0081     edm::LogError("HDQMSummary") << "attempting to retrieve non existing historic DB object : " << elementName
0082                                  << std::endl;
0083   return pos;
0084 }
0085 
0086 void HDQMSummary::setObj(const uint32_t& detID, std::string elementName, float value) {
0087   // modifies value of info "elementName" for the given detID
0088   // requires that an entry has be defined beforehand for detId in DB
0089   RegistryIterator p = std::lower_bound(indexes_.begin(), indexes_.end(), detID, HDQMSummary::StrictWeakOrdering());
0090   if (p == indexes_.end() || p->detid != detID) {
0091     throw cms::Exception("") << "not allowed to modify " << elementName
0092                              << " in historic DB - SummaryObj needs to be available first !";
0093   }
0094 
0095   const HDQMSummary::Range range = getRange(detID);
0096 
0097   std::vector<float>::const_iterator it = range.first + getPosition(elementName);
0098   std::vector<float>::difference_type pos = -1;
0099   if (it != v_sum_.end()) {
0100     pos = it - v_sum_.begin();
0101     v_sum_.at(pos) = value;
0102   }
0103 }
0104 
0105 std::vector<float> HDQMSummary::getSummaryObj(uint32_t& detID, const std::vector<std::string>& _list) const {
0106   std::vector<std::string> list = _list;
0107   std::vector<float> SummaryObj;
0108   const HDQMSummary::Range range = getRange(detID);
0109   if (range.first != range.second) {
0110     for (unsigned int i = 0; i < list.size(); i++) {
0111       const short pos = getPosition(list.at(i));
0112 
0113       if (pos != -1)
0114         SummaryObj.push_back(*((range.first) + pos));
0115       else
0116         SummaryObj.push_back(-999.);
0117     }
0118   } else
0119     for (unsigned int i = 0; i < list.size(); i++)
0120       SummaryObj.push_back(
0121           -99.);  // no summary obj has ever been inserted for this detid, most likely all related histos were not available in DQM
0122 
0123   return SummaryObj;
0124 }
0125 
0126 std::vector<float> HDQMSummary::getSummaryObj(uint32_t& detID) const {
0127   std::vector<float> SummaryObj;
0128   const HDQMSummary::Range range = getRange(detID);
0129   if (range.first != range.second) {
0130     for (unsigned int i = 0; i < userDBContent_.size(); i++)
0131       SummaryObj.push_back(*((range.first) + i));
0132   } else {
0133     for (unsigned int i = 0; i < userDBContent_.size(); i++)
0134       SummaryObj.push_back(-99.);
0135   }
0136   return SummaryObj;
0137 }
0138 
0139 std::vector<float> HDQMSummary::getSummaryObj() const { return v_sum_; }
0140 
0141 std::vector<float> HDQMSummary::getSummaryObj(std::string elementName) const {
0142   std::vector<float> vSumElement;
0143   std::vector<uint32_t> DetIds_ = getDetIds();
0144   const short pos = getPosition(elementName);
0145 
0146   if (pos != -1) {
0147     for (unsigned int i = 0; i < DetIds_.size(); i++) {
0148       const HDQMSummary::Range range = getRange(DetIds_.at(i));
0149       if (range.first != range.second) {
0150         vSumElement.push_back(*((range.first) + pos));
0151       } else {
0152         vSumElement.push_back(-99.);
0153       }
0154     }
0155   }
0156 
0157   return vSumElement;
0158 }
0159 
0160 void HDQMSummary::print() {
0161   std::cout << "Nr. of detector elements in HDQMSummary object is " << indexes_.size() << " RunNr= " << runNr_
0162             << " timeValue= " << timeValue_ << std::endl;
0163 }