00001 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004
00005 bool SiStripApvGain::put(const uint32_t& DetId, Range input) {
00006
00007 RegistryIterator p = std::lower_bound(v_detids.begin(),v_detids.end(),DetId);
00008 if (p!=v_detids.end() && *p==DetId){
00009 edm::LogError("SiStripApvGain") << "[" << __PRETTY_FUNCTION__ << "] SiStripApvGain for DetID " << DetId << " is already stored. Skippig this put" << std::endl;
00010 return false;
00011 }
00012
00013 unsigned int sd= input.second-input.first;
00014 unsigned int pd= p-v_detids.begin();
00015
00016 unsigned int ibegin=v_gains.size();
00017 unsigned int iend =v_gains.size()+sd;
00018 v_detids.insert(p,DetId);
00019 v_ibegin.insert(v_ibegin.begin()+pd,ibegin);
00020 v_iend.insert(v_iend.begin()+pd,iend);
00021
00022 v_gains.insert(v_gains.end(),input.first,input.second);
00023 return true;
00024 }
00025
00026 const SiStripApvGain::Range SiStripApvGain::getRange(const uint32_t& DetId) const {
00027
00028 RegistryConstIterator p = std::lower_bound(v_detids.begin(),v_detids.end(),DetId);
00029 if (p==v_detids.end() || *p!=DetId)
00030 return SiStripApvGain::Range(v_gains.end(),v_gains.end());
00031 else{
00032 unsigned int pd= p-v_detids.begin();
00033 unsigned int ibegin = *(v_ibegin.begin()+pd);
00034 unsigned int iend = *(v_iend.begin()+pd);
00035 return SiStripApvGain::Range(v_gains.begin()+ibegin,v_gains.begin()+iend);
00036 }
00037 }
00038
00039 void SiStripApvGain::getDetIds(std::vector<uint32_t>& DetIds_) const {
00040
00041
00042 DetIds_.insert(DetIds_.begin(),v_detids.begin(),v_detids.end());
00043 }
00044
00045 float SiStripApvGain::getStripGain(const uint16_t& strip, const Range& range) const {
00046 uint16_t apv = (uint16_t) (strip/128);
00047 if (apv>=range.second-range.first){
00048 throw cms::Exception("CorruptedData")
00049 << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for a strip out of range: strip " << strip << " apv " << apv << std::endl;
00050 }
00051
00052
00053
00054 return *(range.first+apv);
00055
00056 }
00057
00058 float SiStripApvGain::getApvGain(const uint16_t& apv, const Range& range) const {
00059 if (apv>=range.second-range.first){
00060 throw cms::Exception("CorruptedData")
00061 << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for an apv out of range: apv " << apv << std::endl;
00062 }
00063
00064
00065
00066 return *(range.first+apv);
00067 }
00068