test
CMS 3D CMS Logo

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