CMS 3D CMS Logo

SiStripPedestals.cc
Go to the documentation of this file.
3 #include <algorithm>
4 
5 bool SiStripPedestals::put(const uint32_t& DetId, InputVector& input) {
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 }
26 
28  // get SiStripPedestals Range of DetId
29 
30  RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,SiStripPedestals::StrictWeakOrdering());
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 }
36 
37 void SiStripPedestals::getDetIds(std::vector<uint32_t>& DetIds_) const {
38  // returns vector of DetIds in map
41  for (SiStripPedestals::RegistryIterator p=begin; p != end; ++p) {
42  DetIds_.push_back(p->detid);
43  }
44 }
45 
46 
48  vped.push_back((static_cast<uint16_t> (ped) & 0x3FF)) ;
49 }
50 
51 float SiStripPedestals::getPed(const uint16_t& strip, const Range& range) const {
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 }
58 
59 void SiStripPedestals::encode(InputVector& Vi, std::vector<unsigned char>& Vo){
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 }
99 
100 uint16_t SiStripPedestals::decode (const uint16_t& strip, const Range& range) const{
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 }
130 
133 inline uint16_t SiStripPedestals::get10bits(const uint8_t * &ptr, int8_t skip) const {
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 }
140 
141 void
142 SiStripPedestals::allPeds (std::vector<int> & peds, const Range& range) const {
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 }
163 
164 void SiStripPedestals::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const
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 }
178 
179 
180 void SiStripPedestals::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const
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 }
205 
206 
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints all pedestals.
size
Write out results.
std::pair< ContainerIterator, ContainerIterator > Range
void encode(InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
uint16_t decode(const uint16_t &strip, const Range &range) const
static std::string const input
Definition: EdmProvDump.cc:48
float getPed(const uint16_t &strip, const Range &range) const
std::vector< uint16_t > InputVector
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints mean pedestal value divided for subdet, layer and mono/stereo.
#define end
Definition: vmac.h:39
Definition: value.py:1
Definition: DetId.h:18
void allPeds(std::vector< int > &pefs, const Range &range) const
void getDetIds(std::vector< uint32_t > &DetIds_) const
bool put(const uint32_t &detID, InputVector &input)
double sd
void setData(float ped, InputVector &vped)
#define begin
Definition: vmac.h:32
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
uint16_t get10bits(const uint8_t *&ptr, int8_t skip) const
const Range getRange(const uint32_t &detID) const
Registry::const_iterator RegistryIterator