CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondFormats/Calibration/src/mySiStripNoises.cc

Go to the documentation of this file.
00001 #include "CondFormats/Calibration/interface/mySiStripNoises.h"
00002 #include <algorithm>
00003 bool mySiStripNoises::put(const uint32_t DetId, InputVector& input) {
00004   // put in SiStripNoises of DetId
00005   std::vector<unsigned char>    Vo_CHAR;
00006   encode(input, Vo_CHAR);
00007   Registry::iterator p=std::lower_bound(indexes.begin(),indexes.end(),DetId,mySiStripNoises::StrictWeakOrdering());
00008   if (p!=indexes.end()  &&      p->detid==DetId)
00009     return false;
00010   size_t sd = Vo_CHAR.end() - Vo_CHAR.begin();
00011   DetRegistry detregistry;
00012   detregistry.detid=DetId;
00013   detregistry.ibegin=v_noises.size();
00014   detregistry.iend=v_noises.size()+sd;
00015   indexes.insert(p,detregistry);
00016   v_noises.insert(v_noises.end(),Vo_CHAR.begin(),Vo_CHAR.end());
00017   return true;
00018 }
00019 
00020 const mySiStripNoises::Range mySiStripNoises::getRange(const uint32_t& DetId) const {
00021   // get SiStripNoises Range of DetId
00022   RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,StrictWeakOrdering());
00023   if (p==indexes.end()|| p->detid!=DetId) 
00024     return mySiStripNoises::Range(v_noises.end(),v_noises.end()); 
00025   else 
00026     return mySiStripNoises::Range(v_noises.begin()+p->ibegin,v_noises.begin()+p->iend);
00027 }
00028 
00029 void mySiStripNoises::getDetIds(std::vector<uint32_t>& DetIds) const {
00030   // returns vector of DetIds in map
00031   mySiStripNoises::RegistryIterator begin = indexes.begin();
00032   mySiStripNoises::RegistryIterator end   = indexes.end();
00033   for (mySiStripNoises::RegistryIterator p=begin; p != end; ++p) {
00034     DetIds.push_back(p->detid);
00035   }
00036 }
00037 
00038 float mySiStripNoises::getNoise( const uint16_t& strip, const Range& range ) const{
00039   return   static_cast<float> (decode(strip,range)/10.0);
00040 } 
00041 
00042 void mySiStripNoises::setData(float noise_, std::vector<short>& v){
00043   v.push_back((static_cast<int16_t>  (noise_*10.0 + 0.5) & 0x01FF)) ;
00044 }
00045 
00046 void mySiStripNoises::encode(InputVector& Vi, std::vector<unsigned char>& Vo){
00047   static const uint16_t  BITS_PER_STRIP  = 9;
00048   const size_t           VoSize          = (size_t)((Vi.size() *       BITS_PER_STRIP)/8+.999);
00049   Vo.resize(VoSize);
00050   for(size_t i = 0; i<Vo.size(); ++i)
00051     Vo[i]   &=      0x00u;
00052   
00053   for(unsigned int stripIndex =0; stripIndex<Vi.size(); ++stripIndex){
00054     unsigned char*  data    =       &Vo[Vo.size()-1];
00055     uint32_t lowBit         =       stripIndex * BITS_PER_STRIP;
00056     uint8_t firstByteBit    =       (lowBit & 0x7);
00057     uint8_t firstByteNBits  =       8 - firstByteBit;
00058     uint8_t firstByteMask   =       0xffu << firstByteBit;
00059     uint8_t secondByteNbits =       (BITS_PER_STRIP - firstByteNBits);
00060     uint8_t secondByteMask  =       ~(0xffu << secondByteNbits);
00061 
00062     *(data-lowBit/8)        =       (*(data-lowBit/8)   & ~(firstByteMask))         | ((Vi[stripIndex] & 0xffu) <<firstByteBit);
00063     *(data-lowBit/8-1)      =       (*(data-lowBit/8-1) & ~(secondByteMask))        | ((Vi[stripIndex] >> firstByteNBits) & secondByteMask);
00064   }
00065 }
00066 
00067 uint16_t mySiStripNoises::decode (const uint16_t& strip, const Range& range) const{
00068   const unsigned char *data = &*(range.second -1);  // pointer to the last byte of data
00069   static const uint16_t BITS_PER_STRIP = 9;
00070   
00071   uint32_t lowBit        = strip * BITS_PER_STRIP;
00072   uint8_t firstByteBit   = (lowBit & 7);//module 8
00073   uint8_t firstByteNBits = 8 - firstByteBit;
00074   uint8_t firstByteMask  = 0xffu << firstByteBit;
00075   uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
00076   uint16_t value         =   ((uint16_t(*(data-lowBit/8  )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
00077   return value;
00078 }
00079 
00080