CMS 3D CMS Logo

SiStripPedestals Class Reference

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

List of all members.

Public Types

typedef std::vector< char > Container
typedef std::vector< 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 allPeds (std::vector< int > &pefs, const Range &range) const
ContainerIterator getDataVectorBegin () const
ContainerIterator getDataVectorEnd () const
void getDetIds (std::vector< uint32_t > &DetIds_) const
float getPed (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, InputVector &input)
void setData (float ped, InputVector &vped)
 SiStripPedestals ()
 ~SiStripPedestals ()

Private Member Functions

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

Private Attributes

Registry indexes
Container v_pedestals

Classes

struct  DetRegistry
class  StrictWeakOrdering


Detailed Description

Definition at line 10 of file SiStripPedestals.h.


Member Typedef Documentation

typedef std::vector<char> SiStripPedestals::Container

Definition at line 31 of file SiStripPedestals.h.

typedef std::vector<char>::const_iterator SiStripPedestals::ContainerIterator

Definition at line 32 of file SiStripPedestals.h.

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

Definition at line 36 of file SiStripPedestals.h.

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

Definition at line 33 of file SiStripPedestals.h.

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

Definition at line 34 of file SiStripPedestals.h.

typedef Registry::const_iterator SiStripPedestals::RegistryIterator

Definition at line 35 of file SiStripPedestals.h.


Constructor & Destructor Documentation

SiStripPedestals::SiStripPedestals (  )  [inline]

Definition at line 38 of file SiStripPedestals.h.

00038 {};

SiStripPedestals::~SiStripPedestals (  )  [inline]

Definition at line 39 of file SiStripPedestals.h.

00039 {};


Member Function Documentation

void SiStripPedestals::allPeds ( std::vector< int > &  pefs,
const Range range 
) const

Definition at line 141 of file SiStripPedestals.cc.

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

00141                                                                               {
00142     size_t mysize  = ((range.second-range.first) << 3) / 10;
00143     size_t size = peds.size();
00144     if (mysize < size) throw cms::Exception("CorruptedData") 
00145             << "[SiStripPedestals::allPeds] Requested pedestals for " << peds.size() << " strips, I have it only for " << mysize << " strips\n";
00146     size_t size4 = size & (~0x3), carry = size & 0x3; // we have an optimized way of unpacking 4 strips
00147     const uint8_t *ptr = reinterpret_cast<const uint8_t *>(&*range.second) - 1;
00148     std::vector<int>::iterator out = peds.begin(), end4 = peds.begin() + size4;
00149     // we do it this baroque way instead of just loopin on all the strips because it's faster
00150     // as the value of 'skip' is a constant, so the compiler can compute the masks directly
00151    while (out < end4) {
00152         *out = static_cast<int> ( get10bits(ptr, 0) ); ++out;
00153         *out = static_cast<int> ( get10bits(ptr, 2) ); ++out;
00154         *out = static_cast<int> ( get10bits(ptr, 4) ); ++out;
00155         *out = static_cast<int> ( get10bits(ptr, 6) ); ++out;
00156         --ptr; // every 4 strips we have to skip one more bit
00157     } 
00158     for (size_t rem = 0; rem < carry; ++rem ) {
00159         *out = static_cast<int> ( get10bits(ptr, 2*rem) ); ++out;
00160     }
00161 }

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

Definition at line 99 of file SiStripPedestals.cc.

References data, and value.

Referenced by getPed().

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

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

Definition at line 58 of file SiStripPedestals.cc.

References data, and i.

Referenced by put().

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

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

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

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

Definition at line 132 of file SiStripPedestals.cc.

Referenced by allPeds().

00132                                                                                    {
00133     uint8_t maskThis = (0xFF << skip);
00134     uint8_t maskThat = ((4 << skip) - 1);
00135     uint16_t ret = ( ((*ptr) & maskThis) >> skip );
00136     --ptr;
00137     return ret | ( ((*ptr) & maskThat) << (8 - skip) );
00138 }

ContainerIterator SiStripPedestals::getDataVectorBegin (  )  const [inline]

Definition at line 46 of file SiStripPedestals.h.

References v_pedestals.

00046 {return v_pedestals.begin();}

ContainerIterator SiStripPedestals::getDataVectorEnd (  )  const [inline]

