CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CondFormats/DQMObjects/src/HDQMSummary.cc

Go to the documentation of this file.
00001 #include "CondFormats/DQMObjects/interface/HDQMSummary.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 #include <algorithm>
00005                 
00006 HDQMSummary::HDQMSummary(std::vector<std::string>& userDBContent)
00007 {
00008   userDBContent_ = userDBContent;
00009   runNr_ = 0;
00010   timeValue_ = 0;
00011 }
00012 
00013 
00014 HDQMSummary::HDQMSummary(const HDQMSummary& input)
00015 {
00016   userDBContent_ = input.getUserDBContent();
00017   runNr_ = input.getTimeValue();
00018   timeValue_ = input.getRunNr();
00019   v_sum_.clear();
00020   indexes_.clear();
00021   v_sum_.insert(v_sum_.end(),input.v_sum_.begin(),input.v_sum_.end());
00022   indexes_.insert(indexes_.end(),input.indexes_.begin(),input.indexes_.end());
00023 }
00024 
00025 
00026 bool HDQMSummary::put(const uint32_t& DetId, InputVector &input, std::vector<std::string>& userContent ) 
00027 {
00028   Registry::iterator p  = std::lower_bound(indexes_.begin(),indexes_.end(),DetId,HDQMSummary::StrictWeakOrdering());
00029   
00030   if(p==indexes_.end() || p->detid!=DetId){
00031     //First request for the given DetID
00032     //Create entries for all the declared userDBContent
00033     //and fill for the provided userContent
00034  
00035     DetRegistry detregistry;
00036     detregistry.detid  = DetId;
00037     detregistry.ibegin = v_sum_.size();
00038     indexes_.insert(p,detregistry);
00039     InputVector tmp(userDBContent_.size(),-9999);
00040 
00041     for(size_t i=0;i<userContent.size();++i)
00042       tmp[getPosition(userContent[i])]=input[i];
00043     
00044     v_sum_.insert(v_sum_.end(),tmp.begin(),tmp.end());
00045   } else {
00046 
00047     if (p->detid==DetId){
00048       //I should already find the entries 
00049       //fill for the provided userContent
00050 
00051       for(size_t i=0;i<userContent.size();++i)
00052         v_sum_[p->ibegin+getPosition(userContent[i])]=input[i];
00053     }
00054   }
00055         
00056   return true;
00057 }
00058 
00059 
00060 const HDQMSummary::Range HDQMSummary::getRange(const uint32_t& DetId) const 
00061 {
00062 
00063   RegistryIterator p = std::lower_bound(indexes_.begin(),indexes_.end(),DetId,HDQMSummary::StrictWeakOrdering());
00064   if (p==indexes_.end()|| p->detid!=DetId) {
00065     return HDQMSummary::Range(v_sum_.end(),v_sum_.end()); std::cout << "not in range " << std::endl;}
00066   else 
00067     return HDQMSummary::Range(v_sum_.begin()+p->ibegin,v_sum_.begin()+p->ibegin+userDBContent_.size());
00068 }
00069 
00070 
00071 std::vector<uint32_t> HDQMSummary::getDetIds() const 
00072 {
00073   // returns vector of DetIds in map
00074   std::vector<uint32_t> DetIds_;
00075   HDQMSummary::RegistryIterator begin = indexes_.begin();
00076   HDQMSummary::RegistryIterator end   = indexes_.end();
00077   for (HDQMSummary::RegistryIterator p=begin; p != end; ++p) {
00078     DetIds_.push_back(p->detid);
00079   }
00080   return DetIds_;
00081 }
00082 
00083 
00084 
00085 const short HDQMSummary::getPosition(std::string elementName) const
00086 {
00087   // returns position of elementName in UserDBContent_
00088     
00089   std::vector<std::string>::const_iterator it = find(userDBContent_.begin(),userDBContent_.end(),elementName);  
00090   short pos = -1;
00091   if (it != userDBContent_.end()) pos = it - userDBContent_.begin();
00092   else edm::LogError("HDQMSummary") << "attempting to retrieve non existing historic DB object : "<< elementName <<std::endl;
00093   return pos;  
00094 }   
00095 
00096 
00097 
00098 void  HDQMSummary::setObj(const uint32_t& detID, std::string elementName, float value) 
00099 {
00100   // modifies value of info "elementName" for the given detID
00101   // requires that an entry has be defined beforehand for detId in DB
00102   RegistryIterator p = std::lower_bound(indexes_.begin(),indexes_.end(),detID,HDQMSummary::StrictWeakOrdering());
00103   if (p==indexes_.end()|| p->detid!=detID) 
00104     {
00105       throw cms::Exception("")
00106         <<"not allowed to modify "<< elementName << " in historic DB - SummaryObj needs to be available first !";
00107     }
00108 
00109   const HDQMSummary::Range range = getRange(detID);
00110    
00111   std::vector<float>::const_iterator it = range.first+getPosition(elementName);
00112   std::vector<float>::difference_type pos = -1;
00113   if (it != v_sum_.end()){ 
00114     pos = it - v_sum_.begin();
00115     v_sum_.at(pos) = value; }  
00116 }
00117 
00118 
00119 std::vector<float> HDQMSummary::getSummaryObj(uint32_t& detID, std::vector<std::string> list) const
00120 {  
00121   std::vector<float> SummaryObj;
00122   const HDQMSummary::Range range = getRange(detID);
00123   if (range.first != range.second ) {
00124    for (unsigned int i=0; i<list.size(); i++){ 
00125      const short pos=getPosition(list.at(i));
00126      
00127      if (pos!=-1) 
00128        SummaryObj.push_back(*((range.first)+pos));
00129      else 
00130        SummaryObj.push_back(-999.);
00131    }
00132   }
00133   else 
00134    for (unsigned int i=0; i<list.size(); i++) SummaryObj.push_back(-99.); // no summary obj has ever been inserted for this detid, most likely all related histos were not available in DQM
00135   
00136   return SummaryObj;
00137 }
00138 
00139 std::vector<float> HDQMSummary::getSummaryObj(uint32_t& detID) const
00140 {  
00141   std::vector<float> SummaryObj;
00142   const HDQMSummary::Range range = getRange(detID);
00143   if (range.first != range.second ) {
00144    for (unsigned int i=0; i<userDBContent_.size(); i++) SummaryObj.push_back(*((range.first)+i));}
00145   else {
00146    for (unsigned int i=0; i<userDBContent_.size(); i++) SummaryObj.push_back(-99.);} 
00147   return SummaryObj;
00148 }
00149 
00150 
00151 
00152 std::vector<float> HDQMSummary::getSummaryObj() const
00153 {
00154   return v_sum_;
00155 }
00156 
00157 
00158 std::vector<float> HDQMSummary::getSummaryObj(std::string elementName) const
00159 {
00160   std::vector<float> vSumElement;
00161   std::vector<uint32_t> DetIds_ = getDetIds();
00162   const short pos = getPosition(elementName);
00163    
00164   if (pos !=-1)
00165     {
00166       for (unsigned int i=0; i<DetIds_.size(); i++){
00167         const HDQMSummary::Range range = getRange(DetIds_.at(i));
00168         if (range.first != range.second ) {
00169         vSumElement.push_back(*((range.first)+pos));}
00170         else { vSumElement.push_back(-99.);}
00171     }
00172   }
00173   
00174   return vSumElement;
00175 }
00176 
00177 
00178 void  HDQMSummary::print() 
00179 {
00180   std::cout << "Nr. of detector elements in HDQMSummary object is " << indexes_.size() 
00181             << " RunNr= " << runNr_ 
00182             << " timeValue= " << timeValue_ 
00183             << std::endl;
00184 }
00185