00001 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 #include <cassert>
00005
00006 bool SiStripThreshold::put(const uint32_t& DetId, InputVector vect) {
00007
00008 Registry::iterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripThreshold::StrictWeakOrdering());
00009 if (p!=indexes.end() && p->detid==DetId){
00010 edm::LogError("SiStripThreshold") << "[" << __PRETTY_FUNCTION__ << "] SiStripThreshold for DetID " << DetId << " is already stored. Skippig this put" << std::endl;
00011 return false;
00012 }
00013
00014 SiStripThreshold::Container::iterator new_end=compact(vect);
00015
00016 size_t sd= new_end-vect.begin();
00017 DetRegistry detregistry;
00018 detregistry.detid=DetId;
00019 detregistry.ibegin=v_threshold.size();
00020 detregistry.iend=v_threshold.size()+sd;
00021 indexes.insert(p,detregistry);
00022
00023 v_threshold.insert(v_threshold.end(),vect.begin(),new_end);
00024
00025 return true;
00026 }
00027
00028 SiStripThreshold::Container::iterator SiStripThreshold::compact(Container& input) {
00029 std::stable_sort(input.begin(),input.end());
00030 return std::unique(input.begin(),input.end());
00031 }
00032
00033 const SiStripThreshold::Range SiStripThreshold::getRange(const uint32_t& DetId) const {
00034
00035
00036 RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripThreshold::StrictWeakOrdering());
00037 if (p==indexes.end()|| p->detid!=DetId)
00038 return SiStripThreshold::Range(v_threshold.end(),v_threshold.end());
00039 else
00040 return SiStripThreshold::Range(v_threshold.begin()+p->ibegin,v_threshold.begin()+p->iend);
00041 }
00042
00043
00044 void SiStripThreshold::getDetIds(std::vector<uint32_t>& DetIds_) const {
00045
00046 SiStripThreshold::RegistryIterator begin = indexes.begin();
00047 SiStripThreshold::RegistryIterator end = indexes.end();
00048 for (SiStripThreshold::RegistryIterator p=begin; p != end; ++p) {
00049 DetIds_.push_back(p->detid);
00050 }
00051 }
00052
00053 void SiStripThreshold::setData(const uint16_t& strip, const float& lTh,const float& hTh, Container& vthr){
00054 Data a;
00055 a.encode(strip,lTh,hTh);
00056 vthr.push_back(a);
00057 }
00058
00059 SiStripThreshold::Data SiStripThreshold::getData(const uint16_t& strip, const Range& range) const {
00060 uint16_t estrip=(strip & sistrip::FirstThStripMask_)<<sistrip::FirstThStripShift_ | (63 & sistrip::HighThStripMask_);
00061 ContainerIterator p = std::upper_bound(range.first,range.second,estrip,SiStripThreshold::dataStrictWeakOrdering());
00062 if (p!=range.first){
00063 return *(--p);
00064 }
00065 else{
00066 throw cms::Exception("CorruptedData")
00067 << "[SiStripThreshold::getData] asking for data for a strip " << strip << " lower then the first stored strip " << p->getFirstStrip();
00068 }
00069 }
00070
00071 void SiStripThreshold::allThresholds(std::vector<float> &lowThs, std::vector<float> &highThs, const Range& range) const {
00072 ContainerIterator it = range.first;
00073 size_t strips = lowThs.size();
00074 assert(strips == highThs.size());
00075 while (it != range.second) {
00076 size_t firstStrip = it->getFirstStrip();
00077
00078 float high = it->getHth(), low = it->getLth();
00079
00080 ++it;
00081 size_t lastStrip = (it == range.second ? strips : it->getFirstStrip());
00082
00083 if (lastStrip > strips) {
00084 it = range.second;
00085 lastStrip = strips;
00086 }
00087 std::fill( & lowThs[firstStrip] , & lowThs[lastStrip] , low );
00088 std::fill( & highThs[firstStrip], & highThs[lastStrip], high );
00089 }
00090 }