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 =
12  if (p != indexes.end() && p->detid == DetId)
13  return false;
14 
15  //size_t sd= input.second-input.first;
16  size_t sd = Vo_CHAR.end() - Vo_CHAR.begin();
17  DetRegistry detregistry;
18  detregistry.detid = DetId;
19  detregistry.ibegin = v_pedestals.size();
20  detregistry.iend = v_pedestals.size() + sd;
21  indexes.insert(p, detregistry);
22 
23  //v_pedestals.insert(v_pedestals.end(),input.first,input.second);
24  v_pedestals.insert(v_pedestals.end(), Vo_CHAR.begin(), Vo_CHAR.end());
25  return true;
26 }
27 
29  // get SiStripPedestals Range of DetId
30 
32  if (p == indexes.end() || p->detid != DetId)
33  return SiStripPedestals::Range(v_pedestals.end(), v_pedestals.end());
34  else
35  return SiStripPedestals::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend);
36 }
37 
38 void SiStripPedestals::getDetIds(std::vector<uint32_t>& DetIds_) const {
39  // returns vector of DetIds in map
42  for (SiStripPedestals::RegistryIterator p = begin; p != end; ++p) {
43  DetIds_.push_back(p->detid);
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) =
77  (*(data - lowBit / 8 - 1) & ~(secondByteMask)) | ((Vi[stripIndex] >> firstByteNBits) & secondByteMask);
78 
79  /*
80  if(stripIndex < 25 ){
81  std::cout << "***************ENCODE*********************"<<std::endl
82  << "\tdata-lowBit/8 :"<<print_as_binary((*(data-lowBit/8) & ~(firstByteMask)))
83  << "-"<<print_as_binary(((Vi[stripIndex] & 0xffu) <<firstByteBit))
84  << "\tdata-lowBit/8-1 :"<<print_as_binary((*(data-lowBit/8-1) & ~(secondByteMask)))
85  << "-"<<print_as_binary((((Vi[stripIndex]>> firstByteNBits) & secondByteMask)))
86  << std::endl;
87  std::cout << "strip "<<stripIndex<<"\tvi: " << Vi[stripIndex] <<"\t"
88  << print_short_as_binary(Vi[stripIndex])
89  << "\tvo1:"<< print_char_as_binary(*(data-lowBit/8))
90  << "\tvo2:"<< print_char_as_binary(*(data-lowBit/8-1))
91  << "\tlowBit:"<< lowBit
92  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
93  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
94  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
95  << std::endl;
96  }
97  */
98  }
99 }
100 
101 uint16_t SiStripPedestals::decode(const uint16_t& strip, const Range& range) const {
102  const char* data = &*(range.second - 1); // pointer to the last byte of data
103  static const uint16_t BITS_PER_STRIP = 10;
104 
105  uint32_t lowBit = strip * BITS_PER_STRIP;
106  uint8_t firstByteBit = (lowBit & 6); //module
107  uint8_t firstByteNBits = 8 - firstByteBit;
108  uint8_t firstByteMask = 0xffu << firstByteBit;
109  uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
110  uint16_t value = ((uint16_t(*(data - lowBit / 8)) & firstByteMask) >> firstByteBit) |
111  ((uint16_t(*(data - lowBit / 8 - 1)) & secondByteMask) << firstByteNBits);
112 
113  /*
114  if(strip < 25){
115  std::cout << "***************DECODE*********************"<<"\n"
116  << "strip "<<strip << " "
117  << value
118  <<"\t :"<<print_as_binary(value)
119  <<"\t :"<<print_as_binary( ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) )
120  << "-"<<print_as_binary( ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits) )
121  << "\t *(data-lowBit/8) " << print_as_binary( *(data-lowBit/8 ))
122  << "\t *(data-lowBit/8-1) " << print_as_binary( *(data-lowBit/8 -1 ))
123  << "\tlowBit:"<< lowBit
124  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
125  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
126  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
127  << std::endl;
128  }
129  */
130  return value;
131 }
132 
135 inline uint16_t SiStripPedestals::get10bits(const uint8_t*& ptr, int8_t skip) const {
136  uint8_t maskThis = (0xFF << skip);
137  uint8_t maskThat = ((4 << skip) - 1);
138  uint16_t ret = (((*ptr) & maskThis) >> skip);
139  --ptr;
140  return ret | (((*ptr) & maskThat) << (8 - skip));
141 }
142 
143 void SiStripPedestals::allPeds(std::vector<int>& peds, const Range& range) const {
144  size_t mysize = ((range.second - range.first) << 3) / 10;
145  size_t size = peds.size();
146  if (mysize < size)
147  throw cms::Exception("CorruptedData") << "[SiStripPedestals::allPeds] Requested pedestals for " << peds.size()
148  << " strips, I have it only for " << mysize << " strips\n";
149  size_t size4 = size & (~0x3), carry = size & 0x3; // we have an optimized way of unpacking 4 strips
150  const uint8_t* ptr = reinterpret_cast<const uint8_t*>(&*range.second) - 1;
151  std::vector<int>::iterator out = peds.begin(), end4 = peds.begin() + size4;
152  // we do it this baroque way instead of just loopin on all the strips because it's faster
153  // as the value of 'skip' is a constant, so the compiler can compute the masks directly
154  while (out < end4) {
155  *out = static_cast<int>(get10bits(ptr, 0));
156  ++out;
157  *out = static_cast<int>(get10bits(ptr, 2));
158  ++out;
159  *out = static_cast<int>(get10bits(ptr, 4));
160  ++out;
161  *out = static_cast<int>(get10bits(ptr, 6));
162  ++out;
163  --ptr; // every 4 strips we have to skip one more bit
164  }
165  for (size_t rem = 0; rem < carry; ++rem) {
166  *out = static_cast<int>(get10bits(ptr, 2 * rem));
167  ++out;
168  }
169 }
170 
171 void SiStripPedestals::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const {
172  std::vector<uint32_t> detid;
173  getDetIds(detid);
174  SiStripDetSummary summary{trackerTopo};
175  for (size_t id = 0; id < detid.size(); ++id) {
177  for (int it = 0; it < (range.second - range.first) * 8 / 10; ++it) {
178  summary.add(detid[id], getPed(it, range));
179  }
180  }
181  ss << "Summary of pedestals:" << std::endl;
182  summary.print(ss);
183 }
184 
185 void SiStripPedestals::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
186  std::vector<uint32_t> detid;
187  getDetIds(detid);
188 
189  ss << "Number of detids = " << detid.size() << std::endl;
190 
191  for (size_t id = 0; id < detid.size(); ++id) {
193 
194  int strip = 0;
195  ss << "detid" << std::setw(15) << "strip" << std::setw(10) << "pedestal" << std::endl;
196  int detId = 0;
197  int oldDetId = 0;
198  for (int it = 0; it < (range.second - range.first) * 8 / 10; ++it) {
199  detId = detid[id];
200  if (detId != oldDetId) {
201  oldDetId = detId;
202  ss << detid[id];
203  } else
204  ss << " ";
205  ss << std::setw(15) << strip++ << std::setw(10) << getPed(it, range) << std::endl;
206  }
207  }
208 }
209 
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
SiStripPedestals::DetRegistry::iend
uint32_t iend
Definition: SiStripPedestals.h:39
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
SiStripPedestals::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripPedestals.h:51
SiStripPedestals::put
bool put(const uint32_t &detID, InputVector &input)
Definition: SiStripPedestals.cc:5
SiStripPedestals::getDetIds
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: SiStripPedestals.cc:38
TrackerTopology
Definition: TrackerTopology.h:16
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SiStripPedestals::setData
void setData(float ped, InputVector &vped)
Definition: SiStripPedestals.cc:47
SiStripPedestals::RegistryIterator
Registry::const_iterator RegistryIterator
Definition: SiStripPedestals.h:53
SiStripPedestals::DetRegistry::detid
uint32_t detid
Definition: SiStripPedestals.h:37
SiStripPedestals::v_pedestals
Container v_pedestals
Definition: SiStripPedestals.h:83
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
optionsL1T.skip
skip
Definition: optionsL1T.py:30
SiStripPedestals::DetRegistry::ibegin
uint32_t ibegin
Definition: SiStripPedestals.h:38
mps_fire.end
end
Definition: mps_fire.py:242
SiStripPedestals::allPeds
void allPeds(std::vector< int > &pefs, const Range &range) const
Definition: SiStripPedestals.cc:143
SiStripPedestals::getRange
const Range getRange(const uint32_t &detID) const
Definition: SiStripPedestals.cc:28
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
SiStripPedestals::indexes
Registry indexes
Definition: SiStripPedestals.h:84
edmLumisInFiles.summary
summary
Definition: edmLumisInFiles.py:39
value
Definition: value.py:1
SiStripPedestals::encode
void encode(InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
Definition: SiStripPedestals.cc:59
SiStripPedestals::get10bits
uint16_t get10bits(const uint8_t *&ptr, int8_t skip) const
Definition: SiStripPedestals.cc:135
SiStripPedestals::printDebug
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints all pedestals.
Definition: SiStripPedestals.cc:185
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
SiStripPedestals::decode
uint16_t decode(const uint16_t &strip, const Range &range) const
Definition: SiStripPedestals.cc:101
SiStripPedestals.h
SiStripPedestals::DetRegistry
Definition: SiStripPedestals.h:36
Exception.h
SiStripDetSummary
Definition: SiStripDetSummary.h:28
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
sd
double sd
Definition: CascadeWrapper.h:113
SiStripPedestals::StrictWeakOrdering
Definition: SiStripPedestals.h:44
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
SiStripPedestals::InputVector
std::vector< uint16_t > InputVector
Definition: SiStripPedestals.h:54
SiStripPedestals::getPed
float getPed(const uint16_t &strip, const Range &range) const
Definition: SiStripPedestals.cc:51
SiStripPedestals::printSummary
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints mean pedestal value divided for subdet, layer and mono/stereo.
Definition: SiStripPedestals.cc:171
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443