CMS 3D CMS Logo

mySiStripNoises.cc
Go to the documentation of this file.
2 #include <algorithm>
3 bool mySiStripNoises::put(const uint32_t DetId, InputVector& input) {
4  // put in SiStripNoises of DetId
5  std::vector<unsigned char> Vo_CHAR;
6  encode(input, Vo_CHAR);
7  Registry::iterator p=std::lower_bound(indexes.begin(),indexes.end(),DetId,mySiStripNoises::StrictWeakOrdering());
8  if (p!=indexes.end() && p->detid==DetId)
9  return false;
10  size_t sd = Vo_CHAR.end() - Vo_CHAR.begin();
11  DetRegistry detregistry;
12  detregistry.detid=DetId;
13  detregistry.ibegin=v_noises.size();
14  detregistry.iend=v_noises.size()+sd;
15  indexes.insert(p,detregistry);
16  v_noises.insert(v_noises.end(),Vo_CHAR.begin(),Vo_CHAR.end());
17  return true;
18 }
19 
21  // get SiStripNoises Range of DetId
22  RegistryIterator p = std::lower_bound(indexes.begin(),indexes.end(),DetId,StrictWeakOrdering());
23  if (p==indexes.end()|| p->detid!=DetId)
24  return mySiStripNoises::Range(v_noises.end(),v_noises.end());
25  else
26  return mySiStripNoises::Range(v_noises.begin()+p->ibegin,v_noises.begin()+p->iend);
27 }
28 
29 void mySiStripNoises::getDetIds(std::vector<uint32_t>& DetIds) const {
30  // returns vector of DetIds in map
33  for (mySiStripNoises::RegistryIterator p=begin; p != end; ++p) {
34  DetIds.push_back(p->detid);
35  }
36 }
37 
38 float mySiStripNoises::getNoise( const uint16_t& strip, const Range& range ) const{
39  return static_cast<float> (decode(strip,range)/10.0);
40 }
41 
42 void mySiStripNoises::setData(float noise_, std::vector<short>& v){
43  v.push_back((static_cast<int16_t> (noise_*10.0 + 0.5) & 0x01FF)) ;
44 }
45 
46 void mySiStripNoises::encode(InputVector& Vi, std::vector<unsigned char>& Vo){
47  static const uint16_t BITS_PER_STRIP = 9;
48  const size_t VoSize = (size_t)((Vi.size() * BITS_PER_STRIP)/8+.999);
49  Vo.resize(VoSize);
50  for(size_t i = 0; i<Vo.size(); ++i)
51  Vo[i] &= 0x00u;
52 
53  for(unsigned int stripIndex =0; stripIndex<Vi.size(); ++stripIndex){
54  unsigned char* data = &Vo[Vo.size()-1];
55  uint32_t lowBit = stripIndex * BITS_PER_STRIP;
56  uint8_t firstByteBit = (lowBit & 0x7);
57  uint8_t firstByteNBits = 8 - firstByteBit;
58  uint8_t firstByteMask = 0xffu << firstByteBit;
59  uint8_t secondByteNbits = (BITS_PER_STRIP - firstByteNBits);
60  uint8_t secondByteMask = ~(0xffu << secondByteNbits);
61 
62  *(data-lowBit/8) = (*(data-lowBit/8) & ~(firstByteMask)) | ((Vi[stripIndex] & 0xffu) <<firstByteBit);
63  *(data-lowBit/8-1) = (*(data-lowBit/8-1) & ~(secondByteMask)) | ((Vi[stripIndex] >> firstByteNBits) & secondByteMask);
64  }
65 }
66 
67 uint16_t mySiStripNoises::decode (const uint16_t& strip, const Range& range) const{
68  const unsigned char *data = &*(range.second -1); // pointer to the last byte of data
69  static const uint16_t BITS_PER_STRIP = 9;
70 
71  uint32_t lowBit = strip * BITS_PER_STRIP;
72  uint8_t firstByteBit = (lowBit & 7);//module 8
73  uint8_t firstByteNBits = 8 - firstByteBit;
74  uint8_t firstByteMask = 0xffu << firstByteBit;
75  uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
76  uint16_t value = ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
77  return value;
78 }
79 
80 
static const char noise_[]
uint16_t decode(const uint16_t &strip, const Range &range) const
float getNoise(const uint16_t &strip, const Range &range) const
const Range getRange(const uint32_t &detID) const
Registry::const_iterator RegistryIterator
static std::string const input
Definition: EdmProvDump.cc:48
bool put(const uint32_t detID, InputVector &input)
std::pair< ContainerIterator, ContainerIterator > Range
#define end
Definition: vmac.h:39
Definition: value.py:1
void getDetIds(std::vector< uint32_t > &DetIds) const
std::vector< DetRegistry > indexes
Definition: DetId.h:18
double sd
const std::vector< short > InputVector
#define begin
Definition: vmac.h:32
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setData(float noise_, std::vector< short > &vped)
std::vector< unsigned char > v_noises
void encode(InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)