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 {
20 }
21 //This part has been modified from the orignal
23 {
24 
25  rocid_=rocid;
26  char cpt[2080] ;
27  bits.copy( cpt , 2080);
28  for(unsigned int i = 0 ; i < bits.size(); i++)
29  bits_[i] = static_cast<unsigned char>(cpt[i]);
30 
31 }
32 //End of part modified
33 
34 // Added by Dario: handles the base_64-decoded strings from aDB read
36  rocid_=rocid;
37  for( int i=0; i<(int)sizeof(bits_); i++)
38  {
39  bits_[i] = in.at(i) ;
40  }
41  return 1 ;
42 }
43 
44 int PixelROCTrimBits::read(PixelROCName rocid,std::ifstream& in){
45 
47 
48  //std::cout << "PixelROCTrimBits::read rocid:"<<rocid<<std::endl;
49 
50  rocid_=rocid;
51 
52  //std::cout << "PixelROCTrimBits::read rocid_:"<<rocid_<<std::endl;
53 
54  for (int i=0;i<52;i++){
55 
56  in >> tag;
57 
58  //std::cout << "Now reading col:"<<tag<<std::endl;
59 
61 
62  in >> data;
63 
64  //std::cout <<"data.size()" <<data.size()<<std::endl;
65 
66  unsigned char byte=0;
67 
68  for(int j=0;j<80;j++){
69 
70  unsigned char tmp=toupper(data[j])-48;
71  if (tmp>9) tmp-=7; //FIXME this is so ugly
72 
73  byte+=tmp;
74 
75  if ((j+1)%2==0) {
76  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
77  bits_[i*40+(j+1)/2-1]=byte;
78  byte=0;
79  }
80  else{
81  byte*=16;
82  }
83 
84 
85  }
86 
87  }
88  return 1;
89 
90 }
91 
92 int PixelROCTrimBits::read(PixelROCName rocid, std::istringstream& in)
93 {
95  //std::cout << "PixelROCTrimBits::read rocid:"<<rocid<<std::endl;
96  rocid_=rocid;
97  //std::cout << "PixelROCTrimBits::read rocid_:"<<rocid_<<std::endl;
98  for (int i=0;i<52;i++)
99  {
100  in >> tag;
101 // std::cout << "Now reading col:"<<tag<<std::endl;
103  in >> data;
104 // std::cout <<" data: " <<data<<std::endl;
105  unsigned char byte=0;
106  for(int j=0;j<80;j++)
107  {
108  unsigned char tmp=toupper(data[j])-48;
109  if (tmp>9) tmp-=7; //FIXME this is so ugly
110  byte+=tmp;
111  if ((j+1)%2==0)
112  {
113  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
114  bits_[i*40+(j+1)/2-1]=byte;
115  byte=0;
116  }
117  else
118  {
119  byte*=16;
120  }
121  }
122  }
123  return 1;
124 }
125 
126 
127 
128 int PixelROCTrimBits::readBinary(PixelROCName rocid,std::ifstream& in){
129 
130  rocid_=rocid;
131 
132  in.read((char*)bits_,2080);
133 
134  return 1;
135 
136 }
137 
138 
139 void PixelROCTrimBits::writeBinary(std::ofstream& out) const{
140 
141  out << (char)rocid_.rocname().size();
142  out.write(rocid_.rocname().c_str(),rocid_.rocname().size());
143 
144  //std::cout << "PixelROCTrimBits::writeBinary:"<<rocid_.rocname().size()
145  // << " " <<rocid_.rocname()<<std::endl;
146 
147  for(unsigned int i=0;i<2080;i++){
148  out << bits_[i];
149  }
150 
151 }
152 
153 void PixelROCTrimBits::writeASCII(std::ofstream& out) const{
154 
155  //std::cout << " PixelROCTrimBits::writeASCII rocid_.rocname():"<<rocid_.rocname()<<std::endl;
156 
157 
158  out << "ROC: "<<rocid_.rocname()<<std::endl;
159 
160  //std::cout << "PixelROCTrimBits::writeBinary:"<<rocid_.rocname().size()
161  // << " " <<rocid_.rocname()<<std::endl;
162 
163  for(unsigned int col=0;col<52;col++){
164  out << "col";
165  if (col<10) out << "0";
166  out <<col<<": ";
167  for (int row=0;row<80;row++){
168  out << std::hex<<std::uppercase<<trim(col,row)<<std::dec;
169  }
170  out << std::endl;
171  }
172 
173 }
174 
175 unsigned int PixelROCTrimBits::trim(unsigned int col, unsigned int row) const{
176 
177  unsigned int tmp=bits_[col*40+row/2];
178  if (row%2==0) tmp/=16;
179  return tmp&0x0F;
180 
181 }
182 
183 void PixelROCTrimBits::setTrim(unsigned int col, unsigned int row, unsigned int trim){
184 
185  assert(trim<16);
186 
187  unsigned int mask=0xf0;
188  if (row%2==0) {
189  trim<<=4;
190  mask>>=4;
191  }
192  unsigned int tmp=bits_[col*40+row/2];
193  bits_[col*40+row/2]=(tmp&mask)|trim;
194 
195 }
196 
197 
198 
199 
200 std::ostream& pos::operator<<(std::ostream& s, const PixelROCTrimBits& mask){
201 
202  s << "Dumping ROC masks" <<std::endl;
203 
204  for(int i=0;i<52;i++){
205  s<<"Col"<<i<<": ";
206  for(int j=0;j<40;j++){
207  unsigned char bitmask=15*16;
208  for(int k=0;k<2;k++){
209  unsigned int tmp=mask.bits_[i*40+j]&bitmask;
210  if (tmp>15) tmp/=16;
211  s << std::hex << tmp << std::dec;
212  bitmask/=16;
213  }
214  }
215  s<<std::endl;
216  }
217 
218 
219  return s;
220 
221 }
222 
223 //=============================================================================================
224 void PixelROCTrimBits::writeXML(std::ofstream * out) const
225 {
226  std::string mthn = "[PixelROCTrimBits::writeXML()]\t\t\t\t" ;
227 
228  std::string encoded = base64_encode(bits_, sizeof(bits_));
229  std::string decoded = base64_decode(encoded);
230 
231  *out << " <DATA>" << std::endl ;
232  *out << " <ROC_NAME>" << rocid_.rocname() << "</ROC_NAME>" << std::endl ;
233  *out << " <TRIM_BITS>" << encoded << "</TRIM_BITS>" << std::endl ;
234  *out << " </DATA>" << std::endl ;
235  *out << " " << std::endl ;
236 
237 }
238 
int read(PixelROCName rocid, std::string in)
void setROCTrimBits(PixelROCName rocid, std::string bits)
#define base64_decode(in, inlen, out, outlen)
Definition: base64.h:57
void writeBinary(std::ofstream &out) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
int readBinary(PixelROCName rocid, std::ifstream &in)
unsigned int trim(unsigned int col, unsigned int row) const
std::string rocname() const
std::ostream & operator<<(std::ostream &s, const PixelCalibConfiguration &calib)
std::string base64_encode(unsigned char const *, unsigned int len)
Definition: PixelBase64.cc:41
void writeXML(std::ofstream *out) const
This class implements..
int k[5][pyjets_maxn]
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
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:82
unsigned char bits_[2080]
col
Definition: cuy.py:1009
void writeASCII(std::ofstream &out) const