CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CondFormats/SiPixelObjects/src/SiPixelDbItem.cc

Go to the documentation of this file.
00001 #include "CondFormats/SiPixelObjects/interface/SiPixelDbItem.h"
00002 
00003 #include <iostream>
00004 #include <algorithm>
00005 
00006 
00026 
00027 
00028 void SiPixelDbItem::setNoise (short n)
00029 {
00030   PackedPixDbType newNoise = (n & packing_.noise_mask) << packing_.noise_shift;
00031   PackedPixDbType oldValue = packedVal_ & ( ~(packing_.noise_mask << packing_.noise_shift) );
00032   packedVal_ = oldValue | newNoise;
00033 }
00034 
00035 void SiPixelDbItem::setPedestal (short p)
00036 {
00037   PackedPixDbType newPedestal = (p & packing_.pedestal_mask) << packing_.pedestal_shift;
00038   PackedPixDbType oldValue = packedVal_ & ( ~(packing_.pedestal_mask << packing_.pedestal_shift) );
00039   packedVal_ = oldValue | newPedestal;
00040 }
00041 
00042 void SiPixelDbItem::setGain (float g)
00043 {
00044   // Convert gain into a shifted-integer
00045   int mult_factor = 1 << packing_.gain_shift;   // TO DO: check
00046   unsigned short gInIntRep = int( g * mult_factor );
00047 
00048   PackedPixDbType newGain = (gInIntRep & packing_.gain_mask) << packing_.gain_shift;
00049   PackedPixDbType oldValue = packedVal_ & ( ~(packing_.gain_mask << packing_.gain_shift) );
00050   packedVal_ = oldValue | newGain;
00051 }
00052 
00053 void SiPixelDbItem::setStatus (char s)
00054 {
00055   PackedPixDbType newStatus = (s & packing_.status_mask) << packing_.status_shift;
00056   PackedPixDbType oldValue = packedVal_ & ( ~(packing_.status_mask << packing_.status_shift) );
00057   packedVal_ = oldValue | newStatus;
00058 }
00059 
00060 
00061 
00063 void SiPixelDbItem::set( short noise, short pedestal, float gain, char status) 
00064 {
00065   // Convert gain into a shifted-integer
00066   int mult_factor = 1 << packing_.gain_shift;   // TO DO: check usage here
00067   unsigned short gInIntRep = int( gain * mult_factor );
00068 
00069   packedVal_ = 
00070     (noise     << packing_.noise_shift)     | 
00071     (pedestal  << packing_.pedestal_shift)  | 
00072     (gInIntRep << packing_.gain_shift)      |
00073     (status    << packing_.status_shift);
00074 }
00075 
00076 
00077 
00078 
00079 SiPixelDbItem::Packing::Packing(int noise_w, int pedestal_w, 
00080                                 int gain_w, int status_w)
00081   : noise_width(noise_w), pedestal_width(pedestal_w), status_width(status_w) 
00082 {
00083   // Constructor: pre-computes masks and shifts from field widths
00084   // Order of fields (from right to left) is
00085   // noise, pedestal, gain, status count.
00086   
00087   if ( noise_w+pedestal_w+gain_w+status_w != 32) {
00088     std::cout << std::endl << "Error in SiPixelDbItem::Packing constructor:" 
00089               << "sum of field widths != 32" << std::endl;
00090     // TO DO: throw an exception?
00091   }
00092 
00093   // Fields are counted from right to left!
00094   
00095   noise_shift     = 0;
00096   pedestal_shift  = noise_shift + noise_w;
00097   gain_shift    = pedestal_shift + pedestal_w;
00098   status_shift     = gain_shift + gain_w;
00099 
00100   // Ensure the complement of the correct 
00101   // number of bits:
00102   PackedPixDbType zero32 = 0;  // 32-bit wide
00103 
00104   noise_mask     = ~(~zero32 << noise_w);
00105   pedestal_mask  = ~(~zero32 << pedestal_w);
00106   gain_mask    = ~(~zero32 << gain_w);
00107   status_mask     = ~(~zero32 << status_w);
00108 }
00109 
00110 //  Initialize the packing (order is: noise, pedestal, gain, status)
00111 SiPixelDbItem::Packing SiPixelDbItem::packing_( 8, 8, 8, 8);  // TO DO: TBD
00112 
00113