CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripNoises.h
Go to the documentation of this file.
1 #ifndef SiStripNoises_h
2 #define SiStripNoises_h
3 
4 #include<vector>
5 #include<map>
6 #include<iostream>
7 #include<boost/cstdint.hpp>
8 
19 {
20  public:
21 
22  struct ratioData{
23  uint32_t detid;
24  std::vector<float> values;
25  };
26 
27  struct DetRegistry{
28  uint32_t detid;
29  uint32_t ibegin;
30  uint32_t iend;
31  };
32 
34  {
35  public:
36  bool operator() (const DetRegistry& p,const uint32_t& i) const {return p.detid < i;}
37  };
38 
39  typedef std::vector<unsigned char> Container;
40  typedef std::vector<unsigned char>::const_iterator ContainerIterator;
41  typedef std::pair<ContainerIterator, ContainerIterator> Range;
42  typedef std::vector<DetRegistry> Registry;
43  typedef Registry::const_iterator RegistryIterator;
44  typedef std::vector<uint16_t> InputVector;
45 
49 
50  bool put(const uint32_t& detID,const InputVector &input);
51  const Range getRange(const uint32_t& detID) const;
52  void getDetIds(std::vector<uint32_t>& DetIds_) const;
53 
54  ContainerIterator getDataVectorBegin() const {return v_noises.begin();}
58 
59  static inline float getNoiseFast(const uint16_t& strip, const Range& range) {
60  return 0.1f*float(decode(strip,range));
61  }
62 
63  static float getNoise(uint16_t strip, const Range& range);
64 
65  void allNoises (std::vector<float> & noises, const Range& range) const;
66  void setData(float noise_, InputVector& vped);
67 
68  void printDebug(std::stringstream& ss) const;
69  void printSummary(std::stringstream& ss) const;
70 
71  std::vector<ratioData> operator / (SiStripNoises d) ;
72 
73  private:
74  static void encode(const InputVector& Vi, std::vector<unsigned char>& Vo_CHAR);
75 
76  static inline uint16_t decode (uint16_t strip, const Range& range);
77 
80  static inline uint16_t get9bits(const uint8_t * &ptr, int8_t skip);
81 
84 
85 
86  /*
87  const std::string print_as_binary(const uint8_t ch) const;
88  std::string print_char_as_binary(const unsigned char ch) const;
89  std::string print_short_as_binary(const short ch) const;
90  */
91 };
92 
95 inline uint16_t SiStripNoises::get9bits(const uint8_t * &ptr, int8_t skip) {
96  uint8_t maskThis = (0xFF << skip);
97  uint8_t maskThat = ((2 << skip) - 1);
98  uint16_t ret = ( ((*ptr) & maskThis) >> skip );
99  --ptr;
100  return ret | ( ((*ptr) & maskThat) << (8 - skip) );
101 }
102 
103 inline uint16_t SiStripNoises::decode (uint16_t strip, const Range& range) {
104  const unsigned char *data = &*(range.second -1); // pointer to the last byte of data
105  static const uint16_t BITS_PER_STRIP = 9;
106 
107  uint32_t lowBit = strip * BITS_PER_STRIP;
108  uint8_t firstByteBit = (lowBit & 7);//module 8
109  uint8_t firstByteNBits = 8 - firstByteBit;
110  uint8_t firstByteMask = 0xffu << firstByteBit;
111  uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
112  uint16_t value = ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
113 
114  /*
115  if(strip < 25){
116  std::cout << "***************DECODE*********************"<<"\n"
117  << "strip "<<strip << " "
118  << value
119  <<"\t :"<<print_as_binary(value)
120  <<"\t :"<<print_as_binary( ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) )
121  << "-"<<print_as_binary( ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits) )
122  << "\t *(data-lowBit/8) " << print_as_binary( *(data-lowBit/8 ))
123  << "\t *(data-lowBit/8-1) " << print_as_binary( *(data-lowBit/8 -1 ))
124  << "\tlowBit:"<< lowBit
125  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
126  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
127  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
128  << std::endl;
129  }
130  */
131  return value;
132 }
133 
134 
135 #endif
static const char noise_[]
std::vector< ratioData > operator/(SiStripNoises d)
int i
Definition: DBlmapReader.cc:9
ContainerIterator getDataVectorEnd() const
Definition: SiStripNoises.h:55
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
Registry indexes
Definition: SiStripNoises.h:83
static uint16_t get9bits(const uint8_t *&ptr, int8_t skip)
Definition: SiStripNoises.h:95
std::vector< float > values
Definition: SiStripNoises.h:24
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:44
Container v_noises
Definition: SiStripNoises.h:82
std::vector< DetRegistry > Registry
Definition: SiStripNoises.h:42
static void encode(const InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
static float getNoiseFast(const uint16_t &strip, const Range &range)
Definition: SiStripNoises.h:59
std::vector< unsigned char >::const_iterator ContainerIterator
Definition: SiStripNoises.h:40
static uint16_t decode(uint16_t strip, const Range &range)
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:43
std::vector< unsigned char > Container
Definition: SiStripNoises.h:39
bool put(const uint32_t &detID, const InputVector &input)
static float getNoise(uint16_t strip, const Range &range)
RegistryIterator getRegistryVectorEnd() const
Definition: SiStripNoises.h:57
void getDetIds(std::vector< uint32_t > &DetIds_) const
RegistryIterator getRegistryVectorBegin() const
Definition: SiStripNoises.h:56
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void printDebug(std::stringstream &ss) const
void printSummary(std::stringstream &ss) const
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:41
const Range getRange(const uint32_t &detID) const
void allNoises(std::vector< float > &noises, const Range &range) const
ContainerIterator getDataVectorBegin() const
Definition: SiStripNoises.h:54
bool operator()(const DetRegistry &p, const uint32_t &i) const
Definition: SiStripNoises.h:36
void setData(float noise_, InputVector &vped)