Definition at line 47 of file SiStripPedestals.h.

References v_pedestals.

00047 {return v_pedestals.end();}

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

Definition at line 36 of file SiStripPedestals.cc.

References begin, end, indexes, and p.

Referenced by newSiStripO2O::analyze().

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

float SiStripPedestals::getPed ( const uint16_t &  strip,
const Range range 
) const

Definition at line 50 of file SiStripPedestals.cc.

References decode(), and Exception.

Referenced by newSiStripO2O::analyze().

00050                                                                               {
00051   if (10*strip>=(range.second-range.first)*8){
00052     throw cms::Exception("CorruptedData")
00053       << "[SiStripPedestals::getPed] looking for SiStripPedestals for a strip out of range: strip " << strip;
00054   }
00055   return   static_cast<float> (decode(strip,range));
00056 }

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

Definition at line 26 of file SiStripPedestals.cc.

References indexes, p, and v_pedestals.

Referenced by newSiStripO2O::analyze().

00026                                                                                   {
00027   // get SiStripPedestals Range of DetId
00028 
00029   RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripPedestals::StrictWeakOrdering());
00030   if (p==indexes.end()|| p->detid!=DetId) 
00031     return SiStripPedestals::Range(v_pedestals.end(),v_pedestals.end()); 
00032   else 
00033     return SiStripPedestals::Range(v_pedestals.begin()+p->ibegin,v_pedestals.begin()+p->iend);
00034 }

RegistryIterator SiStripPedestals::getRegistryVectorBegin (  )  const [inline]

Definition at line 48 of file SiStripPedestals.h.

References indexes.

00048 {return indexes.begin();}

RegistryIterator SiStripPedestals::getRegistryVectorEnd (  )  const [inline]

Definition at line 49 of file SiStripPedestals.h.

References indexes.

00049 {return indexes.end();}

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

Definition at line 4 of file SiStripPedestals.cc.

References SiStripPedestals::DetRegistry::detid, encode(), SiStripPedestals::DetRegistry::ibegin, SiStripPedestals::DetRegistry::iend, indexes, p, and v_pedestals.

Referenced by SiStripPedestalsBuilder::analyze(), SiStripCondObjBuilderFromDb::buildStripRelatedObjects(), SiStripPedDB::endJob(), cms::SiStripOfflinePedNoiseToDb::endJob(), and SiStripPedestalsFakeESSource::makePedestals().

00004                                                                     {
00005   // put in SiStripPedestals of DetId
00006   std::vector<unsigned char>      Vo_CHAR;
00007   encode(input, Vo_CHAR);
00008 
00009   Registry::iterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripPedestals::StrictWeakOrdering());
00010   if (p!=indexes.end() && p->detid==DetId)
00011     return false;
00012 
00013   //size_t sd= input.second-input.first;
00014   size_t sd= Vo_CHAR.end() - Vo_CHAR.begin();
00015   DetRegistry detregistry;
00016   detregistry.detid=DetId;
00017   detregistry.ibegin=v_pedestals.size();
00018   detregistry.iend=v_pedestals.size()+sd;
00019   indexes.insert(p,detregistry);
00020 
00021   //v_pedestals.insert(v_pedestals.end(),input.first,input.second);
00022   v_pedestals.insert(v_pedestals.end(),Vo_CHAR.begin(),Vo_CHAR.end());
00023   return true;
00024 }

void SiStripPedestals::setData ( float  ped,
SiStripPedestals::InputVector vped 
)

Definition at line 46 of file SiStripPedestals.cc.

Referenced by SiStripPedestalsBuilder::analyze(), SiStripPedDB::analyze(), SiStripCondObjBuilderFromDb::buildStripRelatedObjects(), cms::SiStripOfflinePedNoiseToDb::endJob(), and SiStripPedestalsFakeESSource::makePedestals().

00046                                                                           {
00047   vped.push_back((static_cast<uint16_t>  (ped) & 0x3FF)) ;
00048 }


Member Data Documentation

Registry SiStripPedestals::indexes [private]

Definition at line 62 of file SiStripPedestals.h.

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

Container SiStripPedestals::v_pedestals [private]

Definition at line 61 of file SiStripPedestals.h.

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


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