CMS 3D CMS Logo

SiStripNoises.h
Go to the documentation of this file.
1 #ifndef SiStripNoises_h
2 #define SiStripNoises_h
3 
5 
6 #include<vector>
7 #include<utility>
8 #include<iostream>
9 #include<boost/cstdint.hpp>
10 
11 #include<cassert>
12 #include<cstring>
13 
24 {
25  public:
26 
27  struct ratioData{
28  uint32_t detid;
29  std::vector<float> values;
30  };
31 
32  struct DetRegistry{
33  uint32_t detid;
34  uint32_t ibegin;
35  uint32_t iend;
36 
38 };
39 
41  {
42  public:
43  bool operator() (const DetRegistry& p,const uint32_t& i) const {return p.detid < i;}
44  };
45 
46  typedef std::vector<unsigned char> Container;
47  typedef std::vector<unsigned char>::const_iterator ContainerIterator;
48  typedef std::pair<ContainerIterator, ContainerIterator> Range;
49  typedef std::vector<DetRegistry> Registry;
50  typedef Registry::const_iterator RegistryIterator;
51  typedef std::vector<uint16_t> InputVector;
52 
56 
57  bool put(const uint32_t& detID,const InputVector &input);
58  const Range getRange(const uint32_t detID) const;
59  Range getRangeByPos(unsigned short pos) const;
60  void getDetIds(std::vector<uint32_t>& DetIds_) const;
61 
62  ContainerIterator getDataVectorBegin() const {return v_noises.begin();}
63  ContainerIterator getDataVectorEnd() const {return v_noises.end();}
64  RegistryIterator getRegistryVectorBegin() const {return indexes.begin();}
65  RegistryIterator getRegistryVectorEnd() const{return indexes.end();}
66 
67  static inline float getNoiseFast(const uint16_t& strip, const Range& range) {
68  return 0.1f*float(decode(strip,range));
69  }
70 
71  static void verify(uint16_t strip, const Range& range);
72  static float getNoise(uint16_t strip, const Range& range) {
73 #ifdef EDM_ML_DEBUG
74  verify(strip,range);
75 #endif
76  return getNoiseFast(strip,range);
77  }
78 
79 
80  void allNoises (std::vector<float> & noises, const Range& range) const;
81  void setData(float noise_, InputVector& vped);
82 
83  void printDebug(std::stringstream& ss) const;
84  void printSummary(std::stringstream& ss) const;
85 
86  std::vector<ratioData> operator / (const SiStripNoises& d) ;
87 
88  private:
89  static void encode(const InputVector& Vi, std::vector<unsigned char>& Vo_CHAR);
90 
91  static inline uint16_t decode (uint16_t strip, const Range& range);
92 
95  static inline uint16_t get9bits(const uint8_t * &ptr, int8_t skip);
96 
97  Container v_noises;
98  Registry indexes;
99 
100 
101  /*
102  const std::string print_as_binary(const uint8_t ch) const;
103  std::string print_char_as_binary(const unsigned char ch) const;
104  std::string print_short_as_binary(const short ch) const;
105  */
106 
108 };
109 
112 inline uint16_t SiStripNoises::get9bits(const uint8_t * &ptr, int8_t skip) {
113  uint8_t maskThis = (0xFF << skip);
114  uint8_t maskThat = ((2 << skip) - 1);
115  uint16_t ret = ( ((*ptr) & maskThis) >> skip );
116  --ptr;
117  return ret | ( ((*ptr) & maskThat) << (8 - skip) );
118 }
119 
120 inline uint16_t SiStripNoises::decode (uint16_t strip, const Range& range) {
121  const unsigned char *data = &*(range.second -1); // pointer to the last byte of data
122  static const uint16_t BITS_PER_STRIP = 9;
123 
124  uint32_t lowBit = strip * BITS_PER_STRIP;
125  uint8_t firstByteBit = (lowBit & 7);//module 8
126 
127  uint16_t vin = uint16_t(*(data-lowBit/8)) | (uint16_t(*(data-lowBit/8-1))<<8);
128  vin = vin >> firstByteBit; vin &= 0x1FF;
129  return vin;
130 
131  /*
132  uint8_t firstByteNBits = 8 - firstByteBit;
133  uint8_t firstByteMask = 0xffu << firstByteBit;
134  uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
135  uint16_t value = ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
136 
137  if(vin!=value) std::cout << vin << ',' <<value << std::endl;
138  */
139  /*
140  if(strip < 25){
141  std::cout << "***************DECODE*********************"<<"\n"
142  << "strip "<<strip << " "
143  << value
144  <<"\t :"<<print_as_binary(value)
145  <<"\t :"<<print_as_binary( ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) )
146  << "-"<<print_as_binary( ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits) )
147  << "\t *(data-lowBit/8) " << print_as_binary( *(data-lowBit/8 ))
148  << "\t *(data-lowBit/8-1) " << print_as_binary( *(data-lowBit/8 -1 ))
149  << "\tlowBit:"<< lowBit
150  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
151  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
152  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
153  << std::endl;
154  }
155  */
156  //return value;
157 }
158 
159 
160 #endif
static const char noise_[]
ContainerIterator getDataVectorEnd() const
Definition: SiStripNoises.h:63
Registry indexes
Definition: SiStripNoises.h:98
static uint16_t get9bits(const uint8_t *&ptr, int8_t skip)
std::vector< float > values
Definition: SiStripNoises.h:29
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:51
Container v_noises
Definition: SiStripNoises.h:97
std::vector< ratioData > operator/(const SiStripNoises &d)
static void verify(uint16_t strip, const Range &range)
std::vector< DetRegistry > Registry
Definition: SiStripNoises.h:49
static void encode(const InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
static std::string const input
Definition: EdmProvDump.cc:44
static float getNoiseFast(const uint16_t &strip, const Range &range)
Definition: SiStripNoises.h:67
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:72
std::vector< unsigned char >::const_iterator ContainerIterator
Definition: SiStripNoises.h:47
static uint16_t decode(uint16_t strip, const Range &range)
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:50
std::vector< unsigned char > Container
Definition: SiStripNoises.h:46
bool put(const uint32_t &detID, const InputVector &input)
RegistryIterator getRegistryVectorEnd() const
Definition: SiStripNoises.h:65
void getDetIds(std::vector< uint32_t > &DetIds_) const
RegistryIterator getRegistryVectorBegin() const
Definition: SiStripNoises.h:64
#define COND_SERIALIZABLE
Definition: Serializable.h:38
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
Range getRangeByPos(unsigned short pos) const
const Range getRange(const uint32_t detID) const
void printDebug(std::stringstream &ss) const
void printSummary(std::stringstream &ss) const
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:48
void allNoises(std::vector< float > &noises, const Range &range) const
ContainerIterator getDataVectorBegin() const
Definition: SiStripNoises.h:62
void setData(float noise_, InputVector &vped)