CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
SiStripPedestals Class Reference

#include <SiStripPedestals.h>

Classes

struct  DetRegistry
 
class  StrictWeakOrdering
 

Public Types

typedef std::vector< char > Container
 
typedef std::vector< char >::const_iterator ContainerIterator
 
typedef std::vector< uint16_t > InputVector
 
typedef std::pair< ContainerIterator, ContainerIteratorRange
 
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
 
void printDebug (std::stringstream &ss, const TrackerTopology *trackerTopo) const
 Prints all pedestals. More...
 
void printSummary (std::stringstream &ss, const TrackerTopology *trackerTopo) const
 Prints mean pedestal value divided for subdet, layer and mono/stereo. More...
 
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
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Attributes

Registry indexes
 
Container v_pedestals
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

Stores the pedestal of every strip.
Encodes the information in a vector<char> and uses a vector<DetRegistry> to connect each range of values to the corresponding detId.
The DetRegistry struct contains the detId and two uint32_t giving the index of begin and end of the corresponding range in the vector<char>.
Has methods to return the pedestal of a given strip of of all the strips.

The printSummary method uses SiStripDetSummary. See description therein.
The printDebug method prints the pedestal value for every strip of every detId.

Definition at line 27 of file SiStripPedestals.h.

Member Typedef Documentation

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

Definition at line 50 of file SiStripPedestals.h.

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

Definition at line 51 of file SiStripPedestals.h.

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

Definition at line 55 of file SiStripPedestals.h.

Definition at line 52 of file SiStripPedestals.h.

Definition at line 53 of file SiStripPedestals.h.

typedef Registry::const_iterator SiStripPedestals::RegistryIterator

Definition at line 54 of file SiStripPedestals.h.

Constructor & Destructor Documentation

SiStripPedestals::SiStripPedestals ( )
inline

Definition at line 57 of file SiStripPedestals.h.

57 {};
SiStripPedestals::~SiStripPedestals ( )
inline

Definition at line 58 of file SiStripPedestals.h.

References getDetIds(), getRange(), input, and put().

58 {};

Member Function Documentation

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

Definition at line 142 of file SiStripPedestals.cc.

References Exception, get10bits(), MillePedeFileConverter_cfg::out, and findQualityFiles::size.

Referenced by getRegistryVectorEnd(), sistrip::FEDEmulator::retrievePedestals(), and SiStripPedestalsSubtractor::subtract_().

142  {
143  size_t mysize = ((range.second-range.first) << 3) / 10;
144  size_t size = peds.size();
145  if (mysize < size) throw cms::Exception("CorruptedData")
146  << "[SiStripPedestals::allPeds] Requested pedestals for " << peds.size() << " strips, I have it only for " << mysize << " strips\n";
147  size_t size4 = size & (~0x3), carry = size & 0x3; // we have an optimized way of unpacking 4 strips
148  const uint8_t *ptr = reinterpret_cast<const uint8_t *>(&*range.second) - 1;
149  std::vector<int>::iterator out = peds.begin(), end4 = peds.begin() + size4;
150  // we do it this baroque way instead of just loopin on all the strips because it's faster
151  // as the value of 'skip' is a constant, so the compiler can compute the masks directly
152  while (out < end4) {
153  *out = static_cast<int> ( get10bits(ptr, 0) ); ++out;
154  *out = static_cast<int> ( get10bits(ptr, 2) ); ++out;
155  *out = static_cast<int> ( get10bits(ptr, 4) ); ++out;
156  *out = static_cast<int> ( get10bits(ptr, 6) ); ++out;
157  --ptr; // every 4 strips we have to skip one more bit
158  }
159  for (size_t rem = 0; rem < carry; ++rem ) {
160  *out = static_cast<int> ( get10bits(ptr, 2*rem) ); ++out;
161  }
162 }
size
Write out results.
uint16_t get10bits(const uint8_t *&ptr, int8_t skip) const
uint16_t SiStripPedestals::decode ( const uint16_t &  strip,
const Range range 
) const
private

Definition at line 100 of file SiStripPedestals.cc.

References data, and relativeConstraints::value.

Referenced by ztail.Decoder::follow(), getPed(), getRegistryVectorEnd(), and ztail.Decoder::initial_synchronize().

