CMS 3D CMS Logo

PixelROCTrimBits.cc
Go to the documentation of this file.
1 //
2 // This class provide the data structure for the
3 // ROC DAC parameters
4 //
5 // At this point I do not see a reason to make an
6 // abstract layer for this code.
7 //
8 
11 #include <iostream>
12 #include <sstream>
13 #include <cassert>
14 #include <typeinfo>
15 
16 using namespace pos;
17 
19 //This part has been modified from the orignal
21  rocid_ = rocid;
22  char cpt[2080];
23  bits.copy(cpt, 2080);
24  for (unsigned int i = 0; i < bits.size(); i++)
25  bits_[i] = static_cast<unsigned char>(cpt[i]);
26 }
27 //End of part modified
28 
29 // Added by Dario: handles the base_64-decoded strings from aDB read
31  rocid_ = rocid;
32  for (int i = 0; i < (int)sizeof(bits_); i++) {
33  bits_[i] = in.at(i);
34  }
35  return 1;
36 }
37 
38 int PixelROCTrimBits::read(PixelROCName rocid, std::ifstream& in) {
40 
41  //std::cout << "PixelROCTrimBits::read rocid:"<<rocid<<std::endl;
42 
43  rocid_ = rocid;
44 
45  //std::cout << "PixelROCTrimBits::read rocid_:"<<rocid_<<std::endl;
46 
47  for (int i = 0; i < 52; i++) {
48  in >> tag;
49 
50  //std::cout << "Now reading col:"<<tag<<std::endl;
51 
53 
54  in >> data;
55 
56  //std::cout <<"data.size()" <<data.size()<<std::endl;
57 
58  unsigned char byte = 0;
59 
60  for (int j = 0; j < 80; j++) {
61  unsigned char tmp = toupper(data[j]) - 48;
62  if (tmp > 9)
63  tmp -= 7; //FIXME this is so ugly
64 
65  byte += tmp;
66 
67  if ((j + 1) % 2 == 0) {
68  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
69  bits_[i * 40 + (j + 1) / 2 - 1] = byte;
70  byte = 0;
71  } else {
72  byte *= 16;
73  }
74  }
75  }
76  return 1;
77 }
78 
79 int PixelROCTrimBits::read(PixelROCName rocid, std::istringstream& in) {
81  //std::cout << "PixelROCTrimBits::read rocid:"<<rocid<<std::endl;
82  rocid_ = rocid;
83  //std::cout << "PixelROCTrimBits::read rocid_:"<<rocid_<<std::endl;
84  for (int i = 0; i < 52; i++) {
85  in >> tag;
86  // std::cout << "Now reading col:"<<tag<<std::endl;
88  in >> data;
89  // std::cout <<" data: " <<data<<std::endl;
90  unsigned char byte = 0;
91  for (int j = 0; j < 80; j++) {
92  unsigned char tmp = toupper(data[j]) - 48;
93  if (tmp > 9)
94  tmp -= 7; //FIXME this is so ugly
95  byte += tmp;
96  if ((j + 1) % 2 == 0) {
97  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
98  bits_[i * 40 + (j + 1) / 2 - 1] = byte;
99  byte = 0;
100  } else {
101  byte *= 16;
102  }
103  }
104  }
105  return 1;
106 }
107 
108 int PixelROCTrimBits::readBinary(PixelROCName rocid, std::ifstream& in) {
109  rocid_ = rocid;
110 
111  in.read((char*)bits_, 2080);
112 
113  return 1;
114 }
115 
116 void PixelROCTrimBits::writeBinary(std::ofstream& out) const {
117  out << (char)rocid_.rocname().size();
118  out.write(rocid_.rocname().c_str(), rocid_.rocname().size());
119 
120  //std::cout << "PixelROCTrimBits::writeBinary:"<<rocid_.rocname().size()
121  // << " " <<rocid_.rocname()<<std::endl;
122 
123  for (unsigned int i = 0; i < 2080; i++) {
124  out << bits_[i];
125  }
126 }
127 
128 void PixelROCTrimBits::writeASCII(std::ofstream& out) const {
129  //std::cout << " PixelROCTrimBits::writeASCII rocid_.rocname():"<<rocid_.rocname()<<std::endl;
130 
131  out << "ROC: " << rocid_.rocname() << std::endl;
132 
133  //std::cout << "PixelROCTrimBits::writeBinary:"<<rocid_.rocname().size()
134  // << " " <<rocid_.rocname()<<std::endl;
135 
136  for (unsigned int col = 0; col < 52; col++) {
137  out << "col";
138  if (col < 10)
139  out << "0";
140  out << col << ": ";
141  for (int row = 0; row < 80; row++) {
142  out << std::hex << std::uppercase << trim(col, row) << std::dec;
143  }
144  out << std::endl;
145  }
146 }
147 
148 unsigned int PixelROCTrimBits::trim(unsigned int col, unsigned int row) const {
149  unsigned int tmp = bits_[col * 40 + row / 2];
150  if (row % 2 == 0)
151  tmp /= 16;
152  return tmp & 0x0F;
153 }
154 
155 void PixelROCTrimBits::setTrim(unsigned int col, unsigned int row, unsigned int trim) {
156  assert(trim < 16);
157 
158  unsigned int mask = 0xf0;
159  if (row % 2 == 0) {
160  trim <<= 4;
161  mask >>= 4;
162  }
163  unsigned int tmp = bits_[col * 40 + row / 2];
164  bits_[col * 40 + row / 2] = (tmp & mask) | trim;
165 }
166 
167 std::ostream& pos::operator<<(std::ostream& s, const PixelROCTrimBits& mask) {
168  s << "Dumping ROC masks" << std::endl;
169 
170  for (int i = 0; i < 52; i++) {
171  s << "Col" << i << ": ";
172  for (int j = 0; j < 40; j++) {
173  unsigned char bitmask = 15 * 16;
174  for (int k = 0; k < 2; k++) {
175  unsigned int tmp = mask.bits_[i * 40 + j] & bitmask;
176  if (tmp > 15)
177  tmp /= 16;
178  s << std::hex << tmp << std::dec;
179  bitmask /= 16;
180  }
181  }
182  s << std::endl;
183  }
184 
185  return s;
186 }
187 
188 //=============================================================================================
189 void PixelROCTrimBits::writeXML(std::ofstream* out) const {
190  std::string mthn = "[PixelROCTrimBits::writeXML()]\t\t\t\t";
191 
192  std::string encoded = base64_encode(bits_, sizeof(bits_));
193  std::string decoded = base64_decode(encoded);
194 
195  *out << " <DATA>" << std::endl;
196  *out << " <ROC_NAME>" << rocid_.rocname() << "</ROC_NAME>" << std::endl;
197  *out << " <TRIM_BITS>" << encoded << "</TRIM_BITS>" << std::endl;
198  *out << " </DATA>" << std::endl;
199  *out << " " << std::endl;
200 }
int read(PixelROCName rocid, std::string in)
void writeBinary(std::ofstream &out) const
void setROCTrimBits(PixelROCName rocid, std::string bits)
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:52
static void trim(std::string &s)
int readBinary(PixelROCName rocid, std::ifstream &in)
std::ostream & operator<<(std::ostream &s, const PixelCalibConfiguration &calib)
assert(be >=bs)
std::string base64_encode(unsigned char const *, unsigned int len)
Definition: PixelBase64.cc:38
void writeXML(std::ofstream *out) const
std::string rocname() const
This class implements..
void writeASCII(std::ofstream &out) const
void setTrim(unsigned int col, unsigned int row, unsigned int trim)
This class implements..
Definition: PixelROCName.h:23
This class implements..
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
unsigned char bits_[2080]
col
Definition: cuy.py:1009
unsigned int trim(unsigned int col, unsigned int row) const
tmp
align.sh
Definition: createJobs.py:716