CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondFormats/SiStripObjects/interface/SiStripNoises.h

Go to the documentation of this file.
00001 #ifndef SiStripNoises_h
00002 #define SiStripNoises_h
00003 
00004 #include<vector>
00005 #include<map>
00006 #include<iostream>
00007 #include<boost/cstdint.hpp>
00008 
00018 class SiStripNoises
00019 {
00020  public:
00021 
00022   struct ratioData{
00023     uint32_t detid;
00024     std::vector<float> values;
00025   };
00026   
00027   struct DetRegistry{
00028     uint32_t detid;
00029     uint32_t ibegin;
00030     uint32_t iend;
00031   };
00032 
00033   class StrictWeakOrdering
00034   {
00035    public:
00036     bool operator() (const DetRegistry& p,const uint32_t& i) const {return p.detid < i;}
00037   };
00038 
00039   typedef std::vector<unsigned char>                       Container;  
00040   typedef std::vector<unsigned char>::const_iterator       ContainerIterator;  
00041   typedef std::pair<ContainerIterator, ContainerIterator>  Range;      
00042   typedef std::vector<DetRegistry>                         Registry;
00043   typedef Registry::const_iterator                         RegistryIterator;
00044   typedef std::vector<uint16_t>                            InputVector;
00045 
00046   SiStripNoises(const SiStripNoises& );
00047   SiStripNoises(){}
00048   ~SiStripNoises(){}
00049 
00050   bool put(const uint32_t& detID,const InputVector &input);
00051   const Range getRange(const uint32_t& detID) const;
00052   void getDetIds(std::vector<uint32_t>& DetIds_) const;
00053   
00054   ContainerIterator getDataVectorBegin()    const {return v_noises.begin();}
00055   ContainerIterator getDataVectorEnd()      const {return v_noises.end();}
00056   RegistryIterator getRegistryVectorBegin() const {return indexes.begin();}
00057   RegistryIterator getRegistryVectorEnd()   const{return indexes.end();}
00058 
00059   static inline float getNoiseFast(const uint16_t& strip, const Range& range) {
00060     return  0.1f*float(decode(strip,range));
00061   }
00062 
00063   static float getNoise(uint16_t strip, const Range& range);
00064 
00065   void    allNoises (std::vector<float> & noises, const Range& range) const;
00066   void    setData(float noise_, InputVector& vped);
00067 
00068   void printDebug(std::stringstream& ss) const;
00069   void printSummary(std::stringstream& ss) const;
00070 
00071   std::vector<ratioData> operator / (SiStripNoises d) ;
00072 
00073  private:
00074   static  void encode(const InputVector& Vi, std::vector<unsigned char>& Vo_CHAR);
00075 
00076   static inline uint16_t decode (uint16_t strip, const Range& range);
00077 
00080   static inline uint16_t get9bits(const uint8_t * &ptr, int8_t skip);
00081 
00082   Container     v_noises; 
00083   Registry      indexes;
00084 
00085 
00086   /*
00087     const std::string print_as_binary(const uint8_t ch) const;
00088     std::string print_char_as_binary(const unsigned char ch) const;
00089     std::string print_short_as_binary(const short ch) const;
00090   */
00091 };
00092 
00095 inline uint16_t SiStripNoises::get9bits(const uint8_t * &ptr, int8_t skip) {
00096     uint8_t maskThis = (0xFF << skip);
00097     uint8_t maskThat = ((2 << skip) - 1);
00098     uint16_t ret = ( ((*ptr) & maskThis) >> skip );
00099     --ptr;
00100     return ret | ( ((*ptr) & maskThat) << (8 - skip) );
00101 }
00102 
00103 inline uint16_t SiStripNoises::decode (uint16_t strip, const Range& range) {
00104   const unsigned char *data = &*(range.second -1);  // pointer to the last byte of data
00105   static const uint16_t BITS_PER_STRIP = 9;
00106 
00107   uint32_t lowBit        = strip * BITS_PER_STRIP;
00108   uint8_t firstByteBit   = (lowBit & 7);//module 8
00109   uint8_t firstByteNBits = 8 - firstByteBit;
00110   uint8_t firstByteMask  = 0xffu << firstByteBit;
00111   uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
00112   uint16_t value         =   ((uint16_t(*(data-lowBit/8  )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
00113   
00114   /*
00115   if(strip  < 25){
00116     std::cout       << "***************DECODE*********************"<<"\n"
00117                     << "strip "<<strip << " " 
00118                     << value 
00119                     <<"\t   :"<<print_as_binary(value) 
00120                     <<"\t  :"<<print_as_binary(    ((uint16_t(*(data-lowBit/8  )) & firstByteMask) >>   firstByteBit)       )
00121                     << "-"<<print_as_binary(  ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits)    )
00122                     << "\t *(data-lowBit/8) " << print_as_binary(    *(data-lowBit/8 ))
00123                     << "\t *(data-lowBit/8-1) " << print_as_binary(    *(data-lowBit/8 -1 ))
00124                     << "\tlowBit:"<< lowBit
00125                     << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
00126                     << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
00127                     << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
00128                     << std::endl;
00129   }
00130   */
00131   return value;
00132 }
00133 
00134 
00135 #endif