100  {
101  const char *data = &*(range.second -1); // pointer to the last byte of data
102  static const uint16_t BITS_PER_STRIP = 10;
103 
104  uint32_t lowBit = strip * BITS_PER_STRIP;
105  uint8_t firstByteBit = (lowBit & 6);//module
106  uint8_t firstByteNBits = 8 - firstByteBit;
107  uint8_t firstByteMask = 0xffu << firstByteBit;
108  uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
109  uint16_t value = ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
110 
111  /*
112  if(strip < 25){
113  std::cout << "***************DECODE*********************"<<"\n"
114  << "strip "<<strip << " "
115  << value
116  <<"\t :"<<print_as_binary(value)
117  <<"\t :"<<print_as_binary( ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) )
118  << "-"<<print_as_binary( ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits) )
119  << "\t *(data-lowBit/8) " << print_as_binary( *(data-lowBit/8 ))
120  << "\t *(data-lowBit/8-1) " << print_as_binary( *(data-lowBit/8 -1 ))
121  << "\tlowBit:"<< lowBit
122  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
123  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
124  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
125  << std::endl;
126  }
127  */
128  return value;
129 }
Definition: value.py:1
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void SiStripPedestals::encode ( InputVector Vi,
std::vector< unsigned char > &  Vo_CHAR 
)
private

Definition at line 59 of file SiStripPedestals.cc.

References data, and mps_fire::i.

Referenced by getRegistryVectorEnd(), and put().

