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 
10 #include <cassert>
11 #include <cstring>
12 #include <cstdint>
13 
14 class TrackerTopology;
15 
26 public:
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  public:
42  bool operator()(const DetRegistry& p, const uint32_t& i) const { return p.detid < i; }
43  };
44 
45  typedef std::vector<unsigned char> Container;
46  typedef std::vector<unsigned char>::const_iterator ContainerIterator;
47  typedef std::pair<ContainerIterator, ContainerIterator> Range;
48  typedef std::vector<DetRegistry> Registry;
49  typedef Registry::const_iterator RegistryIterator;
50  typedef std::vector<uint16_t> InputVector;
51 
54 
55  bool put(const uint32_t& detID, const InputVector& input);
56  const Range getRange(const uint32_t detID) const;
57  Range getRangeByPos(unsigned short pos) const;
58  void getDetIds(std::vector<uint32_t>& DetIds_) const;
59 
60  ContainerIterator getDataVectorBegin() const { return v_noises.begin(); }
61  ContainerIterator getDataVectorEnd() const { return v_noises.end(); }
62  RegistryIterator getRegistryVectorBegin() const { return indexes.begin(); }
63  RegistryIterator getRegistryVectorEnd() const { return indexes.end(); }
64 
65  static inline float getRawNoise(const uint16_t& strip, const Range& range) { return decode(strip, range); }
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  void allNoises(std::vector<float>& noises, const Range& range) const;
80  void setData(float noise_, InputVector& vped);
81 
82  void printDebug(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
83  void printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const;
84 
85  std::vector<ratioData> operator/(const SiStripNoises& d);
86 
87 private:
88  static void encode(const InputVector& Vi, std::vector<unsigned char>& Vo_CHAR);
89 
90  static inline uint16_t decode(uint16_t strip, const Range& range);
91 
94  static inline uint16_t get9bits(const uint8_t*& ptr, int8_t skip);
95 
98 
99  /*
100  const std::string print_as_binary(const uint8_t ch) const;
101  std::string print_char_as_binary(const unsigned char ch) const;
102  std::string print_short_as_binary(const short ch) const;
103  */
104 
106 };
107 
110 inline uint16_t SiStripNoises::get9bits(const uint8_t*& ptr, int8_t skip) {
111  uint8_t maskThis = (0xFF << skip);
112  uint8_t maskThat = ((2 << skip) - 1);
113  uint16_t ret = (((*ptr) & maskThis) >> skip);
114  --ptr;
115  return ret | (((*ptr) & maskThat) << (8 - skip));
116 }
117 
118 inline uint16_t SiStripNoises::decode(uint16_t strip, const Range& range) {
119  const unsigned char* data = &*(range.second - 1); // pointer to the last byte of data
120  static const uint16_t BITS_PER_STRIP = 9;
121 
122  uint32_t lowBit = strip * BITS_PER_STRIP;
123  uint8_t firstByteBit = (lowBit & 7); //module 8
124 
125  uint16_t vin = uint16_t(*(data - lowBit / 8)) | (uint16_t(*(data - lowBit / 8 - 1)) << 8);
126  vin = vin >> firstByteBit;
127  vin &= 0x1FF;
128  return vin;
129 
130  /*
131  uint8_t firstByteNBits = 8 - firstByteBit;
132  uint8_t firstByteMask = 0xffu << firstByteBit;
133  uint8_t secondByteMask = ~(0xffu << (BITS_PER_STRIP - firstByteNBits));
134  uint16_t value = ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) | ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) << firstByteNBits);
135 
136  if(vin!=value) std::cout << vin << ',' <<value << std::endl;
137  */
138  /*
139  if(strip < 25){
140  std::cout << "***************DECODE*********************"<<"\n"
141  << "strip "<<strip << " "
142  << value
143  <<"\t :"<<print_as_binary(value)
144  <<"\t :"<<print_as_binary( ((uint16_t(*(data-lowBit/8 )) & firstByteMask) >> firstByteBit) )
145  << "-"<<print_as_binary( ((uint16_t(*(data-lowBit/8-1)) & secondByteMask) <<firstByteNBits) )
146  << "\t *(data-lowBit/8) " << print_as_binary( *(data-lowBit/8 ))
147  << "\t *(data-lowBit/8-1) " << print_as_binary( *(data-lowBit/8 -1 ))
148  << "\tlowBit:"<< lowBit
149  << "\tfirstByteMask :"<<print_as_binary(firstByteMask)
150  << "\tsecondByteMask:"<<print_as_binary(secondByteMask)
151  << "\tfirstByteBit:"<<print_as_binary(firstByteBit)
152  << std::endl;
153  }
154  */
155  //return value;
156 }
157 
158 #endif
static const char noise_[]
Range getRangeByPos(unsigned short pos) const
static float getRawNoise(const uint16_t &strip, const Range &range)
Definition: SiStripNoises.h:65
RegistryIterator getRegistryVectorBegin() const
Definition: SiStripNoises.h:62
void allNoises(std::vector< float > &noises, const Range &range) const
Registry indexes
Definition: SiStripNoises.h:97
static uint16_t get9bits(const uint8_t *&ptr, int8_t skip)
ret
prodAgent to be discontinued
std::vector< float > values
Definition: SiStripNoises.h:29
std::vector< uint16_t > InputVector
Definition: SiStripNoises.h:50
Container v_noises
Definition: SiStripNoises.h:96
std::vector< ratioData > operator/(const SiStripNoises &d)
ContainerIterator getDataVectorBegin() const
Definition: SiStripNoises.h:60
static void verify(uint16_t strip, const Range &range)
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
std::vector< DetRegistry > Registry
Definition: SiStripNoises.h:48
static void encode(const InputVector &Vi, std::vector< unsigned char > &Vo_CHAR)
static std::string const input
Definition: EdmProvDump.cc:50
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:46
static uint16_t decode(uint16_t strip, const Range &range)
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:49
d
Definition: ztail.py:151
std::vector< unsigned char > Container
Definition: SiStripNoises.h:45
bool put(const uint32_t &detID, const InputVector &input)
Definition: SiStripNoises.cc:9
ContainerIterator getDataVectorEnd() const
Definition: SiStripNoises.h:61
bool operator()(const DetRegistry &p, const uint32_t &i) const
Definition: SiStripNoises.h:42
RegistryIterator getRegistryVectorEnd() const
Definition: SiStripNoises.h:63
#define COND_SERIALIZABLE
Definition: Serializable.h:39
const Range getRange(const uint32_t detID) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:47
void getDetIds(std::vector< uint32_t > &DetIds_) const
void setData(float noise_, InputVector &vped)