Go to the documentation of this file.00001 #include "CondFormats/SiStripObjects/interface/SiStripSummary.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003
00004 #include <algorithm>
00005
00006 SiStripSummary::SiStripSummary(std::vector<std::string>& userDBContent)
00007 {
00008 userDBContent_ = userDBContent;
00009 runNr_ = 0;
00010 timeValue_ = 0;
00011 }
00012
00013
00014 SiStripSummary::SiStripSummary(const SiStripSummary& 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 SiStripSummary::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,SiStripSummary::StrictWeakOrdering());
00029
00030 if(p==indexes_.end() || p->detid!=DetId){
00031
00032
00033
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
00049
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 bool SiStripSummary::put(sistripsummary::TrackerRegion region, InputVector &input, std::vector<std::string>& userContent ) {
00061
00062 uint32_t fakeDet = region;
00063 return put(fakeDet, input, userContent);
00064 }
00065
00066
00067 const SiStripSummary::Range SiStripSummary::getRange(const uint32_t& DetId) const
00068 {
00069
00070 RegistryIterator p = std::lower_bound(indexes_.begin(),indexes_.end(),DetId,SiStripSummary::StrictWeakOrdering());
00071 if (p==indexes_.end()|| p->detid!=DetId) {
00072 return SiStripSummary::Range(v_sum_.end(),v_sum_.end()); std::cout << "not in range " << std::endl;}
00073 else
00074 return SiStripSummary::Range(v_sum_.begin()+p->ibegin,v_sum_.begin()+p->ibegin+userDBContent_.size());
00075 }
00076
00077
00078 std::vector<uint32_t> SiStripSummary::getDetIds() const
00079 {
00080
00081 std::vector<uint32_t> DetIds_;
00082 SiStripSummary::RegistryIterator begin = indexes_.begin();
00083 SiStripSummary::RegistryIterator end = indexes_.end();
00084 for (SiStripSummary::RegistryIterator p=begin; p != end; ++p) {
00085 DetIds_.push_back(p->detid);
00086 }
00087 return DetIds_;
00088 }
00089
00090
00091
00092 const short SiStripSummary::getPosition(std::string elementName) const
00093 {
00094
00095
00096 std::vector<std::string>::const_iterator it = find(userDBContent_.begin(),userDBContent_.end(),elementName);
00097 short pos = -1;
00098 if (it != userDBContent_.end()) pos = it - userDBContent_.begin();
00099 else edm::LogError("SiStripSummary") << "attempting to retrieve non existing historic DB object : "<< elementName <<std::endl;
00100 return pos;
00101 }
00102
00103
00104
00105 void SiStripSummary::setObj(const uint32_t& detID, std::string elementName, float value)
00106 {
00107
00108
00109 RegistryIterator p = std::lower_bound(indexes_.begin(),indexes_.end(),detID,SiStripSummary::StrictWeakOrdering());
00110 if (p==indexes_.end()|| p->detid!=detID)
00111 {
00112 throw cms::Exception("")
00113 <<"not allowed to modify "<< elementName << " in historic DB - SummaryObj needs to be available first !";
00114 }
00115
00116 const SiStripSummary::Range range = getRange(detID);
00117
00118 std::vector<float>::const_iterator it = range.first+getPosition(elementName);
00119 std::vector<float>::difference_type pos = -1;
00120 if (it != v_sum_.end()){
00121 pos = it - v_sum_.begin();
00122 v_sum_.at(pos) = value; }
00123 }
00124
00125
00126 std::vector<float> SiStripSummary::getSummaryObj(uint32_t& detID, std::vector<std::string> list) const
00127 {
00128 std::vector<float> SummaryObj;
00129 const SiStripSummary::Range range = getRange(detID);
00130 if (range.first != range.second ) {
00131 for (unsigned int i=0; i<list.size(); i++){
00132 const short pos=getPosition(list.at(i));
00133
00134 if (pos!=-1)
00135 SummaryObj.push_back(*((range.first)+pos));
00136 else
00137 SummaryObj.push_back(-999.);
00138 }
00139 }
00140 else
00141 for (unsigned int i=0; i<list.size(); i++) SummaryObj.push_back(-99.);
00142
00143 return SummaryObj;
00144 }
00145
00146 std::vector<float> SiStripSummary::getSummaryObj(sistripsummary::TrackerRegion region, std::vector<std::string> list) const
00147 {
00148
00149 uint32_t fakeDet = region;
00150 return getSummaryObj(fakeDet,list);
00151 }
00152
00153 std::vector<float> SiStripSummary::getSummaryObj(uint32_t& detID) const
00154 {
00155 std::vector<float> SummaryObj;
00156 const SiStripSummary::Range range = getRange(detID);
00157 if (range.first != range.second ) {
00158 for (unsigned int i=0; i<userDBContent_.size(); i++) SummaryObj.push_back(*((range.first)+i));}
00159 else {
00160 for (unsigned int i=0; i<userDBContent_.size(); i++) SummaryObj.push_back(-99.);}
00161 return SummaryObj;
00162 }
00163
00164
00165
00166 std::vector<float> SiStripSummary::getSummaryObj() const
00167 {
00168 return v_sum_;
00169 }
00170
00171
00172 std::vector<float> SiStripSummary::getSummaryObj(std::string elementName) const
00173 {
00174 std::vector<float> vSumElement;
00175 std::vector<uint32_t> DetIds_ = getDetIds();
00176 const short pos = getPosition(elementName);
00177
00178 if (pos !=-1)
00179 {
00180 for (unsigned int i=0; i<DetIds_.size(); i++){
00181 const SiStripSummary::Range range = getRange(DetIds_.at(i));
00182 if (range.first != range.second ) {
00183 vSumElement.push_back(*((range.first)+pos));}
00184 else { vSumElement.push_back(-99.);}
00185 }
00186 }
00187
00188 return vSumElement;
00189 }
00190
00191
00192 void SiStripSummary::print()
00193 {
00194 std::cout << "Nr. of detector elements in SiStripSummary object is " << indexes_.size()
00195 << " RunNr= " << runNr_
00196 << " timeValue= " << timeValue_
00197 << std::endl;
00198 }
00199