59  {
60  static const uint16_t BITS_PER_STRIP = 10;
61  const size_t VoSize = (size_t)((Vi.size() * BITS_PER_STRIP)/8+.999);
62  Vo.resize(VoSize);
63  for(size_t i = 0; i<Vo.size(); ++i)
64  Vo[i] &= 0x00u;
65 
66  for(unsigned int stripIndex =0; stripIndex<Vi.size(); ++stripIndex){
67  unsigned char* data = &Vo[Vo.size()-1];
68  uint32_t lowBit = stripIndex * BITS_PER_STRIP;
69  uint8_t firstByteBit = (lowBit & 0x6);
70  uint8_t firstByteNBits = 8 - firstByteBit;
71  uint8_t firstByteMask = 0xffu << firstByteBit;
72  uint8_t secondByteNbits = (BITS_PER_STRIP - firstByteNBits);
73  uint8_t secondByteMask = ~(0xffu << secondByteNbits);
74 
75  *(data-lowBit/8) = (*(data-lowBit/8) & ~(firstByteMask)) | ((Vi[stripIndex] & 0xffu) <<firstByteBit);
76  *(data-lowBit/8-1) = (*(data-lowBit/8-1) & ~(secondByteMask)) | ((Vi[stripIndex] >> firstByteNBits) & secondByteMask);
77 
78  /*
79  if(stripIndex < 25 ){
80  std::cout << "***************ENCODE*********************"<<std::endl
81  << "\tdata-lowBit/8 :"<<print_as_binary((*(data-lowBit/8) & ~(firstByteMask)))
82  << "-"<<print_as_binary(((Vi[stripIndex] & 0xffu) <<firstByteBit))
83  << "\tdata-lowBit/8-1 :"<<print_as_binary((*(data-lowBit/8-1) & ~(secondByteMask)))
84  << "-"<<print_as_binary((((Vi[stripIndex]>> firstByteNBits) & secondByteMask)))
85  << std::endl;
86  std::cout << "strip "<<stripIndex<<"\tvi: " << Vi[stripIndex] <<"\t"
87  << print_short_as_binary(Vi[stripIndex])
88  << "\tvo1:"<< print_char_as_binary(*(data-lowBit/8))
89  << "\tvo2:"<< print_char_as_binary(*(data-lowBit/8-1))
90  << "\tlowBit:"<< lowBit
91  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
92  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
93  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
94  << std::endl;
95  }
96  */
97  }
98 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
uint16_t SiStripPedestals::get10bits ( const uint8_t *&  ptr,
int8_t  skip 
) const
inlineprivate

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 133 of file SiStripPedestals.cc.

References createPayload::skip.

Referenced by allPeds(), and getRegistryVectorEnd().

133  {
134  uint8_t maskThis = (0xFF << skip);
135  uint8_t maskThat = ((4 << skip) - 1);
136  uint16_t ret = ( ((*ptr) & maskThis) >> skip );
137  --ptr;
138  return ret | ( ((*ptr) & maskThat) << (8 - skip) );
139 }
ContainerIterator SiStripPedestals::getDataVectorBegin ( ) const
inline

Definition at line 65 of file SiStripPedestals.h.

References v_pedestals.

65 {return v_pedestals.begin();}
ContainerIterator SiStripPedestals::getDataVectorEnd ( ) const
inline

Definition at line 66 of file SiStripPedestals.h.

References v_pedestals.

66 {return v_pedestals.end();}
void SiStripPedestals::getDetIds ( std::vector< uint32_t > &  DetIds_) const

Definition at line 37 of file SiStripPedestals.cc.

References begin, end, indexes, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by SiStripPedestalsReader::analyze(), SiStripPedestalsDQM::getActiveDetIds(), printDebug(), printSummary(), and ~SiStripPedestals().

37  {
38  // returns vector of DetIds in map
41  for (SiStripPedestals::RegistryIterator p=begin; p != end; ++p) {
42  DetIds_.push_back(p->detid);
43  }
44 }
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
Registry::const_iterator RegistryIterator
float SiStripPedestals::getPed ( const uint16_t &  strip,
const Range range 
) const

Definition at line 51 of file SiStripPedestals.cc.

References decode(), Exception, and digitizers_cfi::strip.

Referenced by SiStripPedestalsReader::analyze(), CalibrationScanTask::CalibrationScanTask(), CalibrationTask::CalibrationTask(), SiStripAPVRestorer::createCMMapRealPed(), SiStripDigitizerAlgorithm::digitize(), SiStripMonitorPedestals::fillCondDBMEs(), SiStripPedestalsDQM::fillMEsForDet(), SiStripPedestalsDQM::fillMEsForLayer(), LaserAlignment::fillPedestalProfiles(), getRegistryVectorEnd(), printDebug(), printSummary(), and DigiSimLinkAlgorithm::run().

51  {
52  if (10*strip>=(range.second-range.first)*8){
53  throw cms::Exception("CorruptedData")
54  << "[SiStripPedestals::getPed] looking for SiStripPedestals for a strip out of range: strip " << strip;
55  }
56  return static_cast<float> (decode(strip,range));
57 }
uint16_t decode(const uint16_t &strip, const Range &range) const
const SiStripPedestals::Range SiStripPedestals::getRange ( const uint32_t &  detID) const

Definition at line 27 of file SiStripPedestals.cc.

References indexes, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, AlCaHLTBitMon_ParallelJobs::p, and v_pedestals.

Referenced by SiStripPedestalsReader::analyze(), CalibrationScanTask::CalibrationScanTask(), CalibrationTask::CalibrationTask(), SiStripAPVRestorer::createCMMapRealPed(), SiStripDigitizerAlgorithm::digitize(), SiStripMonitorPedestals::fillCondDBMEs(), SiStripPedestalsDQM::fillMEsForDet(), SiStripPedestalsDQM::fillMEsForLayer(), LaserAlignment::fillPedestalProfiles(), printDebug(), printSummary(), sistrip::FEDEmulator::retrievePedestals(), DigiSimLinkAlgorithm::run(), SiStripPedestalsSubtractor::subtract_(), and ~SiStripPedestals().

27  {
28  // get SiStripPedestals Range of DetId
29 
31  if (p==indexes.end()|| p->detid!=DetId)
32  return SiStripPedestals::Range(v_pedestals.end(),v_pedestals.end());
33  else
34  return SiStripPedestals::Range(v_pedestals.begin()+p->ibegin,v_pedestals.begin()+p->iend);
35 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:18
Registry::const_iterator RegistryIterator
RegistryIterator SiStripPedestals::getRegistryVectorBegin ( ) const
inline

Definition at line 67 of file SiStripPedestals.h.

References indexes.

67 {return indexes.begin();}
RegistryIterator SiStripPedestals::getRegistryVectorEnd ( ) const
inline
void SiStripPedestals::printDebug ( std::stringstream &  ss,
const TrackerTopology trackerTopo 
) const

Prints all pedestals.

Definition at line 180 of file SiStripPedestals.cc.

References getDetIds(), getPed(), getRange(), triggerObjects_cff::id, and digitizers_cfi::strip.

Referenced by getRegistryVectorEnd().

181 {
182  std::vector<uint32_t> detid;
183  getDetIds(detid);
184 
185  ss << "Number of detids = " << detid.size() << std::endl;
186 
187  for( size_t id = 0; id < detid.size(); ++id ) {
188  SiStripPedestals::Range range = getRange(detid[id]);
189 
190  int strip = 0;
191  ss << "detid" << std::setw(15) << "strip" << std::setw(10) << "pedestal" << std::endl;
192  int detId = 0;
193  int oldDetId = 0;
194  for( int it=0; it < (range.second-range.first)*8/10; ++it ){
195  detId = detid[id];
196  if( detId != oldDetId ) {
197  oldDetId = detId;
198  ss << detid[id];
199  }
200  else ss << " ";
201  ss << std::setw(15) << strip++ << std::setw(10) << getPed(it,range) << std::endl;
202  }
203  }
204 }
std::pair< ContainerIterator, ContainerIterator > Range
float getPed(const uint16_t &strip, const Range &range) const
void getDetIds(std::vector< uint32_t > &DetIds_) const
const Range getRange(const uint32_t &detID) const
void SiStripPedestals::printSummary ( std::stringstream &  ss,
const TrackerTopology trackerTopo 
) const

Prints mean pedestal value divided for subdet, layer and mono/stereo.

Definition at line 164 of file SiStripPedestals.cc.

References getDetIds(), getPed(), getRange(), triggerObjects_cff::id, and heppy_report::summary.

Referenced by getRegistryVectorEnd().

165 {
166  std::vector<uint32_t> detid;
167  getDetIds(detid);
168  SiStripDetSummary summary{trackerTopo};
169  for( size_t id = 0; id < detid.size(); ++id ) {
170  SiStripPedestals::Range range = getRange(detid[id]);
171  for( int it=0; it < (range.second-range.first)*8/10; ++it ){
172  summary.add( detid[id], getPed(it,range) );
173  }
174  }
175  ss << "Summary of pedestals:" << std::endl;
176  summary.print(ss);
177 }
std::pair< ContainerIterator, ContainerIterator > Range
float getPed(const uint16_t &strip, const Range &range) const
void getDetIds(std::vector< uint32_t > &DetIds_) const
const Range getRange(const uint32_t &detID) const
bool SiStripPedestals::put ( const uint32_t &  detID,
InputVector input 
)

Definition at line 5 of file SiStripPedestals.cc.

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

Referenced by SiStripPedestalsBuilder::analyze(), SiStripPopConPedestalsHandlerFromDQM::dqmEndJob(), SiStripCondObjBuilderFromDb::storePedestals(), and ~SiStripPedestals().

5  {
6  // put in SiStripPedestals of DetId
7  std::vector<unsigned char> Vo_CHAR;
8  encode(input, Vo_CHAR);
9 
10  Registry::iterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripPedestals::StrictWeakOrdering());
11  if (p!=indexes.end() && p->detid==DetId)
12  return false;
13 
14  //size_t sd= input.second-input.first;
15  size_t sd= Vo_CHAR.end() - Vo_CHAR.begin();
16  DetRegistry detregistry;
17  detregistry.detid=DetId;
18  detregistry.ibegin=v_pedestals.size();
19  detregistry.iend=v_pedestals.size()+sd;
20  indexes.insert(p,detregistry);
21 
22  //v_pedestals.insert(v_pedestals.end(),input.first,input.second);
23  v_pedestals.insert(v_pedestals.end(),Vo_CHAR.begin(),Vo_CHAR.end());
24  return true;
25 }
void encode(InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
static std::string const input
Definition: EdmProvDump.cc:48
Definition: DetId.h:18
double sd
template<class Archive >
void SiStripPedestals::serialize ( Archive &  ar,
const unsigned int  version 
)
private
void SiStripPedestals::setData ( float  ped,
SiStripPedestals::InputVector vped 
)

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 88 of file SiStripPedestals.h.

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 88 of file SiStripPedestals.h.

Member Data Documentation

Registry SiStripPedestals::indexes
private
Container SiStripPedestals::v_pedestals
private

Definition at line 85 of file SiStripPedestals.h.

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