CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CondFormats/SiStripObjects/src/SiStripApvGain.cc

Go to the documentation of this file.
00001 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
00005 
00006 #include <algorithm>
00007 
00008 bool SiStripApvGain::put(const uint32_t& DetId, Range input) {
00009   // put in SiStripApvGain of DetId
00010   RegistryIterator p = std::lower_bound(v_detids.begin(),v_detids.end(),DetId);
00011   if (p!=v_detids.end() && *p==DetId){
00012     edm::LogError("SiStripApvGain") << "[" << __PRETTY_FUNCTION__ << "] SiStripApvGain for DetID " << DetId << " is already stored. Skippig this put" << std::endl;
00013     return false;
00014   }
00015  
00016   unsigned int sd= input.second-input.first; 
00017   unsigned int pd= p-v_detids.begin();
00018 
00019   unsigned int ibegin=v_gains.size();
00020   unsigned int iend  =v_gains.size()+sd;
00021   v_detids.insert(p,DetId);
00022   v_ibegin.insert(v_ibegin.begin()+pd,ibegin);
00023   v_iend.insert(v_iend.begin()+pd,iend);
00024 
00025   v_gains.insert(v_gains.end(),input.first,input.second);
00026   return true;
00027 }
00028 
00029 const SiStripApvGain::Range SiStripApvGain::getRange(const uint32_t& DetId) const {
00030   // get SiStripApvGain Range of DetId
00031   RegistryConstIterator p = std::lower_bound(v_detids.begin(),v_detids.end(),DetId);
00032   if (p==v_detids.end() || *p!=DetId) 
00033     return SiStripApvGain::Range(v_gains.end(),v_gains.end()); 
00034   else{ 
00035     unsigned int pd= p-v_detids.begin();
00036     unsigned int ibegin = *(v_ibegin.begin()+pd);
00037     unsigned int iend   = *(v_iend.begin()+pd);    
00038     return SiStripApvGain::Range(v_gains.begin()+ibegin,v_gains.begin()+iend);
00039   }
00040 }
00041 
00042 void SiStripApvGain::getDetIds(std::vector<uint32_t>& DetIds_) const {
00043   // returns vector of DetIds in map
00044   //  DetIds_=v_detids;
00045   DetIds_.insert(DetIds_.begin(),v_detids.begin(),v_detids.end());
00046 }
00047 
00048 float SiStripApvGain::getStripGain(const uint16_t& strip, const Range& range) const {
00049   uint16_t apv = (uint16_t) (strip/128);
00050   if (apv>=range.second-range.first){
00051     throw cms::Exception("CorruptedData")
00052       << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for a strip out of range: strip " << strip << " apv " << apv << std::endl;
00053   }
00054   
00055   //  return static_cast<float> (*(range.first+apv));
00056 
00057   return *(range.first+apv);
00058 
00059 }
00060 
00061 float SiStripApvGain::getApvGain(const uint16_t& apv, const Range& range) const {
00062   if (apv>=range.second-range.first){
00063     throw cms::Exception("CorruptedData")
00064       << "[SiStripApvGain::getApvGain] looking for SiStripApvGain for an apv out of range: apv " << apv << std::endl;
00065   }
00066   
00067   //  return static_cast<float> (*(range.first+apv));
00068 
00069   return *(range.first+apv);
00070 }
00071 
00072 void SiStripApvGain::printDebug(std::stringstream & ss) const
00073 {
00074   std::vector<unsigned int>::const_iterator detid = v_detids.begin();
00075   ss << "Number of detids " << v_detids.size() << std::endl;
00076 
00077   for( ; detid != v_detids.end(); ++detid ) {
00078     SiStripApvGain::Range range = getRange(*detid);
00079     int apv=0;
00080     for( int it=0; it < range.second - range.first; ++it ) {
00081       ss << "detid " << *detid << " \t"
00082          << " apv " << apv++ << " \t"
00083          << getApvGain(it,range) << " \t" 
00084          << std::endl;          
00085     } 
00086   }
00087 }
00088 
00089 void SiStripApvGain::printSummary(std::stringstream & ss) const
00090 {
00091   SiStripDetSummary summaryGain;
00092 
00093   std::vector<uint32_t>::const_iterator detid = v_detids.begin();
00094   for( ; detid != v_detids.end(); ++detid ) {
00095     Range range = getRange(*detid);
00096     for( int it=0; it < range.second - range.first; ++it ) {
00097       summaryGain.add(*detid, getApvGain(it, range));
00098     } 
00099   }
00100   ss << "Summary of gain values:" << std::endl;
00101   summaryGain.print(ss, true);
00102 }