CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 try{
26  rocid_=rocid;
27  char cpt[2080] ;
28  bits.copy( cpt , 2080);
29  for(unsigned int i = 0 ; i < bits.size(); i++)
30  bits_[i] = (unsigned char)cpt[i];
31 }catch(std::bad_cast){
32 
33 std::cout << "Error casting variable." << std::endl;
34 
35 }
36 
37 }
38 //End of part modified
39 
40 // Added by Dario: handles the base_64-decoded strings from aDB read
42  rocid_=rocid;
43  for( int i=0; i<(int)sizeof(bits_); i++)
44  {
45  bits_[i] = in.at(i) ;
46  }
47  return 1 ;
48 }
49 
50 int PixelROCTrimBits::read(PixelROCName rocid,std::ifstream& in){
51 
53 
54  //std::cout << "PixelROCTrimBits::read rocid:"<<rocid<<std::endl;
55 
56  rocid_=rocid;
57 
58  //std::cout << "PixelROCTrimBits::read rocid_:"<<rocid_<<std::endl;
59 
60  for (int i=0;i<52;i++){
61 
62  in >> tag;
63 
64  //std::cout << "Now reading col:"<<tag<<std::endl;
65 
67 
68  in >> data;
69 
70  //std::cout <<"data.size()" <<data.size()<<std::endl;
71 
72  unsigned char byte=0;
73 
74  for(int j=0;j<80;j++){
75 
76  unsigned char tmp=toupper(data[j])-48;
77  if (tmp>9) tmp-=7; //FIXME this is so ugly
78 
79  byte+=tmp;
80 
81  if ((j+1)%2==0) {
82  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
83  bits_[i*40+(j+1)/2-1]=byte;
84  byte=0;
85  }
86  else{
87  byte*=16;
88  }
89 
90 
91  }
92 
93  }
94  return 1;
95 
96 }
97 
98 int PixelROCTrimBits::read(PixelROCName rocid, std::istringstream& in)
99 {
101  //std::cout << "PixelROCTrimBits::read rocid:"<<rocid<<std::endl;
102  rocid_=rocid;
103  //std::cout << "PixelROCTrimBits::read rocid_:"<<rocid_<<std::endl;
104  for (int i=0;i<52;i++)
105  {
106  in >> tag;
107 // std::cout << "Now reading col:"<<tag<<std::endl;
109  in >> data;
110 // std::cout <<" data: " <<data<<std::endl;
111  unsigned char byte=0;
112  for(int j=0;j<80;j++)
113  {
114  unsigned char tmp=toupper(data[j])-48;
115  if (tmp>9) tmp-=7; //FIXME this is so ugly
116  byte+=tmp;
117  if ((j+1)%2==0)
118  {
119  //std::cout << "Writing byte:"<<(int)byte<<std::endl;
120  bits_[i*40+(j+1)/2-1]=byte;
121  byte=0;
122  }
123  else
124  {
125  byte*=16;
126  }
127  }
128  }
129  return 1;
130 }
131 
132 
133 
134 int PixelROCTrimBits::readBinary(PixelROCName rocid,std::ifstream& in){
135 
136  rocid_=rocid;
137 
138  in.read((char*)bits_,2080);
139 
140  return 1;
141 
142 }
143 
144 
145 void PixelROCTrimBits::writeBinary(std::ofstream& out) const{
146 
147  out << (char)rocid_.rocname().size();
148  out.write(rocid_.rocname().c_str(),rocid_.rocname().size());
149 
150  //std::cout << "PixelROCTrimBits::writeBinary:"<<rocid_.rocname().size()
151  // << " " <<rocid_.rocname()<<std::endl;
152 
153  for(unsigned int i=0;i<2080;i++){
154  out << bits_[i];
155  }
156 
157 }
158 
159 void PixelROCTrimBits::writeASCII(std::ofstream& out) const{
160 
161  //std::cout << " PixelROCTrimBits::writeASCII rocid_.rocname():"<<rocid_.rocname()<<std::endl;
162 
163 
164  out << "ROC: "<<rocid_.rocname()<<std::endl;
165 
166  //std::cout << "PixelROCTrimBits::writeBinary:"<<rocid_.rocname().size()
167  // << " " <<rocid_.rocname()<<std::endl;
168 
169  for(unsigned int col=0;col<52;col++){
170  out << "col";
171  if (col<10) out << "0";
172  out <<col<<": ";
173  for (int row=0;row<80;row++){
174  out << std::hex<<std::uppercase<<trim(col,row)<<std::dec;
175  }
176  out << std::endl;
177  }
178 
179 }
180 
181 unsigned int PixelROCTrimBits::trim(unsigned int col, unsigned int row) const{
182 
183  unsigned int tmp=bits_[col*40+row/2];
184  if (row%2==0) tmp/=16;
185  return tmp&0x0F;
186 
187 }
188 
189 void PixelROCTrimBits::setTrim(unsigned int col, unsigned int row, unsigned int trim){
190 
191  assert(trim<16);
192 
193  unsigned int mask=0xf0;
194  if (row%2==0) {
195  trim<<=4;
196  mask>>=4;
197  }
198  unsigned int tmp=bits_[col*40+row/2];
199  bits_[col*40+row/2]=(tmp&mask)|trim;
200 
201 }
202 
203 
204 
205 
206 std::ostream& pos::operator<<(std::ostream& s, const PixelROCTrimBits& mask){
207 
208  s << "Dumping ROC masks" <<std::endl;
209 
210  for(int i=0;i<52;i++){
211  s<<"Col"<<i<<": ";
212  for(int j=0;j<40;j++){
213  unsigned char bitmask=15*16;
214  for(int k=0;k<2;k++){
215  unsigned int tmp=mask.bits_[i*40+j]&bitmask;
216  if (tmp>15) tmp/=16;
217  s << std::hex << tmp << std::dec;
218  bitmask/=16;
219  }
220  }
221  s<<std::endl;
222  }
223 
224 
225  return s;
226 
227 }
228 
229 //=============================================================================================
230 void PixelROCTrimBits::writeXML(std::ofstream * out) const
231 {
232  std::string mthn = "[PixelROCTrimBits::writeXML()]\t\t\t\t" ;
233 
234  std::string encoded = base64_encode(bits_, sizeof(bits_));
235  std::string decoded = base64_decode(encoded);
236 
237  *out << " <DATA>" << std::endl ;
238  *out << " <ROC_NAME>" << rocid_.rocname() << "</ROC_NAME>" << std::endl ;
239  *out << " <TRIM_BITS>" << encoded << "</TRIM_BITS>" << std::endl ;
240  *out << " </DATA>" << std::endl ;
241  *out << " " << std::endl ;
242 
243 }
244 
int i
Definition: DBlmapReader.cc:9
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
int j
Definition: DBlmapReader.cc:9
void writeXML(std::ofstream *out) const
This class implements..
tuple out
Definition: dbtoconf.py:99
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]
void writeASCII(std::ofstream &out) const
tuple cout
Definition: gather_cfg.py:121
int col
Definition: cuy.py:1008