CMS 3D CMS Logo

SiStripNoises Class Reference

#include <CondFormats/SiStripObjects/interface/SiStripNoises.h>

List of all members.

Public Types

typedef std::vector< unsigned
char > 
Container
typedef std::vector< unsigned
char >::const_iterator 
ContainerIterator
typedef std::vector< uint16_t > InputVector
typedef std::pair
< ContainerIterator,
ContainerIterator
Range
typedef std::vector< DetRegistryRegistry
typedef Registry::const_iterator RegistryIterator

Public Member Functions

void allNoises (std::vector< float > &noises, const Range &range) const
ContainerIterator getDataVectorBegin () const
ContainerIterator getDataVectorEnd () const
void getDetIds (std::vector< uint32_t > &DetIds_) const
float getNoise (const uint16_t &strip, const Range &range) const
const Range getRange (const uint32_t &detID) const
RegistryIterator getRegistryVectorBegin () const
RegistryIterator getRegistryVectorEnd () const
bool put (const uint32_t &detID, const InputVector &input)
void setData (float noise_, InputVector &vped)
 SiStripNoises ()
 SiStripNoises (const SiStripNoises &)
 ~SiStripNoises ()

Private Member Functions

uint16_t decode (const uint16_t &strip, const Range &range) const
void encode (const InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
uint16_t get9bits (const uint8_t *&ptr, int8_t skip) const
 Get 9 bits from a bit stream, starting from the right, skipping the first 'skip' bits (0 < skip < 8).

Private Attributes

Registry indexes
Container v_noises

Classes

struct  DetRegistry
class  StrictWeakOrdering


Detailed Description

Definition at line 10 of file SiStripNoises.h.


Member Typedef Documentation

typedef std::vector<unsigned char> SiStripNoises::Container

Definition at line 26 of file SiStripNoises.h.

typedef std::vector<unsigned char>::const_iterator SiStripNoises::ContainerIterator

Definition at line 27 of file SiStripNoises.h.

typedef std::vector<uint16_t> SiStripNoises::InputVector

Definition at line 31 of file SiStripNoises.h.

typedef std::pair<ContainerIterator, ContainerIterator> SiStripNoises::Range

Definition at line 28 of file SiStripNoises.h.

typedef std::vector<DetRegistry> SiStripNoises::Registry

Definition at line 29 of file SiStripNoises.h.

typedef Registry::const_iterator SiStripNoises::RegistryIterator

Definition at line 30 of file SiStripNoises.h.


Constructor & Destructor Documentation

SiStripNoises::SiStripNoises ( const SiStripNoises input  ) 

Definition at line 4 of file SiStripNoises.cc.

References indexes, and v_noises.

00004                                                       {
00005   v_noises.clear();
00006   indexes.clear();
00007   v_noises.insert(v_noises.end(),input.v_noises.begin(),input.v_noises.end());
00008   indexes.insert(indexes.end(),input.indexes.begin(),input.indexes.end());
00009 }

SiStripNoises::SiStripNoises (  )  [inline]

Definition at line 34 of file SiStripNoises.h.

00034 {};

SiStripNoises::~SiStripNoises (  )  [inline]

Definition at line 35 of file SiStripNoises.h.

00035 {};


Member Function Documentation

void SiStripNoises::allNoises ( std::vector< float > &  noises,
const Range range 
) const

Definition at line 146 of file SiStripNoises.cc.

References Exception, get9bits(), out, ptr, and size.

00146                                                                                 {
00147     size_t mysize  = ((range.second-range.first) << 3) / 9;
00148     size_t size = noises.size();
00149     if (mysize < size) throw cms::Exception("CorruptedData") 
00150             << "[SiStripNoises::allNoises] Requested noise for " << noises.size() << " strips, I have it only for " << mysize << " strips\n";
00151     size_t size8 = size & (~0x7), carry = size & 0x7; // we have an optimized way of unpacking 8 strips
00152     const uint8_t *ptr = (&*range.second) - 1;
00153     std::vector<float>::iterator out = noises.begin(), end8 = noises.begin() + size8;
00154     // we do it this baroque way instead of just loopin on all the strips because it's faster
00155     // as the value of 'skip' is a constant, so the compiler can compute the masks directly
00156    while (out < end8) {
00157         *out = static_cast<float> ( get9bits(ptr, 0) / 10.0f ); ++out;
00158         *out = static_cast<float> ( get9bits(ptr, 1) / 10.0f ); ++out;
00159         *out = static_cast<float> ( get9bits(ptr, 2) / 10.0f ); ++out;
00160         *out = static_cast<float> ( get9bits(ptr, 3) / 10.0f ); ++out;
00161         *out = static_cast<float> ( get9bits(ptr, 4) / 10.0f ); ++out;
00162         *out = static_cast<float> ( get9bits(ptr, 5) / 10.0f ); ++out;
00163         *out = static_cast<float> ( get9bits(ptr, 6) / 10.0f ); ++out;
00164         *out = static_cast<float> ( get9bits(ptr, 7) / 10.0f ); ++out;
00165         --ptr; // every 8 strips we have to skip one more bit
00166     } 
00167     for (size_t rem = 0; rem < carry; ++rem ) {
00168         *out = static_cast<float> ( get9bits(ptr, rem) / 10.0f ); ++out;
00169     }
00170 }

uint16_t SiStripNoises::decode ( const uint16_t &  strip,
const Range range 
) const [private]

Definition at line 101 of file SiStripNoises.cc.

References data, and value.

Referenced by getNoise().

00101                                                                               {
00102   const unsigned char *data = &*(range.second -1);  // pointer to the last byte of data
00103   static const uint16_t BITS_PER_STRIP = 9;
00104 
00105   uint32_t lowBit        = strip * BITS_PER_STRIP;
00106   uint8_t firstByteBit   = (lowBit & 7);//module 8
00107   uint8_t firstByteNBits = 8 - firstByteBit;
00108   uint8_t firstByteMask  = 0xffu << firstByteBit;
00109   uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
00110   uint16_t value         =   ((uint16_t(*(data-lowBit/8  )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
00111   
00112   /*
00113   if(strip  < 25){
00114     std::cout       << "***************DECODE*********************"<<"\n"
00115                     << "strip "<<strip << " " 
00116                     << value 
00117                     <<"\t   :"<<print_as_binary(value) 
00118                     <<"\t  :"<<print_as_binary(    ((uint16_t(*(data-lowBit/8  )) & firstByteMask) >>   firstByteBit)       )
00119                     << "-"<<print_as_binary(  ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits)    )
00120                     << "\t *(data-lowBit/8) " << print_as_binary(    *(data-lowBit/8 ))
00121                     << "\t *(data-lowBit/8-1) " << print_as_binary(    *(data-lowBit/8 -1 ))
00122                     << "\tlowBit:"<< lowBit
00123                     << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
00124                     << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
00125                     << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
00126                     << std::endl;
00127   }
00128   */
00129   return value;
00130 }

void SiStripNoises::encode ( const InputVector Vi,
std::vector< unsigned char > &  Vo_CHAR 
) [private]

Definition at line 60 of file SiStripNoises.cc.

References data, and i.

Referenced by put().

00060                                                                              {
00061   static const uint16_t  BITS_PER_STRIP  = 9;
00062   const size_t           VoSize          = (size_t)((Vi.size() *       BITS_PER_STRIP)/8+.999);
00063   Vo.resize(VoSize);
00064   for(size_t i = 0; i<Vo.size(); ++i)
00065     Vo[i]   &=      0x00u;
00066   
00067   for(unsigned int stripIndex =0; stripIndex<Vi.size(); ++stripIndex){
00068     unsigned char*  data    =       &Vo[Vo.size()-1];
00069     uint32_t lowBit         =       stripIndex * BITS_PER_STRIP;
00070     uint8_t firstByteBit    =       (lowBit & 0x7);
00071     uint8_t firstByteNBits  =       8 - firstByteBit;
00072     uint8_t firstByteMask   =       0xffu << firstByteBit;
00073     uint8_t secondByteNbits =       (BITS_PER_STRIP - firstByteNBits);
00074     uint8_t secondByteMask  =       ~(0xffu << secondByteNbits);
00075 
00076     *(data-lowBit/8)        =       (*(data-lowBit/8)   & ~(firstByteMask))         | ((Vi[stripIndex] & 0xffu) <<firstByteBit);
00077     *(data-lowBit/8-1)      =       (*(data-lowBit/8-1) & ~(secondByteMask))        | ((Vi[stripIndex] >> firstByteNBits) & secondByteMask);
00078 
00079     /*
00080     if(stripIndex   < 25 ){
00081       std::cout       << "***************ENCODE*********************"<<std::endl
00082                       << "\tdata-lowBit/8     :"<<print_as_binary((*(data-lowBit/8)   & ~(firstByteMask)))
00083                       << "-"<<print_as_binary(((Vi[stripIndex] & 0xffu) <<firstByteBit))
00084                       << "\tdata-lowBit/8-1   :"<<print_as_binary((*(data-lowBit/8-1)   & ~(secondByteMask)))
00085                       << "-"<<print_as_binary((((Vi[stripIndex]>> firstByteNBits) & secondByteMask)))
00086                       << std::endl;
00087       std::cout       << "strip "<<stripIndex<<"\tvi: " << Vi[stripIndex] <<"\t"
00088                       << print_short_as_binary(Vi[stripIndex])
00089                       << "\tvo1:"<< print_char_as_binary(*(data-lowBit/8))
00090                       << "\tvo2:"<< print_char_as_binary(*(data-lowBit/8-1))
00091                       << "\tlowBit:"<< lowBit
00092                       << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
00093                       << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
00094                       << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
00095                       << std::endl;
00096         }
00097     */
00098   }
00099 }

uint16_t SiStripNoises::get9bits ( const uint8_t *&  ptr,
int8_t  skip 
) const [inline, private]

Get 9 bits from a bit stream, starting from the right, skipping the first 'skip' bits (0 < skip < 8).

Get 9 bit words from a bit stream, starting from the right, skipping the first 'skip' bits (0 < skip < 8).

Ptr must point to the rightmost bit, and is updated by this function

Ptr must point to the rightmost byte that has some bits of this word, and is updated by this function

Definition at line 137 of file SiStripNoises.cc.

Referenced by allNoises().

00137                                                                                {
00138     uint8_t maskThis = (0xFF << skip);
00139     uint8_t maskThat = ((2 << skip) - 1);
00140     uint16_t ret = ( ((*ptr) & maskThis) >> skip );
00141     --ptr;
00142     return ret | ( ((*ptr) & maskThat) << (8 - skip) );
00143 }

ContainerIterator SiStripNoises::getDataVectorBegin (  )  const [inline]

Definition at line 41 of file SiStripNoises.h.

References v_noises.

00041 {return v_noises.begin();}

ContainerIterator SiStripNoises::getDataVectorEnd (  )  const [inline]

Definition at line 42 of file SiStripNoises.h.

References v_noises.

00042 {return v_noises.end();}

void SiStripNoises::getDetIds ( std::vector< uint32_t > &  DetIds_  )  const

Definition at line 39 of file SiStripNoises.cc.

References begin, end, indexes, and p.

Referenced by newSiStripO2O::analyze().

00039                                                                 {
00040         // returns vector of DetIds in map
00041         SiStripNoises::RegistryIterator begin = indexes.begin();
00042         SiStripNoises::RegistryIterator end   = indexes.end();
00043         for (SiStripNoises::RegistryIterator p=begin; p != end; ++p) {
00044                 DetIds_.push_back(p->detid);
00045         }
00046 }

float SiStripNoises::getNoise ( const uint16_t &  strip,
const Range range 
) const

Definition at line 48 of file SiStripNoises.cc.

References decode(), and Exception.

Referenced by SiStripThreeThresholdAlgo::add(), and newSiStripO2O::analyze().

00048                                                                              {
00049         if (9*strip>=(range.second-range.first)*8){
00050                 throw cms::Exception("CorruptedData")
00051                         << "[SiStripNoises::getNoise] looking for SiStripNoises for a strip out of range: strip " << strip;
00052         }
00053         return   static_cast<float> (decode(strip,range)/10.0);
00054 }

const SiStripNoises::Range SiStripNoises::getRange ( const uint32_t &  detID  )  const

Definition at line 29 of file SiStripNoises.cc.

References indexes, p, and v_noises.

Referenced by newSiStripO2O::analyze().

00029                                                                             {
00030         // get SiStripNoises Range of DetId
00031 
00032         RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripNoises::StrictWeakOrdering());
00033         if (p==indexes.end()|| p->detid!=DetId) 
00034                 return SiStripNoises::Range(v_noises.end(),v_noises.end()); 
00035         else 
00036                 return SiStripNoises::Range(v_noises.begin()+p->ibegin,v_noises.begin()+p->iend);
00037 }

RegistryIterator SiStripNoises::getRegistryVectorBegin (  )  const [inline]

Definition at line 43 of file SiStripNoises.h.

References indexes.

00043 {return indexes.begin();}

RegistryIterator SiStripNoises::getRegistryVectorEnd (  )  const [inline]

Definition at line 44 of file SiStripNoises.h.

References indexes.

00044 {return indexes.end();}

bool SiStripNoises::put ( const uint32_t &  detID,
const InputVector input 
)

Definition at line 11 of file SiStripNoises.cc.

References SiStripNoises::DetRegistry::detid, encode(), SiStripNoises::DetRegistry::ibegin, SiStripNoises::DetRegistry::iend, indexes, p, and v_noises.

Referenced by SiStripNoisesBuilder::analyze(), SiStripCondObjBuilderFromDb::buildStripRelatedObjects(), SiStripNoiseDB::endJob(), cms::SiStripOfflinePedNoiseToDb::endJob(), SiStripNoiseDummyCalculator::getNewObject(), and SiStripNoiseFakeESSource::makeNoise().

00011                                                                        {
00012         std::vector<unsigned char>      Vo_CHAR;
00013         encode(input, Vo_CHAR);
00014 
00015         Registry::iterator p    =       std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripNoises::StrictWeakOrdering());
00016         if (p!=indexes.end()    &&      p->detid==DetId)
00017           return false;
00018 
00019         size_t sd = Vo_CHAR.end() - Vo_CHAR.begin();
00020         DetRegistry detregistry;
00021         detregistry.detid  = DetId;
00022         detregistry.ibegin = v_noises.size();
00023         detregistry.iend   = v_noises.size()+sd;
00024         indexes.insert(p,detregistry);
00025         v_noises.insert(v_noises.end(),Vo_CHAR.begin(),Vo_CHAR.end());
00026         return true;
00027 }

void SiStripNoises::setData ( float  noise_,
InputVector vped 
)

Definition at line 56 of file SiStripNoises.cc.

Referenced by SiStripNoisesBuilder::analyze(), SiStripNoiseDB::analyze(), SiStripCondObjBuilderFromDb::buildStripRelatedObjects(), cms::SiStripOfflinePedNoiseToDb::endJob(), SiStripNoiseDummyCalculator::getNewObject(), and SiStripNoiseFakeESSource::makeNoise().

00056                                                        {
00057         v.push_back((static_cast<int16_t>  (noise_*10.0 + 0.5) & 0x01FF)) ;
00058 }


Member Data Documentation

Registry SiStripNoises::indexes [private]

Definition at line 59 of file SiStripNoises.h.

Referenced by getDetIds(), getRange(), getRegistryVectorBegin(), getRegistryVectorEnd(), put(), and SiStripNoises().

Container SiStripNoises::v_noises [private]

Definition at line 58 of file SiStripNoises.h.

Referenced by getDataVectorBegin(), getDataVectorEnd(), getRange(), put(), and SiStripNoises().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:32:27 2009 for CMSSW by  doxygen 1.5.4