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