CMS 3D CMS Logo

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